aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@kernel.org>2015-11-25 11:24:42 -0500
committerDarren Hart (VMware) <dvhart@infradead.org>2017-06-06 13:15:18 -0400
commita1c31bcd5772b13b39b028126fa9de918c36cf26 (patch)
treed00d06de011ba692119731a7cf68e7edd4bf7065
parent844af950da946cfab227a04b950614da04cb6275 (diff)
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 <luto@kernel.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Mario Limonciello <mario_limonciello@dell.com> Cc: Pali Rohár <pali.rohar@gmail.com> Cc: linux-kernel@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org Cc: linux-acpi@vger.kernel.org Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
-rw-r--r--drivers/platform/x86/wmi.c28
1 files changed, 15 insertions, 13 deletions
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)
757 if (debug_dump_wdg) 757 if (debug_dump_wdg)
758 wmi_dump_wdg(&gblock[i]); 758 wmi_dump_wdg(&gblock[i]);
759 759
760 /*
761 * Some WMI devices, like those for nVidia hooks, have a
762 * duplicate GUID. It's not clear what we should do in this
763 * case yet, so for now, we'll just ignore the duplicate
764 * for device creation.
765 */
766 if (guid_already_parsed(device, gblock[i].guid))
767 continue;
768
760 wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL); 769 wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
761 if (!wblock) 770 if (!wblock)
762 return -ENOMEM; 771 return -ENOMEM;
@@ -764,19 +773,12 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
764 wblock->acpi_device = device; 773 wblock->acpi_device = device;
765 wblock->gblock = gblock[i]; 774 wblock->gblock = gblock[i];
766 775
767 /* 776 retval = wmi_create_device(wmi_bus_dev, &gblock[i],
768 Some WMI devices, like those for nVidia hooks, have a 777 wblock, device);
769 duplicate GUID. It's not clear what we should do in this 778 if (retval) {
770 case yet, so for now, we'll just ignore the duplicate 779 put_device(&wblock->dev.dev);
771 for device creation. 780 wmi_free_devices(device);
772 */ 781 goto out_free_pointer;
773 if (!guid_already_parsed(device, gblock[i].guid)) {
774 retval = wmi_create_device(wmi_bus_dev, &gblock[i],
775 wblock, device);
776 if (retval) {
777 wmi_free_devices(device);
778 goto out_free_pointer;
779 }
780 } 782 }
781 783
782 list_add_tail(&wblock->list, &wmi_block_list); 784 list_add_tail(&wblock->list, &wmi_block_list);