Skip to content

Commit b6b5669

Browse files
Wer-Wolfij-intel
authored andcommitted
platform/x86: wmi: Use devres to disable the WMI device
Use devm_add_action_or_reset() to disable the WMI device instead of manually calling wmi_method_enable() to prepare for future changes inside the WMI data block handlign code. The reason for this is that we have to make sure that all devres-managed resources are released first because some might still want to access the underlying WMI device. Because devres-managed resources are not released during shutdown we still have to manually disable the WMI device in this case. Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://lore.kernel.org/r/20250216193251.866125-6-W_Armin@gmx.de Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 0fcc316 commit b6b5669

File tree

1 file changed

+22
-9
lines changed
  • drivers/platform/x86

1 file changed

+22
-9
lines changed

drivers/platform/x86/wmi.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,19 @@ static int wmi_dev_match(struct device *dev, const struct device_driver *driver)
821821
return 0;
822822
}
823823

824+
static void wmi_dev_disable(void *data)
825+
{
826+
struct wmi_block *wblock = data;
827+
828+
if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
829+
dev_warn(&wblock->dev.dev, "Failed to disable device\n");
830+
}
831+
824832
static int wmi_dev_probe(struct device *dev)
825833
{
826834
struct wmi_block *wblock = dev_to_wblock(dev);
827835
struct wmi_driver *wdriver = to_wmi_driver(dev->driver);
828-
int ret = 0;
836+
int ret;
829837

830838
/* Some older WMI drivers will break if instantiated multiple times,
831839
* so they are blocked from probing WMI devices with a duplicated GUID.
@@ -847,15 +855,19 @@ static int wmi_dev_probe(struct device *dev)
847855
if (ACPI_FAILURE(wmi_method_enable(wblock, true)))
848856
dev_warn(dev, "failed to enable device -- probing anyway\n");
849857

858+
/*
859+
* We have to make sure that all devres-managed resources are released first because
860+
* some might still want to access the underlying WMI device.
861+
*/
862+
ret = devm_add_action_or_reset(dev, wmi_dev_disable, wblock);
863+
if (ret < 0)
864+
return ret;
865+
850866
if (wdriver->probe) {
851867
ret = wdriver->probe(to_wmi_device(dev),
852868
find_guid_context(wblock, wdriver));
853-
if (ret) {
854-
if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
855-
dev_warn(dev, "Failed to disable device\n");
856-
869+
if (ret)
857870
return ret;
858-
}
859871
}
860872

861873
down_write(&wblock->notify_lock);
@@ -876,9 +888,6 @@ static void wmi_dev_remove(struct device *dev)
876888

877889
if (wdriver->remove)
878890
wdriver->remove(to_wmi_device(dev));
879-
880-
if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
881-
dev_warn(dev, "failed to disable device\n");
882891
}
883892

884893
static void wmi_dev_shutdown(struct device *dev)
@@ -902,6 +911,10 @@ static void wmi_dev_shutdown(struct device *dev)
902911
if (wdriver->shutdown)
903912
wdriver->shutdown(to_wmi_device(dev));
904913

914+
/*
915+
* We still need to disable the WMI device here since devres-managed resources
916+
* like wmi_dev_disable() will not be release during shutdown.
917+
*/
905918
if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
906919
dev_warn(dev, "Failed to disable device\n");
907920
}

0 commit comments

Comments
 (0)