From: Andy Lutomirski Date: Wed, 25 Nov 2015 16:24:42 +0000 (-0800) Subject: platform/x86: wmi: Fix error handling when creating devices X-Git-Tag: MMI-PSA29.97-13-9~5166^2~55 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a1c31bcd5772b13b39b028126fa9de918c36cf26;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git platform/x86: wmi: Fix error handling when creating devices We have two memory leaks. If guid_already_parsed returned true, we leak the wmi_block. If wmi_create_device failed, we leak the device. Simplify the logic and fix both of them. Signed-off-by: Andy Lutomirski Cc: Andy Lutomirski Cc: Mario Limonciello Cc: Pali Rohár Cc: linux-kernel@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org Cc: linux-acpi@vger.kernel.org Acked-by: Rafael J. Wysocki Signed-off-by: Darren Hart (VMware) --- diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index f06b7c00339d..31c317fb65dc 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -757,6 +757,15 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device) if (debug_dump_wdg) wmi_dump_wdg(&gblock[i]); + /* + * Some WMI devices, like those for nVidia hooks, have a + * duplicate GUID. It's not clear what we should do in this + * case yet, so for now, we'll just ignore the duplicate + * for device creation. + */ + if (guid_already_parsed(device, gblock[i].guid)) + continue; + wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL); if (!wblock) return -ENOMEM; @@ -764,19 +773,12 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device) wblock->acpi_device = device; wblock->gblock = gblock[i]; - /* - Some WMI devices, like those for nVidia hooks, have a - duplicate GUID. It's not clear what we should do in this - case yet, so for now, we'll just ignore the duplicate - for device creation. - */ - if (!guid_already_parsed(device, gblock[i].guid)) { - retval = wmi_create_device(wmi_bus_dev, &gblock[i], - wblock, device); - if (retval) { - wmi_free_devices(device); - goto out_free_pointer; - } + retval = wmi_create_device(wmi_bus_dev, &gblock[i], + wblock, device); + if (retval) { + put_device(&wblock->dev.dev); + wmi_free_devices(device); + goto out_free_pointer; } list_add_tail(&wblock->list, &wmi_block_list);