From patchwork Fri Aug 16 22:21:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 11098323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D6A31399 for ; Fri, 16 Aug 2019 22:22:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5795E289E1 for ; Fri, 16 Aug 2019 22:22:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47418289FF; Fri, 16 Aug 2019 22:22:02 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 D5400289E1 for ; Fri, 16 Aug 2019 22:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727729AbfHPWV5 (ORCPT ); Fri, 16 Aug 2019 18:21:57 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38035 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727726AbfHPWV5 (ORCPT ); Fri, 16 Aug 2019 18:21:57 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1hykbY-0002Yt-Bx; Fri, 16 Aug 2019 22:21:52 +0000 From: Colin King To: Pankaj Dubey , Kukjin Kim , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] soc: samsung: exynos-chipid: fix memory leak Date: Fri, 16 Aug 2019 23:21:51 +0100 Message-Id: <20190816222151.11098-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Colin Ian King Currently when the call to product_id_to_soc_id fails there is a memory leak of soc_dev_attr->revision and soc_dev_attr on the error return path. Fix this by adding a common error return path that frees there obects and use this for two error return paths. Addresses-Coverity: ("Resource leak") Fixes: 3253b7b7cd44 ("soc: samsung: Add exynos chipid driver support") Signed-off-by: Colin Ian King --- drivers/soc/samsung/exynos-chipid.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/soc/samsung/exynos-chipid.c b/drivers/soc/samsung/exynos-chipid.c index 006a95feb618..4e194a97c0fa 100644 --- a/drivers/soc/samsung/exynos-chipid.c +++ b/drivers/soc/samsung/exynos-chipid.c @@ -81,15 +81,15 @@ int __init exynos_chipid_early_init(void) soc_dev_attr->soc_id = product_id_to_soc_id(product_id); if (!soc_dev_attr->soc_id) { pr_err("Unknown SoC\n"); - return -ENODEV; + ret = -ENODEV; + goto err; } /* please note that the actual registration will be deferred */ soc_dev = soc_device_register(soc_dev_attr); if (IS_ERR(soc_dev)) { - kfree(soc_dev_attr->revision); - kfree(soc_dev_attr); - return PTR_ERR(soc_dev); + ret = PTR_ERR(soc_dev); + goto err; } /* it is too early to use dev_info() here (soc_dev is NULL) */ @@ -97,5 +97,11 @@ int __init exynos_chipid_early_init(void) soc_dev_attr->soc_id, product_id, revision); return 0; + +err: + kfree(soc_dev_attr->revision); + kfree(soc_dev_attr); + return ret; } + early_initcall(exynos_chipid_early_init);