From patchwork Thu Aug 31 20:24:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 9932831 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 428006022E for ; Thu, 31 Aug 2017 20:25:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 371852018F for ; Thu, 31 Aug 2017 20:25:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B33D201F5; Thu, 31 Aug 2017 20:25:55 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A9D912018F for ; Thu, 31 Aug 2017 20:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=NVX4D2sKTZ5mH9mxQP9gL32E3TeFct8Ceoa10UETPtA=; b=Yc+ gIyeNzxojsCj+XrEBjwJJJ0cOuvP6LKGH/r+/l/MZ99enkh9GQmnA3fwzdBDB7oEzKyQ3sHMM/nz+ rRVordCC+iJULkLkxcoz+2MMRwNvhPYkyoKBT7eFKZjqB8LVgL6pxDTHPMNPWo+G9E3tW4VJnCb2T OPu6HcyJCqXczGaIXaR7MP18BnOgMj0TC1JdCglFha8nhOWrdENUPFmA7UmUnDzs+mXwJUIFIPd44 QQwFqOJM8TWhxiQi2y7WB/PaNNVOH+w1VcX+bJf4fv7a3OjoTV6c9gpXlaaSl4Zw5Ehixy7lEX0kb 3NlZt3aKDIZxd2Kz881yspCIELUhg3w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dnW2A-0000FN-NV; Thu, 31 Aug 2017 20:25:50 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dnW27-0000Dp-O1 for linux-arm-kernel@lists.infradead.org; Thu, 31 Aug 2017 20:25:49 +0000 Received: from localhost.localdomain ([95.90.209.32]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.183]) with ESMTPSA (Nemesis) id 0Lo18K-1dGe7G1wqW-00fyia; Thu, 31 Aug 2017 22:25:14 +0200 From: Stefan Wahren To: Daniel Lezcano , Leo Yan , "Rafael J . Wysocki" , Sudeep Holla Subject: [PATCH] ARM: cpuidle: Avoid memleak if init fail Date: Thu, 31 Aug 2017 22:24:36 +0200 Message-Id: <1504211076-2331-1-git-send-email-stefan.wahren@i2se.com> X-Mailer: git-send-email 2.7.4 X-Provags-ID: V03:K0:+oTGb5zceJJzd1uGCGv3z8F2r20LuLxfl6NqGcsL2ORnMlcnvBD vILQLSuZmcXC8cYTvJ5RcMz3jEdXHFYbcjgpOWeQxeZuN2qkiXlnRkOD2aAFdU+ub5EeQd/ Dfo0X3zM1UPrnT3fOlHBgj8ZUQt/BzgHBQyWF6/SeBMI3N2+CU8GWnMV5y33Z0oYa1AZ30N A2gYoxlvwFf4cQQJNLxZA== X-UI-Out-Filterresults: notjunk:1; V01:K0:axWQ9G2jea4=:Gkg5+02369ObtyE7wr/+k5 3SUvKwlOAFF1hKGc54OqPdsgkBFgwsgCjO041GgfDzQjnNxmnLCRQDb04wLJJFO/BAu7ENUX4 LtOI1ru+w8rWAfzJ4o5nJuLSWT7XUXLBsojg5oBgh1EM3HWxg6zH0OjunXnG+JkGo0aVUG4ZN WdLsmfFlDIgNQJFljv+4x2dCFc+72aOrADyK1ouXyWljr/RI2qjzu33XZks2CoaNo14LTEpYP auB7D8jlbKbXqr5kLhJKsvIrg8iIM0absI4EHeZ9VAPrbmEU4aJ3v18zwcuSOSZWQszV7Wz3z 7CHKPn5MB4AJC/iZuWWn4OQRwe/WkctS96FRQRJ51iqVVoxHcyCZMj+lQg11xKTYe1cDp5Sp0 XpVOVNd1plSiw6RN++Qte1z/R62OoxmmI9VU762AvccZ+OYaO9XgSDxXJ9yQWMND36gqa6ypU +gfD+YN1EZMEFVVZAkDpIl1j0Gj62MOqFG0yf44GDjvGbdDWZBbIO0hP/5/jNDFjw/UGDDLzJ beumsSetKWoZ31QCcQd0iWaCGs5Nb1Pl6nhhrFdPWBvEPjTqpjgJGZ3a/5CauZzJjSISG6aGX H4K9FP+Z8hYgAXHvIxZKMGQ/SQOlw0W+vGMpNbLxB0ZA2FpuVm0tboO5RLYf9tkYGPNf0fG0x wiIG24FmHb8sKd5PngjTfTKSKZSnMjspJEM55A0C/sWJ6nVI4NPQGk5PdznOloYnOJ1xZqU6z G6inIDrUB/g0t4STGjQBkmIeZSVlOE0XD4nZUA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170831_132548_137172_9840968C X-CRM114-Status: UNSURE ( 8.49 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In case there are no DT idle states defined or cpuidle_register_driver() fails, the copy of the idle driver is leaked: unreferenced object 0xede0dc00 (size 1024): comm "swapper/0", pid 1, jiffies 4294937431 (age 744.510s) hex dump (first 32 bytes): 94 9e 0b c1 00 00 00 00 00 00 00 00 00 00 00 00 ................ 57 46 49 00 00 00 00 00 00 00 00 00 00 00 00 00 WFI............. backtrace: [] arm_idle_init+0x44/0x1ac [] do_one_initcall+0x3c/0x16c [] kernel_init_freeable+0x110/0x1d0 [] kernel_init+0x8/0x114 [] ret_from_fork+0x14/0x3c So fix this by freeing the unregistered copy in error case. Signed-off-by: Stefan Wahren Fixes: d50a7d8acd78 ("ARM: cpuidle: Support asymmetric idle definition") Acked-by: Daniel Lezcano --- drivers/cpuidle/cpuidle-arm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c index 7080c38..52a7505 100644 --- a/drivers/cpuidle/cpuidle-arm.c +++ b/drivers/cpuidle/cpuidle-arm.c @@ -104,13 +104,13 @@ static int __init arm_idle_init(void) ret = dt_init_idle_driver(drv, arm_idle_state_match, 1); if (ret <= 0) { ret = ret ? : -ENODEV; - goto out_fail; + goto init_fail; } ret = cpuidle_register_driver(drv); if (ret) { pr_err("Failed to register cpuidle driver\n"); - goto out_fail; + goto init_fail; } /* @@ -149,6 +149,8 @@ static int __init arm_idle_init(void) } return 0; +init_fail: + kfree(drv); out_fail: while (--cpu >= 0) { dev = per_cpu(cpuidle_devices, cpu);