From patchwork Tue Dec 1 01:05:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Lutomirski X-Patchwork-Id: 7731501 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9A52BBEEE1 for ; Tue, 1 Dec 2015 01:06:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D16D520674 for ; Tue, 1 Dec 2015 01:06:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06A5E20692 for ; Tue, 1 Dec 2015 01:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755040AbbLABGT (ORCPT ); Mon, 30 Nov 2015 20:06:19 -0500 Received: from mail.kernel.org ([198.145.29.136]:46745 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755075AbbLABGR (ORCPT ); Mon, 30 Nov 2015 20:06:17 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CEA1320665; Tue, 1 Dec 2015 01:06:16 +0000 (UTC) Received: from localhost (c-71-202-137-17.hsd1.ca.comcast.net [71.202.137.17]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DAB3920674; Tue, 1 Dec 2015 01:06:15 +0000 (UTC) From: Andy Lutomirski To: Darren Hart Cc: Matthew Garrett , linux-acpi@vger.kernel.org, platform-driver-x86@vger.kernel.org, Mario Limonciello , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Andy Lutomirski Subject: [PATCH 06/14] wmi: Fix error handling when creating devices Date: Mon, 30 Nov 2015 17:05:56 -0800 Message-Id: <5da108e9e36b235fff41da575658192e817c71c4.1448931782.git.luto@kernel.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: References: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);