From: sashiko-bot@kernel.org
To: "Claudiu Beznea" <claudiu.beznea+renesas@tuxon.dev>
Cc: robh@kernel.org, "Vincent Mailhol" <mailhol@kernel.org>,
devicetree@vger.kernel.org, linux-can@vger.kernel.org,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
wsa+renesas@sang-engineering.com,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
conor+dt@kernel.org
Subject: Re: [PATCH v3 4/8] can: rcar_canfd: Allow the CAN FD clock to be sourced from fck
Date: Tue, 14 Jul 2026 17:47:34 +0000 [thread overview]
Message-ID: <20260714174734.7A2141F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714173315.1981708-5-claudiu.beznea+renesas@tuxon.dev>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver ignores `-EPROBE_DEFER` when acquiring the optional `can_clk`, leading to an incorrect clock source fallback or spurious probe failures.
- [High] Double free of `ndev` and UAF via `unregister_candev` if `register_candev` fails during channel probe.
- [High] Unbalanced clock disable and reset assert when `rcar_canfd_global_init` fails.
--
--- Patch [4]: [PATCH v3 4/8] can: rcar_canfd: Allow the CAN FD clock to be sourced from fck ---
commit a52a5e318c0ad2d299e214595e95da5df928f319
Author: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
can: rcar_canfd: Allow the CAN FD clock to be sourced from fck
This commit adjusts the clock handling in the RZ/G3S CAN FD driver to allow
the clock to be sourced from the peripheral clock instead of an external
clock. It also updates existing hardware info structures to support this.
Link: https://lore.kernel.org/all/1d9719e3-10ff-4cd8-b729-55fea93c37ce@wanadoo.fr
> diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
> index b40ae5998c1da..2e84dc5dfa34d 100644
> --- a/drivers/net/can/rcar/rcar_canfd.c
> +++ b/drivers/net/can/rcar/rcar_canfd.c
[ ... ]
> @@ -2190,13 +2196,20 @@ static int rcar_canfd_probe(struct platform_device *pdev)
> */
> 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(dev, "canfd");
> - if (IS_ERR(gpriv->can_clk))
> - return dev_err_probe(dev, PTR_ERR(gpriv->can_clk),
> - "cannot get canfd clock\n");
> + if (info->fcan_pclk) {
[Severity: High]
This is a pre-existing issue, but the driver appears to ignore -EPROBE_DEFER
when acquiring the optional can_clk.
If can_clk is defined in the device tree but its provider has not yet probed,
devm_clk_get() returns -EPROBE_DEFER. Because the driver checks IS_ERR() and
blindly coalesces all errors into the fallback path, platforms with fcan_pclk
will silently fall back to the peripheral clock instead of deferring the probe.
Could this cause the CAN controller to run on the wrong clock, resulting in
invalid CAN baud rates? Should devm_clk_get_optional() be used here to
correctly propagate -EPROBE_DEFER?
> + fcan_freq = clk_get_rate(gpriv->clkp);
> + gpriv->can_clk = NULL;
> + } else {
> + gpriv->can_clk = devm_clk_get(dev, "canfd");
> + if (IS_ERR(gpriv->can_clk))
> + return dev_err_probe(dev, PTR_ERR(gpriv->can_clk),
> + "cannot get canfd clock\n");
> +
> + fcan_freq = clk_get_rate(gpriv->can_clk);
> + }
[Severity: High]
This isn't a bug introduced by this patch, but there appears to be a double free
and use-after-free risk during channel probe failure.
In rcar_canfd_channel_probe(), the channel pointer is assigned before calling
register_candev():
gpriv->ch[priv->channel] = priv;
err = register_candev(ndev);
if (err) {
...
goto fail_candev;
}
If register_candev() fails, the error path frees ndev (which embeds priv) via
free_candev(ndev), but leaves the dangling pointer in gpriv->ch.
When this error propagates back to rcar_canfd_probe(), the cleanup loop calls
rcar_canfd_channel_remove() for all channels:
struct rcar_canfd_channel *priv = gpriv->ch[ch];
if (priv) {
unregister_candev(priv->ndev);
netif_napi_del(&priv->napi);
free_candev(priv->ndev);
}
Will this dereference the dangling pointer, incorrectly call unregister_candev()
on invalid memory, and double-free ndev?
[Severity: High]
This is a pre-existing issue, but there seems to be an unbalanced clock disable
and reset assert when rcar_canfd_global_init() fails.
Inside rcar_canfd_global_init(), if an initialization step fails, the error
path correctly cleans up:
fail_ram_clk:
clk_disable_unprepare(gpriv->clk_ram);
fail_clk:
clk_disable_unprepare(gpriv->clkp);
fail_reset2:
reset_control_assert(gpriv->rstc2);
fail_reset1:
reset_control_assert(gpriv->rstc1);
return err;
However, the error then propagates back to rcar_canfd_probe(), which jumps
to fail_mode and blindly calls rcar_canfd_global_deinit():
fail_mode:
rcar_canfd_global_deinit(gpriv, false);
Since rcar_canfd_global_deinit() disables the exact same clocks and asserts
the exact same resets again, could this result in an unbalanced clock disable
(enable count underflow) and trigger kernel warnings?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260714173315.1981708-1-claudiu.beznea+renesas@tuxon.dev?part=4
next prev parent reply other threads:[~2026-07-14 17:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 17:33 [PATCH v3 0/8] can: rcar_canfd: Add support for Renesas RZ/G3S Claudiu Beznea
2026-07-14 17:33 ` [PATCH v3 1/8] clk: r9a08g045-cpg: Add clocks and resets for CAN-FD Claudiu Beznea
2026-07-14 17:33 ` [PATCH v3 2/8] dt-bindings: can: renesas,rcar-canfd: Document RZ/G3S SoC Claudiu Beznea
2026-07-14 17:33 ` [PATCH v3 3/8] can: rcar_canfd: Fix typos in macro names Claudiu Beznea
2026-07-14 17:33 ` [PATCH v3 4/8] can: rcar_canfd: Allow the CAN FD clock to be sourced from fck Claudiu Beznea
2026-07-14 17:47 ` sashiko-bot [this message]
2026-07-14 17:33 ` [PATCH v3 5/8] can: rcar_canfd: Do not set registers selecting the CAN mode Claudiu Beznea
2026-07-14 17:33 ` [PATCH v3 6/8] can: rcar_canfd: Add support for Renesas RZ/G3S Claudiu Beznea
2026-07-14 17:49 ` sashiko-bot
2026-07-14 17:33 ` [PATCH v3 7/8] arm64: dts: renesas: r9a08g045: Add CAN-FD node Claudiu Beznea
2026-07-14 17:33 ` [PATCH v3 8/8] arm64: dts: renesas: rzg3s-smarc: Enable CAN-FD Claudiu Beznea
2026-07-14 17:54 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260714174734.7A2141F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=claudiu.beznea+renesas@tuxon.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=socketcan@hartkopp.net \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.