Skip to contentSkip to conversation

platform/x86: dell-wmi-ddv: switch sensor mutex to devm_mutex_init()

PATCH In review [email protected] 2 participants 3 messages Oct 27 – Nov 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: dell-wmi-ddv: switch sensor mutex to devm_mutex_init()

From: Chitransh Mandhaniya <[email protected]>

Replace mutex_init() with devm_mutex_init() for the sensor caching mutex so the mutex lifecycle is managed by devres. This allows removing the manual mutex_destroy() call from the dell_wmi_ddv_hwmon_cache_destroy() cleanup callback.

The translation_cache_lock in the same driver already uses devm_mutex_init(); this brings the sensor lock in line.

---
 drivers/platform/x86/dell/dell-wmi-ddv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/dell/dell-wmi-ddv.c +3 -2
index f8903ced461b..c7f3d07abbc7 100644
@@ -548,7 +548,6 @@ static void dell_wmi_ddv_hwmon_cache_destroy(void *data)
 	struct dell_wmi_ddv_sensors *sensors = data;
 
 	sensors->active = false;
-	mutex_destroy(&sensors->lock);
 	kfree(sensors->buffer);
 }
 
@@ -566,7 +565,9 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_init(struct wmi_device *w
 	if (ret < 0)
 		return ERR_PTR(ret);
 
-	mutex_init(&sensors->lock);
+	ret = devm_mutex_init(&wdev->dev, &sensors->lock);
+	if (ret < 0)
+		return ERR_PTR(ret);
 	sensors->active = true;
 
 	ret = devm_add_action_or_reset(&wdev->dev, dell_wmi_ddv_hwmon_cache_destroy, sensors);
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Am 27.10.26 um 05:48 schrieb [email protected]:

Quoted 9 lines

From: Chitransh Mandhaniya <[email protected]>

Replace mutex_init() with devm_mutex_init() for the sensor caching mutex so the mutex lifecycle is managed by devres. This allows removing the manual mutex_destroy() call from the dell_wmi_ddv_hwmon_cache_destroy() cleanup callback.

The translation_cache_lock in the same driver already uses devm_mutex_init(); this brings the sensor lock in line.

Hi,

thanks for the patch, but now sensors->lock will remain initialized even when dell_wmi_ddv_channel_create() fails. To be honest i do not think that using devm_mutex_init() makes much sense here, because the lifetime of the sensor cache can end before the device lifetime (if dell_wmi_ddv_channel_create() returns an error).

Thanks,
Armin Wolf

Quoted 28 lines
---
  drivers/platform/x86/dell/dell-wmi-ddv.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/dell/dell-wmi-ddv.c +3 -2
index f8903ced461b..c7f3d07abbc7 100644
@@ -548,7 +548,6 @@ static void dell_wmi_ddv_hwmon_cache_destroy(void *data)
  	struct dell_wmi_ddv_sensors *sensors = data;
 
  	sensors->active = false;
-	mutex_destroy(&sensors->lock);
  	kfree(sensors->buffer);
  }
 
@@ -566,7 +565,9 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_init(struct wmi_device *w
  	if (ret < 0)
  		return ERR_PTR(ret);
 
-	mutex_init(&sensors->lock);
+	ret = devm_mutex_init(&wdev->dev, &sensors->lock);
+	if (ret < 0)
+		return ERR_PTR(ret);
  	sensors->active = true;
 
  	ret = devm_add_action_or_reset(&wdev->dev, dell_wmi_ddv_hwmon_cache_destroy, sensors);
#2 lore raw

From: Chitransh Mandhaniya <[email protected]>

Hi Armin,

Thank you for the review. You are right, the sensor cache lifetime can end before the device lifetime when dell_wmi_ddv_channel_create() fails, so tying the mutex to devres is not appropriate here.

I will drop this patch.

Thanks,
Chitransh
---