From: Caleb Connolly <caleb.connolly@linaro.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: Yang Yingliang <yangyingliang@huawei.com>,
Amit Kucheria <amitk@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Zhang Rui <rui.zhang@intel.com>,
linux-pm@vger.kernel.org,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Subject: Re: [PATCH v3] thermal/core: fix error paths in __thermal_cooling_device_register()
Date: Tue, 17 Jan 2023 18:11:14 +0000 [thread overview]
Message-ID: <26cc4bea-1e0b-2d41-fbf3-aae3ab6dfcfe@linaro.org> (raw)
In-Reply-To: <CAJZ5v0ihaNHneyRwd8nWYUhGKGRpHrVFi7gJsp_g9MX=oLc9Eg@mail.gmail.com>
On 17/01/2023 13:39, Rafael J. Wysocki wrote:
> On Tue, Jan 17, 2023 at 5:36 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>>
>> On 16-01-23, 20:38, Yang Yingliang wrote:
>>> The 'cdev' will be freed after calling put_device(), it can not be accessed
>>> anymore.
>>
>> I surely missed the class's release callback :(
>>
>> How about this then, it clears this in a better way, i.e. what entity
>> is responsible for what exactly. This can be divided in a few patches
>> for sure.
>
> It looks good to me, but then I haven't caught the release bug too.
it's a fun one:
https://lore.kernel.org/linux-pm/20230101174342.58351-1-caleb.connolly@linaro.org/
I don't see any issues with this suggested patch, however I don't think
I could comfortably attach my SoB to it given the larger code reordering
and my complete lack of experience with this subsystem.
Would a Tested-by be acceptable?
>
>> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
>> index f17ab2316dbd..5555bf827a0f 100644
>> --- a/drivers/thermal/thermal_core.c
>> +++ b/drivers/thermal/thermal_core.c
>> @@ -774,6 +774,9 @@ static void thermal_release(struct device *dev)
>> } else if (!strncmp(dev_name(dev), "cooling_device",
>> sizeof("cooling_device") - 1)) {
>> cdev = to_cooling_device(dev);
>> + thermal_cooling_device_destroy_sysfs(cdev);
>> + kfree(cdev->type);
>> + ida_free(&thermal_cdev_ida, cdev->id);
>> kfree(cdev);
>> }
>> }
>> @@ -910,17 +913,18 @@ __thermal_cooling_device_register(struct device_node *np,
>>
>> ret = cdev->ops->get_max_state(cdev, &cdev->max_state);
>> if (ret)
>> - goto out_kfree_type;
>> + goto out_cdev_type;
>>
>> thermal_cooling_device_setup_sysfs(cdev);
>> ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
>> + if (ret)
>> + goto out_cooling_dev;
>> + ret = device_register(&cdev->device);
>> if (ret) {
>> - thermal_cooling_device_destroy_sysfs(cdev);
>> - goto out_kfree_type;
>> + /* thermal_release() handles rest of the cleanup */
>> + put_device(&cdev->device);
>> + return ret;
>> }
>> - ret = device_register(&cdev->device);
>> - if (ret)
>> - goto out_kfree_type;
>>
>> /* Add 'this' new cdev to the global cdev list */
>> mutex_lock(&thermal_list_lock);
>> @@ -939,11 +943,10 @@ __thermal_cooling_device_register(struct device_node *np,
>>
>> return cdev;
>>
>> -out_kfree_type:
>> +out_cooling_dev:
>> thermal_cooling_device_destroy_sysfs(cdev);
>> +out_cdev_type:
>> kfree(cdev->type);
>> - put_device(&cdev->device);
>> - cdev = NULL;
>> out_ida_remove:
>> ida_free(&thermal_cdev_ida, id);
>> out_kfree_cdev:
>> @@ -1104,11 +1107,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
>>
>> mutex_unlock(&thermal_list_lock);
>>
>> - ida_free(&thermal_cdev_ida, cdev->id);
>> - device_del(&cdev->device);
>> - thermal_cooling_device_destroy_sysfs(cdev);
>> - kfree(cdev->type);
>> - put_device(&cdev->device);
>> + device_unregister(&cdev->device);
>> }
>> EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
>>
>> --
>> viresh
--
Kind Regards,
Caleb (they/them)
next prev parent reply other threads:[~2023-01-17 18:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-12 15:47 [PATCH v3] thermal/core: fix error paths in __thermal_cooling_device_register() Caleb Connolly
2023-01-12 21:43 ` Luca Weiss
2023-01-16 4:23 ` Viresh Kumar
2023-01-16 12:22 ` Caleb Connolly
2023-01-17 4:40 ` Viresh Kumar
2023-01-16 12:38 ` Yang Yingliang
2023-01-17 4:36 ` Viresh Kumar
2023-01-17 13:39 ` Rafael J. Wysocki
2023-01-17 18:11 ` Caleb Connolly [this message]
2023-01-18 4:18 ` Viresh Kumar
2023-01-16 12:52 ` Yang Yingliang
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=26cc4bea-1e0b-2d41-fbf3-aae3ab6dfcfe@linaro.org \
--to=caleb.connolly@linaro.org \
--cc=amitk@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
--cc=viresh.kumar@linaro.org \
--cc=yangyingliang@huawei.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;
as well as URLs for NNTP newsgroup(s).