Skip to content

Commit

Permalink
platform/x86: wmi: Use devres to disable the WMI device
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Armin Wolf authored and Ilpo Järvinen committed Feb 24, 2025
1 parent 0fcc316 commit b6b5669
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions drivers/platform/x86/wmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,19 @@ static int wmi_dev_match(struct device *dev, const struct device_driver *driver)
return 0;
}

static void wmi_dev_disable(void *data)
{
struct wmi_block *wblock = data;

if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
dev_warn(&wblock->dev.dev, "Failed to disable device\n");
}

static int wmi_dev_probe(struct device *dev)
{
struct wmi_block *wblock = dev_to_wblock(dev);
struct wmi_driver *wdriver = to_wmi_driver(dev->driver);
int ret = 0;
int ret;

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

/*
* We have to make sure that all devres-managed resources are released first because
* some might still want to access the underlying WMI device.
*/
ret = devm_add_action_or_reset(dev, wmi_dev_disable, wblock);
if (ret < 0)
return ret;

if (wdriver->probe) {
ret = wdriver->probe(to_wmi_device(dev),
find_guid_context(wblock, wdriver));
if (ret) {
if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
dev_warn(dev, "Failed to disable device\n");

if (ret)
return ret;
}
}

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

if (wdriver->remove)
wdriver->remove(to_wmi_device(dev));

if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
dev_warn(dev, "failed to disable device\n");
}

static void wmi_dev_shutdown(struct device *dev)
Expand All @@ -902,6 +911,10 @@ static void wmi_dev_shutdown(struct device *dev)
if (wdriver->shutdown)
wdriver->shutdown(to_wmi_device(dev));

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

0 comments on commit b6b5669

Please sign in to comment.