From: Guenter Roeck <linux@roeck-us.net>
To: void0red <void0red@gmail.com>
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org,
linux-kernel@vger.kernel.org, mezin.alexander@gmail.com
Subject: Re: [PATCH v3] hwmon: nzxt-smart2: handle failure of devm_add_action in nzxt_smart2_hid_probe
Date: Fri, 10 Mar 2023 08:42:10 -0800 [thread overview]
Message-ID: <6f835ca7-66dc-4df2-814e-ba6d94478f29@roeck-us.net> (raw)
In-Reply-To: <20230227091534.907101-1-void0red@gmail.com>
On Mon, Feb 27, 2023 at 05:15:34PM +0800, void0red wrote:
> From: Kang Chen <void0red@gmail.com>
>
> 1. replace the devm_add_action with devm_add_action_or_reset to ensure
> the mutex lock can be destroyed when it fails.
> 2. use local wrapper function mutex_fini instead of mutex_destroy to
> avoid undefined behaviours.
> 3. add a check of devm_add_action_or_reset and return early when it fails.
>
> Link: https://lore.kernel.org/all/f5043281-9b3e-e454-16fe-ef4cde36dfdb@roeck-us.net
> Signed-off-by: Kang Chen <void0red@gmail.com>
Applied.
Thanks,
Guenter
> ---
> v3 -> v2: use local function and devm_add_action_or_rest
> v2 -> v1: split the patch
>
> drivers/hwmon/nzxt-smart2.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/nzxt-smart2.c b/drivers/hwmon/nzxt-smart2.c
> index 2b93ba896..340002581 100644
> --- a/drivers/hwmon/nzxt-smart2.c
> +++ b/drivers/hwmon/nzxt-smart2.c
> @@ -721,6 +721,11 @@ static int __maybe_unused nzxt_smart2_hid_reset_resume(struct hid_device *hdev)
> return init_device(drvdata, drvdata->update_interval);
> }
>
> +static void mutex_fini(void *lock)
> +{
> + mutex_destroy(lock);
> +}
> +
> static int nzxt_smart2_hid_probe(struct hid_device *hdev,
> const struct hid_device_id *id)
> {
> @@ -737,8 +742,9 @@ static int nzxt_smart2_hid_probe(struct hid_device *hdev,
> init_waitqueue_head(&drvdata->wq);
>
> mutex_init(&drvdata->mutex);
> - devm_add_action(&hdev->dev, (void (*)(void *))mutex_destroy,
> - &drvdata->mutex);
> + ret = devm_add_action_or_reset(&hdev->dev, mutex_fini, &drvdata->mutex);
> + if (ret)
> + return ret;
>
> ret = hid_parse(hdev);
> if (ret)
next prev parent reply other threads:[~2023-03-10 16:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-27 2:17 [PATCH] hwmon: add a check of devm_add_action Kang Chen
2023-02-27 2:36 ` Guenter Roeck
2023-02-27 3:09 ` [PATCH v2 1/2] hwmon: g762: add a check of devm_add_action in g762_of_clock_enable void0red
2023-02-27 3:09 ` [PATCH v2 2/2] hwmon: nzxt-smart2: add a check of devm_add_action in nzxt_smart2_hid_probe void0red
2023-02-27 4:21 ` Guenter Roeck
2023-02-27 9:15 ` [PATCH v3] hwmon: nzxt-smart2: handle failure " void0red
2023-03-10 16:42 ` Guenter Roeck [this message]
2023-03-10 16:42 ` [PATCH v2 1/2] hwmon: g762: add a check of devm_add_action in g762_of_clock_enable Guenter Roeck
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=6f835ca7-66dc-4df2-814e-ba6d94478f29@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mezin.alexander@gmail.com \
--cc=void0red@gmail.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
all inboxes | Powered by JetHome®