summaryrefslogtreecommitdiff
path: root/drivers/hwmon/nzxt-smart2.c
diff options
context:
space:
mode:
authorKang Chen <void0red@gmail.com>2023-02-27 12:15:34 +0300
committerGuenter Roeck <linux@roeck-us.net>2023-04-19 17:08:31 +0300
commitdbfeafdad31c52da8965819a298ed3b0127025e7 (patch)
treece5c2c22c84c40aad002a70d8a5be99c95f8411c /drivers/hwmon/nzxt-smart2.c
parent37ef30fbf2894e1acd5aa7cc1dccfc54039cecd5 (diff)
downloadlinux-dbfeafdad31c52da8965819a298ed3b0127025e7.tar.xz
hwmon: (nzxt-smart2) handle failure of devm_add_action in nzxt_smart2_hid_probe
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> Link: https://lore.kernel.org/r/20230227091534.907101-1-void0red@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/nzxt-smart2.c')
-rw-r--r--drivers/hwmon/nzxt-smart2.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/hwmon/nzxt-smart2.c b/drivers/hwmon/nzxt-smart2.c
index a8e72d8fd060..e5edf8071f39 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)