From patchwork Mon Nov 30 13:01:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 'Qinglang Miao X-Patchwork-Id: 335216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DD1FC83013 for ; Mon, 30 Nov 2020 12:54:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0086320691 for ; Mon, 30 Nov 2020 12:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbgK3MyI (ORCPT ); Mon, 30 Nov 2020 07:54:08 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8533 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726001AbgK3MyG (ORCPT ); Mon, 30 Nov 2020 07:54:06 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Cl4s658FgzhkdP; Mon, 30 Nov 2020 20:52:58 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Mon, 30 Nov 2020 20:53:16 +0800 From: Qinglang Miao To: =?utf-8?q?=C5=81ukasz_Stelmach?= , "Krzysztof Kozlowski" CC: , , , , Qinglang Miao Subject: [PATCH v2] hwrng: exynos - fix reference leak in exynos_trng_probe Date: Mon, 30 Nov 2020 21:01:18 +0800 Message-ID: <20201130130118.51339-1-miaoqinglang@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org pm_runtime_get_sync will increment pm usage counter even failed. Forgetting to putting operation will result in a reference leak here. Replace it with pm_runtime_resume_and_get to keep usage counter balanced. I remove err_clock label at the same. Fixes: 6cd225cc5d8a ("hwrng: exynos - add Samsung Exynos True RNG driver") Reported-by: Hulk Robot Suggested-by: Lukasz Stelmach Signed-off-by: Qinglang Miao --- v2: remobe useless label as Lukasz suggested. drivers/char/hw_random/exynos-trng.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/char/hw_random/exynos-trng.c b/drivers/char/hw_random/exynos-trng.c index 8e1fe3f8d..ffebb72e4 100644 --- a/drivers/char/hw_random/exynos-trng.c +++ b/drivers/char/hw_random/exynos-trng.c @@ -132,7 +132,7 @@ static int exynos_trng_probe(struct platform_device *pdev) return PTR_ERR(trng->mem); pm_runtime_enable(&pdev->dev); - ret = pm_runtime_get_sync(&pdev->dev); + ret = pm_runtime_resume_and_get(&pdev->dev); if (ret < 0) { dev_err(&pdev->dev, "Could not get runtime PM.\n"); goto err_pm_get; @@ -142,13 +142,13 @@ static int exynos_trng_probe(struct platform_device *pdev) if (IS_ERR(trng->clk)) { ret = PTR_ERR(trng->clk); dev_err(&pdev->dev, "Could not get clock.\n"); - goto err_clock; + goto err_pm_get; } ret = clk_prepare_enable(trng->clk); if (ret) { dev_err(&pdev->dev, "Could not enable the clk.\n"); - goto err_clock; + goto err_pm_get; } ret = devm_hwrng_register(&pdev->dev, &trng->rng); @@ -164,9 +164,6 @@ static int exynos_trng_probe(struct platform_device *pdev) err_register: clk_disable_unprepare(trng->clk); -err_clock: - pm_runtime_put_sync(&pdev->dev); - err_pm_get: pm_runtime_disable(&pdev->dev);