All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yue Hu <zbestahu@gmail.com>
To: rui.zhang@intel.com, edubezval@gmail.com, daniel.lezcano@linaro.org
Cc: linux-pm@vger.kernel.org, huyue2@yulong.com, zhangwen@yulong.com
Subject: [PATCH] thermal/drivers/core: Use put_device() if device_register() fails
Date: Fri,  2 Aug 2019 14:55:20 +0800	[thread overview]
Message-ID: <20190802065520.3744-1-zbestahu@gmail.com> (raw)

From: Yue Hu <huyue2@yulong.com>

Never directly free @dev after calling device_register(), even if it
returned an error! Always use put_device() to give up the reference
initialized.

Signed-off-by: Yue Hu <huyue2@yulong.com>
---
 drivers/thermal/thermal_core.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 6bab66e..ffe5d8e 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -985,7 +985,7 @@ static void bind_cdev(struct thermal_cooling_device *cdev)
 	result = device_register(&cdev->device);
 	if (result) {
 		ida_simple_remove(&thermal_cdev_ida, cdev->id);
-		kfree(cdev);
+		put_device(&cdev->device);
 		return ERR_PTR(result);
 	}
 
@@ -1292,7 +1292,7 @@ struct thermal_zone_device *
 	dev_set_name(&tz->device, "thermal_zone%d", tz->id);
 	result = device_register(&tz->device);
 	if (result)
-		goto remove_device_groups;
+		goto release_device;
 
 	for (count = 0; count < trips; count++) {
 		if (tz->ops->get_trip_type(tz, count, &trip_type))
@@ -1347,8 +1347,11 @@ struct thermal_zone_device *
 	device_unregister(&tz->device);
 	return ERR_PTR(result);
 
-remove_device_groups:
-	thermal_zone_destroy_device_groups(tz);
+release_device:
+	ida_simple_remove(&thermal_tz_ida, tz->id);
+	put_device(&tz->device);
+	return ERR_PTR(result);
+
 remove_id:
 	ida_simple_remove(&thermal_tz_ida, tz->id);
 free_tz:
-- 
1.9.1


                 reply	other threads:[~2019-08-02  6:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190802065520.3744-1-zbestahu@gmail.com \
    --to=zbestahu@gmail.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=edubezval@gmail.com \
    --cc=huyue2@yulong.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=zhangwen@yulong.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.