From patchwork Fri Sep 2 07:46:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lv Zheng X-Patchwork-Id: 9310503 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 99E1A607D2 for ; Fri, 2 Sep 2016 07:46:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DFAB296D3 for ; Fri, 2 Sep 2016 07:46:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82FF7296D6; Fri, 2 Sep 2016 07:46:50 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 D699F296D3 for ; Fri, 2 Sep 2016 07:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750979AbcIBHqr (ORCPT ); Fri, 2 Sep 2016 03:46:47 -0400 Received: from mga11.intel.com ([192.55.52.93]:25082 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752043AbcIBHqq (ORCPT ); Fri, 2 Sep 2016 03:46:46 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 02 Sep 2016 00:46:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,270,1470726000"; d="scan'208";a="1034594044" Received: from lvzheng-z530.sh.intel.com ([10.239.159.35]) by fmsmga001.fm.intel.com with ESMTP; 02 Sep 2016 00:46:42 -0700 From: Lv Zheng To: "Rafael J. Wysocki" , "Rafael J. Wysocki" , Len Brown Cc: Lv Zheng , Lv Zheng , linux-acpi@vger.kernel.org, Peter Wu , Luya Tshimbalanga Subject: [PATCH 2/4] ACPI / EC: Fix a memory leakage issue in acpi_ec_add() Date: Fri, 2 Sep 2016 15:46:38 +0800 Message-Id: <51bc232e82784a302fcba870d55ffa1a178f7e09.1472802172.git.lv.zheng@intel.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: References: 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 When the handler installation failed, there was no code to free the allocated EC device. This patch fixes this memory leakage issue. Link: https://bugzilla.kernel.org/show_bug.cgi?id=115021 Reported-and-tested-by: Luya Tshimbalanga Suggested-by: Peter Wu Cc: Peter Wu Cc: Luya Tshimbalanga Signed-off-by: Lv Zheng --- drivers/acpi/ec.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 4a5f3ab..4b4c0cb 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -1438,22 +1438,25 @@ static int acpi_ec_add(struct acpi_device *device) return -ENOMEM; if (ec_parse_device(device->handle, 0, ec, NULL) != AE_CTRL_TERMINATE) { - acpi_ec_free(ec); - return -EINVAL; + ret = -EINVAL; + goto error; } /* Find and register all query methods */ acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1, acpi_ec_register_query_methods, NULL, ec, NULL); + ret = acpi_config_boot_ec(ec, false); + if (ret) + goto error; + device->driver_data = ec; ret = !!request_region(ec->data_addr, 1, "EC data"); WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr); ret = !!request_region(ec->command_addr, 1, "EC cmd"); WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr); - - ret = acpi_config_boot_ec(ec, false); + ret = 0; /* Reprobe devices depending on the EC */ acpi_walk_dep_device_list(ec->handle); @@ -1464,6 +1467,9 @@ static int acpi_ec_add(struct acpi_device *device) /* Clear stale _Q events if hardware might require that */ if (EC_FLAGS_CLEAR_ON_RESUME) acpi_ec_clear(ec); +error: + if (ret) + acpi_ec_free(ec); return ret; }