We had two memory leaks.  If guid_already_parsed returned true, we'd
leak the wmi_block.  If wmi_create_device failed, we'd leak the
device.

Simplify the logic and fix both of them.

Signed-off-by: Andy Lutomirski <l...@kernel.org>
---
 drivers/platform/x86/wmi.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 2fa9493bd35c..c181cf5ecdc6 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -835,6 +835,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;
@@ -842,19 +851,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);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" 
in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to