linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: daniel.lezcano@linaro.org, rafael@kernel.org
Cc: rui.zhang@intel.com, amitk@kernel.org,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Ray Jui" <rjui@broadcom.com>,
	"Scott Branden" <sbranden@broadcom.com>,
	"Broadcom internal kernel review list"
	<bcm-kernel-feedback-list@broadcom.com>,
	"Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
	"ye xingchen" <ye.xingchen@zte.com.cn>,
	"Thierry Reding" <treding@nvidia.com>,
	linux-pm@vger.kernel.org (open list:THERMAL),
	linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM
	BCM2711/BCM2835 ARM ARCHITECTURE),
	linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM
	BCM2711/BCM2835 ARM ARCHITECTURE),
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v1 07/11] thermal/drivers/bcm2835: Remove buggy call to thermal_of_zone_unregister
Date: Tue,  7 Mar 2023 14:37:31 +0100	[thread overview]
Message-ID: <20230307133735.90772-8-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <20230307133735.90772-1-daniel.lezcano@linaro.org>

The driver is using the devm_thermal_of_zone_device_register().

In the error path of the function calling
devm_thermal_of_zone_device_register(), the function
devm_thermal_of_zone_unregister() should be called instead of
thermal_of_zone_unregister(), otherwise this one will be called twice
when the device is freed.

The same happens for the remove function where the devm_ guarantee the
thermal_of_zone_unregister() will be called, so adding this call in
the remove function will lead to a double free also.

Use devm_ variant in the error path of the probe function.

Remove thermal_of_zone_unregister() in the remove function.

Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Ray Jui <rjui@broadcom.com>
Cc: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/broadcom/bcm2835_thermal.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/broadcom/bcm2835_thermal.c b/drivers/thermal/broadcom/bcm2835_thermal.c
index a217d832f24e..ea07152a6d0d 100644
--- a/drivers/thermal/broadcom/bcm2835_thermal.c
+++ b/drivers/thermal/broadcom/bcm2835_thermal.c
@@ -269,13 +269,13 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
 	 */
 	err = thermal_add_hwmon_sysfs(tz);
 	if (err)
-		goto err_tz;
+		goto err_clk;
 
 	bcm2835_thermal_debugfs(pdev);
 
 	return 0;
 err_tz:
-	thermal_of_zone_unregister(tz);
+	devm_thermal_of_zone_unregister(&pdev->dev, tz);
 err_clk:
 	clk_disable_unprepare(data->clk);
 
@@ -285,10 +285,8 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
 static int bcm2835_thermal_remove(struct platform_device *pdev)
 {
 	struct bcm2835_thermal_data *data = platform_get_drvdata(pdev);
-	struct thermal_zone_device *tz = data->tz;
 
 	debugfs_remove_recursive(data->debugfsdir);
-	thermal_of_zone_unregister(tz);
 	clk_disable_unprepare(data->clk);
 
 	return 0;
-- 
2.34.1


  parent reply	other threads:[~2023-03-07 13:38 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230307133735.90772-1-daniel.lezcano@linaro.org>
2023-03-07 13:37 ` [PATCH v1 01/11] thermal/core: Relocate the traces definition in thermal directory Daniel Lezcano
2023-03-07 15:51   ` Steven Rostedt
2023-03-07 13:37 ` [PATCH v1 02/11] thermal/drivers/intel_pch_thermal: Use thermal driver device to write a trace Daniel Lezcano
2023-03-07 13:37 ` [PATCH v1 03/11] thermal/drivers/intel_menlow: Remove add_one_attribute Daniel Lezcano
2023-03-13 10:55   ` Daniel Lezcano
2023-03-13 12:26     ` Rafael J. Wysocki
2023-03-13 12:35       ` Daniel Lezcano
2023-03-17 18:18         ` Rafael J. Wysocki
2023-04-04 18:12           ` Daniel Lezcano
2023-04-04 18:14             ` Rafael J. Wysocki
2023-03-07 13:37 ` [PATCH v1 04/11] thermal/drivers/db8500: Use driver dev instead of tz->device Daniel Lezcano
2023-03-07 20:52   ` Linus Walleij
2023-03-07 13:37 ` [PATCH v1 05/11] thermal/drivers/stm: Don't set no_hwmon to false Daniel Lezcano
2023-03-07 13:37 ` [PATCH v1 06/11] thermal/drivers/ti: Use fixed update interval Daniel Lezcano
2023-03-07 13:47   ` J, KEERTHY
2023-03-07 15:30   ` Gole, Dhruva
2023-03-07 13:37 ` Daniel Lezcano [this message]
2023-03-07 13:37 ` [PATCH v1 08/11] thermal/of: Unexport unused OF functions Daniel Lezcano
2023-03-07 13:37 ` [PATCH v1 09/11] thermal/core: Add a linked device parameter Daniel Lezcano
2023-03-27 16:16   ` Rafael J. Wysocki
2023-04-04 19:01     ` Daniel Lezcano
2023-04-14 18:43       ` Rafael J. Wysocki
2023-03-07 13:37 ` [PATCH v1 10/11] thermal/core: Alloc-copy-free the thermal zone parameters structure Daniel Lezcano
2023-03-15 12:54   ` kernel test robot
2023-03-18  9:07   ` 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=20230307133735.90772-8-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=amitk@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=f.fainelli@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=rafael@kernel.org \
    --cc=rjui@broadcom.com \
    --cc=rui.zhang@intel.com \
    --cc=sbranden@broadcom.com \
    --cc=treding@nvidia.com \
    --cc=ye.xingchen@zte.com.cn \
    /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;
as well as URLs for NNTP newsgroup(s).