[PATCH] platform/x86: wmi: Apply fixes per MichaÅ KÄpieÅ (squash)

From: Darren Hart (VMware)
Date: Mon Jun 05 2017 - 22:54:03 EST


Per:
https://www.spinics.net/lists/platform-driver-x86/msg08201.html

Eliminate the kfree of a wblock with a null bus now that we ignore
duplicate GUIDs in parse_wdg.

Move the out_free_pointer: label and kfree to the end of the function,
clearly marking it as a return path.

Rework the device_add loop at the end of parse_wdg to avoid leaking the
wblock, and symmetrically call wmi_method_enable() if (debug_event).

Signed-off-by: Darren Hart (VMware) <dvhart@xxxxxxxxxxxxx>
---
drivers/platform/x86/wmi.c | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index bfc0a3f..fbce876 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -863,14 +863,7 @@ static void wmi_free_devices(struct acpi_device *device)
list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
if (wblock->acpi_device == device) {
list_del(&wblock->list);
- if (wblock->dev.dev.bus) {
- /* Device was initialized. */
- device_del(&wblock->dev.dev);
- put_device(&wblock->dev.dev);
- } else {
- /* device_initialize was not called. */
- kfree(wblock);
- }
+ device_unregister(&wblock->dev.dev);
}
}
}
@@ -903,9 +896,9 @@ static bool guid_already_parsed(struct acpi_device *device,
static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
{
struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
- union acpi_object *obj;
const struct guid_block *gblock;
struct wmi_block *wblock, *next;
+ union acpi_object *obj;
acpi_status status;
int retval = 0;
u32 i, total;
@@ -958,24 +951,27 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
}
}

-out_free_pointer:
- kfree(out.pointer);
-
/*
* Now that all of the devices are created, add them to the
* device tree and probe subdrivers.
*/
list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
- if (wblock->acpi_device == device) {
- if (device_add(&wblock->dev.dev) != 0) {
- dev_err(wmi_bus_dev,
- "failed to register %pULL\n",
- wblock->gblock.guid);
- list_del(&wblock->list);
- }
+ if (wblock->acpi_device != device)
+ continue;
+
+ retval = device_add(&wblock->dev.dev);
+ if (retval) {
+ dev_err(wmi_bus_dev, "failed to register %pULL\n",
+ wblock->gblock.guid);
+ if (debug_event)
+ wmi_method_enable(wblock, 0);
+ list_del(&wblock->list);
+ put_device(&wblock->dev.dev);
}
}

+out_free_pointer:
+ kfree(out.pointer);
return retval;
}

--
2.9.4


--
Darren Hart
VMware Open Source Technology Center