[PATCH net-next 06/12] can: rcar_canfd: Check can_clk request for errors

From
Marc Kleine-Budde <mkl@pengutronix.de>
Date
2026-11-10 11:51:21
Also in
linux-can
Reply to
Marc Kleine-Budde, 2026-11-10
From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>

If the provider of can_clk is not yet probed, devm_clk_get() returns
-EPROBE_DEFER. The driver treats any error as can_clk being absent and
falls back to the other clocking options, so the wrong clock may be
selected instead of deferring the probe.

Request can_clk with devm_clk_get_optional() and propagate its errors.
While at it, add a comment mentioning that the canfd or fck clocks are
used as a fallbacks when the external clock is not available or it is
described in device tree with a rate of 0.

Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Link: https://patch.msgid.link/20261019121356.2421761-2-claudiu.beznea@kernel.org (local)
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/rcar/rcar_canfd.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
index 74c3c3f20991..bb2d03b75142 100644
--- a/drivers/net/can/rcar/rcar_canfd.c
+++ b/drivers/net/can/rcar/rcar_canfd.c
@@ -2220,11 +2220,14 @@ static int rcar_canfd_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, PTR_ERR(gpriv->clkp),
 				     "cannot get peripheral clock\n");
 
-	/* fCAN clock: Pick External clock. If not available fallback to
-	 * CANFD clock
+	/* fCAN clock: Pick External clock. If not available or its rate is
+	 * zero fallback to CANFD clock or fck (when info->fcan_pclk = 1).
 	 */
-	gpriv->can_clk = devm_clk_get(dev, "can_clk");
-	if (IS_ERR(gpriv->can_clk) || (clk_get_rate(gpriv->can_clk) == 0)) {
+	gpriv->can_clk = devm_clk_get_optional(dev, "can_clk");
+	if (IS_ERR(gpriv->can_clk))
+		return dev_err_probe(dev, PTR_ERR(gpriv->can_clk), "cannot get can_clk");
+
+	if (!gpriv->can_clk || (clk_get_rate(gpriv->can_clk) == 0)) {
 		if (info->fcan_pclk) {
 			fcan_freq = clk_get_rate(gpriv->clkp);
 			gpriv->can_clk = NULL;
-- 
2.53.0
Thread (27 messages) 27 messages, 6 authors, last reply 5d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help