Skip to contentSkip to conversation

hwmon: (occ) Lock mutex in shutdown to prevent race with occ_active

PATCH Applied Eddie James 2 participants 2 messages Jun 6, 2022 – Jun 7, 2022 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (occ) Lock mutex in shutdown to prevent race with occ_active

Unbinding the driver or removing the parent device at the same time as using the OCC active sysfs file can cause the driver to unregister the hwmon device twice. Prevent this by locking the occ mutex in the shutdown function.

---
 drivers/hwmon/occ/common.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/hwmon/occ/common.c +5 -0
index d78f4bebc718..ea070b91e5b9 100644
@@ -1228,10 +1228,15 @@ EXPORT_SYMBOL_GPL(occ_setup);
 
 void occ_shutdown(struct occ *occ)
 {
+	mutex_lock(&occ->lock);
+
 	occ_shutdown_sysfs(occ);
 
 	if (occ->hwmon)
 		hwmon_device_unregister(occ->hwmon);
+	occ->hwmon = NULL;
+
+	mutex_unlock(&occ->lock);
 }
 EXPORT_SYMBOL_GPL(occ_shutdown);
 
Signature · 1 line
2.31.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Eddie James

Unbinding the driver or removing the parent device at the same time as using the OCC active sysfs file can cause the driver to unregister the hwmon device twice. Prevent this by locking the occ mutex in the shutdown function.

Applied.

Thanks,
Guenter

Quoted 24 lines
---
 drivers/hwmon/occ/common.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/hwmon/occ/common.c +5 -0
index d78f4bebc718..ea070b91e5b9 100644
@@ -1228,10 +1228,15 @@ EXPORT_SYMBOL_GPL(occ_setup);
 
 void occ_shutdown(struct occ *occ)
 {
+	mutex_lock(&occ->lock);
+
 	occ_shutdown_sysfs(occ);
 
 	if (occ->hwmon)
 		hwmon_device_unregister(occ->hwmon);
+	occ->hwmon = NULL;
+
+	mutex_unlock(&occ->lock);
 }
 EXPORT_SYMBOL_GPL(occ_shutdown);