Skip to content

Commit 001f61c

Browse files
Wer-Wolfjwrdegoede
authored andcommitted
platform/x86: dell-ddv: Fix cache invalidation on resume
If one or both sensor buffers could not be initialized, either due to missing hardware support or due to some error during probing, the resume handler will encounter undefined behaviour when attempting to lock buffers then protected by an uninitialized or destroyed mutex. Fix this by introducing a "active" flag which is set during probe, and only invalidate buffers which where flaged as "active". Tested on a Dell Inspiron 3505. Fixes: 3b7eeff ("platform/x86: dell-ddv: Add hwmon support") Signed-off-by: Armin Wolf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Hans de Goede <[email protected]>
1 parent 24efcdf commit 001f61c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/platform/x86/dell/dell-wmi-ddv.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct combined_chip_info {
9696
};
9797

9898
struct dell_wmi_ddv_sensors {
99+
bool active;
99100
struct mutex lock; /* protect caching */
100101
unsigned long timestamp;
101102
union acpi_object *obj;
@@ -520,6 +521,9 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_create(struct device *dev
520521

521522
static void dell_wmi_ddv_hwmon_cache_invalidate(struct dell_wmi_ddv_sensors *sensors)
522523
{
524+
if (!sensors->active)
525+
return;
526+
523527
mutex_lock(&sensors->lock);
524528
kfree(sensors->obj);
525529
sensors->obj = NULL;
@@ -530,6 +534,7 @@ static void dell_wmi_ddv_hwmon_cache_destroy(void *data)
530534
{
531535
struct dell_wmi_ddv_sensors *sensors = data;
532536

537+
sensors->active = false;
533538
mutex_destroy(&sensors->lock);
534539
kfree(sensors->obj);
535540
}
@@ -549,6 +554,7 @@ static struct hwmon_channel_info *dell_wmi_ddv_channel_init(struct wmi_device *w
549554
return ERR_PTR(ret);
550555

551556
mutex_init(&sensors->lock);
557+
sensors->active = true;
552558

553559
ret = devm_add_action_or_reset(&wdev->dev, dell_wmi_ddv_hwmon_cache_destroy, sensors);
554560
if (ret < 0)
@@ -852,7 +858,7 @@ static int dell_wmi_ddv_resume(struct device *dev)
852858
{
853859
struct dell_wmi_ddv_data *data = dev_get_drvdata(dev);
854860

855-
/* Force re-reading of all sensors */
861+
/* Force re-reading of all active sensors */
856862
dell_wmi_ddv_hwmon_cache_invalidate(&data->fans);
857863
dell_wmi_ddv_hwmon_cache_invalidate(&data->temps);
858864

0 commit comments

Comments
 (0)