From patchwork Sat May 27 05:31:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Darren Hart X-Patchwork-Id: 9751575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 341BF603F1 for ; Sat, 27 May 2017 05:36:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27BC5283C5 for ; Sat, 27 May 2017 05:36:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B93428470; Sat, 27 May 2017 05:36:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDACC2846C for ; Sat, 27 May 2017 05:36:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752164AbdE0FcF (ORCPT ); Sat, 27 May 2017 01:32:05 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:49128 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752115AbdE0Fbs (ORCPT ); Sat, 27 May 2017 01:31:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PHafM8NUosl7oFp+9px3YvCszX6RfP8GbCT8NJBHRFw=; b=svY3U4AdSbowadK2u/IcVHM9j 5pgFhfB+hsWpWSS1IgxZlG+ACXOWEG1K9TSxybW/bGVT/sMfDgVwqMTcDEzru9RJ9/tDLDbglYnCe BoJTVpF21Gij/JXySENyHrpdMyQd5iJCL1Dl7xWPbHFS0VsC/+sBAF5A93zMg2NSvid3pms14Xmok g+8AhCzElNspAgzhuNLXM8/QJ8eIjtkduJCISmUpFt8fnhi/Vz4vg55OUtBjJy9UVXe3CSIZbOYvc UJQXjJDTz3fs1UhmiRKSeNb18TcCY/mgi/R13zpR5gIxb1Q8l1J66oLOHlS4MDfXbG8j6LwQt/tex RBq5AVloA==; Received: from dvhart by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1dEUKJ-0000fU-GW; Sat, 27 May 2017 05:31:47 +0000 From: Darren Hart To: platform-driver-x86@vger.kernel.org Cc: Andy Shevchenko , Andy Lutomirski , Andy Lutomirski , Mario Limonciello , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Rafael Wysocki , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Darren Hart Subject: [PATCH 06/16] platform/x86: wmi: Fix error handling when creating devices Date: Fri, 26 May 2017 22:31:20 -0700 Message-Id: <99f96cee64db588a3846332162aaccb11aa8641b.1495862272.git.dvhart@infradead.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 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 From: Andy Lutomirski 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: Rafael Wysocki Cc: linux-kernel@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org Cc: linux-acpi@vger.kernel.org Signed-off-by: Darren Hart (VMware) --- 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 f06b7c0..31c317f 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);