From: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
To: Dan Carpenter <error27@gmail.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Magnus Damm <magnus.damm@gmail.com>,
linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] thermal/drivers/rcar: add error checking in probe()
Date: Tue, 23 Jun 2026 10:18:22 +0200 [thread overview]
Message-ID: <20260623081822.GB3937090@ragnatech.se> (raw)
In-Reply-To: <ajo6iQ3VWvcxedA9@stanley.mountain>
Hi Dan,
Thanks for your work.
On 2026-06-23 10:49:29 +0300, Dan Carpenter wrote:
> The thermal_zone_device_register_with_trips() can fail for a number of
> reasons, including allocation failures. Check for error pointers to
> avoid an error pointer dereference.
>
> Fixes: 9d617949d490 ("thermal/drivers/renesas: Group all renesas thermal drivers together")
I don't think this is correct as this commits just moves the file.
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
> drivers/thermal/renesas/rcar_thermal.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/thermal/renesas/rcar_thermal.c b/drivers/thermal/renesas/rcar_thermal.c
> index 6e5dcac5d47a..71f836fbc698 100644
> --- a/drivers/thermal/renesas/rcar_thermal.c
> +++ b/drivers/thermal/renesas/rcar_thermal.c
> @@ -492,6 +492,11 @@ static int rcar_thermal_probe(struct platform_device *pdev)
> "rcar_thermal", trips, ARRAY_SIZE(trips), priv,
> &rcar_thermal_zone_ops, NULL, 0,
> idle);
> + if (IS_ERR(priv->zone)) {
> + ret = PTR_ERR(priv->zone);
> + priv->zone = NULL;
> + goto error_unregister;
> + }
While this indeed is an issue that should be fixed I don't think this is
the correct fix. Below the if .. else .. block where this is added there
already is a check for IS_ERR(priv->zone). That however does not guard
against the usage of priv->zone for thermal_zone_device_enable().
We should only call thermal_zone_device_enable() if we are on a system
that uses OF (gated by chip->use_of_thermal) which is the reason for the
if .. else .. block in the first place. As chance have it we also have a
check on chip->use_of_thermal directly after the existing
IS_ERR(priv->zone) check. I think it would be better to move the call to
thermal_zone_device_enable() there and avoid having two checks for
IS_ERR(priv->zone)? Something like this,
diff --git a/drivers/thermal/renesas/rcar_thermal.c b/drivers/thermal/renesas/rcar_thermal.c
index 6e5dcac5d47a..dd13cf971ddb 100644
--- a/drivers/thermal/renesas/rcar_thermal.c
+++ b/drivers/thermal/renesas/rcar_thermal.c
@@ -492,12 +492,6 @@ static int rcar_thermal_probe(struct platform_device *pdev)
"rcar_thermal", trips, ARRAY_SIZE(trips), priv,
&rcar_thermal_zone_ops, NULL, 0,
idle);
-
- ret = thermal_zone_device_enable(priv->zone);
- if (ret) {
- thermal_zone_device_unregister(priv->zone);
- priv->zone = ERR_PTR(ret);
- }
}
if (IS_ERR(priv->zone)) {
dev_err(dev, "can't register thermal zone\n");
@@ -507,13 +501,16 @@ static int rcar_thermal_probe(struct platform_device *pdev)
}
if (chip->use_of_thermal) {
+ ret = thermal_zone_device_enable(priv->zone);
+ if (ret)
+ goto error_of_thermal;
+
ret = thermal_add_hwmon_sysfs(priv->zone);
if (ret)
- goto error_unregister;
+ goto error_of_thermal;
}
rcar_thermal_irq_enable(priv);
-
list_move_tail(&priv->list, &common->head);
/* update ENR bits */
@@ -528,6 +525,8 @@ static int rcar_thermal_probe(struct platform_device *pdev)
return 0;
+error_of_thermal:
+ thermal_zone_device_unregister(priv->zone);
error_unregister:
rcar_thermal_remove(pdev);
>
> ret = thermal_zone_device_enable(priv->zone);
> if (ret) {
> --
> 2.53.0
>
--
Kind Regards,
Niklas Söderlund
next prev parent reply other threads:[~2026-06-23 8:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 7:49 [PATCH] thermal/drivers/rcar: add error checking in probe() Dan Carpenter
2026-06-23 8:03 ` Geert Uytterhoeven
2026-06-23 8:13 ` Dan Carpenter
2026-06-23 8:18 ` Niklas Söderlund [this message]
2026-06-23 8:25 ` Dan Carpenter
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=20260623081822.GB3937090@ragnatech.se \
--to=niklas.soderlund+renesas@ragnatech.se \
--cc=daniel.lezcano@kernel.org \
--cc=error27@gmail.com \
--cc=geert+renesas@glider.be \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=magnus.damm@gmail.com \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox