Message ID | 20221123032237.64567-1-xiujianfeng@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2569194wrr; Tue, 22 Nov 2022 19:28:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf6cwUHwU+uTuUIC8MIE2P5yoneFg3nQw1I0S2GRpEEiy7da9L12gUa7biOcKwkN/lNFR0ej X-Received: by 2002:a05:6402:4028:b0:467:c33e:edd6 with SMTP id d40-20020a056402402800b00467c33eedd6mr24584993eda.146.1669174082579; Tue, 22 Nov 2022 19:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669174082; cv=none; d=google.com; s=arc-20160816; b=jdDC6S2YhRPNUNc+mBmuC0ZM2OnOBMZb6cnuLovPfeU5u+re48mlMLsJUlNvHyh1Tj in6Hb/ATNJESm5+D/ROA9bqhg/GXDRdeWBhywdDv+p+u5cz6YkfbQeasNMXtF5OBe+z4 0MP+XapfMrrKeM6mRq95Mpa/AlIT2pVbrBry5sjzefZKETOR/IKVvJ0WRkhGU5WYGZHq GUXaCNnIqUpr4LS7ludy+XEbXj26kkcdtd4NHhVe41nicxnCpdvqRsuA6rNIlSllNnra LV+ddQGtP1lkkmYoMdHQ7LnsdHUQvMqoKbWoLET8MHeYqdEuV5F1pZ29AYgl15C+vZ8i DL6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=DmW9S3UGd8BC7hOWrsDhSqYOJUG055/7J98+Tu3joXc=; b=wu88D6W1te4q1gWyFshWxlxY8DF5qSMcn+H9o35LQ9vKdS4Eq8PIFnpXOd02ipDYXp 3WwxTZGcQcqJwYgySVl+NepoxsnaINPmd7rNnoSaJrwzDOhzdPqxjkWPTxoF6KVYKFAm NJkwc0EaGnw/QQWp7aLEeEdjPmNTzPhuRXyWccQsIO/uWU7Y89KQo6TI+ybBCz/noltZ Wji+fBDXmB/Naq+xxvM761pxJ59ksordHwGYCEFFtEYy9QBX9nmU6S4bthULWLap4EY7 gOOCNgHVqMdZC0n/gdyEnws8L4oY4Ha2Z7SZMDfrt8X+8vZzUzMXgYj/VlL7yY/IwSfK V32g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a056402358900b004597671e0ddsi13739486edc.338.2022.11.22.19.27.36; Tue, 22 Nov 2022 19:28:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235552AbiKWDZp (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Tue, 22 Nov 2022 22:25:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234070AbiKWDZn (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 22 Nov 2022 22:25:43 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22F6FE6367; Tue, 22 Nov 2022 19:25:42 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NH5z43JVwzJnrn; Wed, 23 Nov 2022 11:22:24 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 23 Nov 2022 11:25:40 +0800 From: Xiu Jianfeng <xiujianfeng@huawei.com> To: <mturquette@baylibre.com>, <sboyd@kernel.org>, <heiko@sntech.de>, <mturquette@linaro.org> CC: <linux-clk@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-rockchip@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH] clk: rockchip: Fix memory leak in rockchip_clk_register_pll() Date: Wed, 23 Nov 2022 11:22:37 +0800 Message-ID: <20221123032237.64567-1-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750255883303082316?= X-GMAIL-MSGID: =?utf-8?q?1750255883303082316?= |
Series |
clk: rockchip: Fix memory leak in rockchip_clk_register_pll()
|
|
Commit Message
Xiu Jianfeng
Nov. 23, 2022, 3:22 a.m. UTC
If clk_register() fails, @pll->rate_table may have allocated memory by
kmemdup(), so it needs to be freed, otherwise will cause memory leak
issue, this patch fixes it.
Fixes: 90c590254051 ("clk: rockchip: add clock type for pll clocks and pll used on rk3066")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
drivers/clk/rockchip/clk-pll.c | 1 +
1 file changed, 1 insertion(+)
Comments
Hi, Am Mittwoch, 23. November 2022, 04:22:37 CET schrieb Xiu Jianfeng: > If clk_register() fails, @pll->rate_table may have allocated memory by > kmemdup(), so it needs to be freed, otherwise will cause memory leak > issue, this patch fixes it. > > Fixes: 90c590254051 ("clk: rockchip: add clock type for pll clocks and pll used on rk3066") > Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com> > --- > drivers/clk/rockchip/clk-pll.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c > index 4b9840994295..dc4ce280d125 100644 > --- a/drivers/clk/rockchip/clk-pll.c > +++ b/drivers/clk/rockchip/clk-pll.c > @@ -1200,6 +1200,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx, > clk_unregister(mux_clk); > mux_clk = pll_clk; > err_mux: > + kfree(pll->rate_table); I think this free needs to go up to the err_pll block. In the code it is - clk_register(pll_mux->hw) -> err_mux - kmemdup - clk_register(pll->hw) -> err_pll so the kfree for the rate-table should probably be at err_pll: kfree(rate_table) clk_unregister(mux_clk); ... Heiko > kfree(pll); > return mux_clk; > } >
Hi, 在 2022/11/23 17:01, Heiko Stuebner 写道: > Hi, > > Am Mittwoch, 23. November 2022, 04:22:37 CET schrieb Xiu Jianfeng: >> If clk_register() fails, @pll->rate_table may have allocated memory by >> kmemdup(), so it needs to be freed, otherwise will cause memory leak >> issue, this patch fixes it. >> >> Fixes: 90c590254051 ("clk: rockchip: add clock type for pll clocks and pll used on rk3066") >> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com> >> --- >> drivers/clk/rockchip/clk-pll.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c >> index 4b9840994295..dc4ce280d125 100644 >> --- a/drivers/clk/rockchip/clk-pll.c >> +++ b/drivers/clk/rockchip/clk-pll.c >> @@ -1200,6 +1200,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx, >> clk_unregister(mux_clk); >> mux_clk = pll_clk; >> err_mux: >> + kfree(pll->rate_table); > > I think this free needs to go up to the err_pll block. > > In the code it is > - clk_register(pll_mux->hw) -> err_mux > - kmemdup > - clk_register(pll->hw) -> err_pll > > so the kfree for the rate-table should probably > be at > err_pll: > kfree(rate_table) Thanks for you review, I think here should be kfree(pll->rate_table) instead of kfree(rate_table), because @rate_table is the intput param while pll->rate_table is the new allocated memory. v2 already sent. > clk_unregister(mux_clk); > ... > > > Heiko > >> kfree(pll); >> return mux_clk; >> } >> > > > > > > . >
diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c index 4b9840994295..dc4ce280d125 100644 --- a/drivers/clk/rockchip/clk-pll.c +++ b/drivers/clk/rockchip/clk-pll.c @@ -1200,6 +1200,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx, clk_unregister(mux_clk); mux_clk = pll_clk; err_mux: + kfree(pll->rate_table); kfree(pll); return mux_clk; }