Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7092204rwb; Wed, 23 Nov 2022 01:55:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf7eUcW07lRj/rE7FQNYfKs9gy/0dQ58yLcUns52SjXyLQgrx/xpWei0WGCDsM2l6tcmNUZ1 X-Received: by 2002:a17:906:b29a:b0:78d:b695:1d68 with SMTP id q26-20020a170906b29a00b0078db6951d68mr7165410ejz.235.1669197330038; Wed, 23 Nov 2022 01:55:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669197330; cv=none; d=google.com; s=arc-20160816; b=j2l99K1zoXVZqu1vnodGGHK9iOzeqMgr3o+KBjX7kXshY3wRBGZVlHVTYdw4ue67/L qKmWI38HRrJueIbTef6tyg0jLZk/73CDUlBxU9BWz0brfN+gcA37qV2q3RNWwP/r03Jj 59ZCrF06puLKb0IZ7xTfPPf/wVJgw6dnkqUXZ/YCae0q1HmTaFWRMggxb19tQCDv8zhC 44RcqdoK2txY83t5Pvo/rGvLN7aNjAnSvlTmgJohZ48fyca1wytyBmFezDRigiwZdcxk j/f5ETj2HnXhTffmxU1ts6fJ7XIRXI0m3tZvR8edmPcV93VJP4cOZYbkyG+4WTvNKxO1 ++cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oVuJRUd9+3mLNiC9xwDe2DLuOXFKz/3r4JLn0KZITs8=; b=xTkwi/MIXsknRITVcmjoykPyjbDBmWfgzkVjaOqsqQQvGhI661VkhjQnwgC03QbcuC BY/bv9efoQabjRYa6pDQjy8/O1Dmi39/Mn/61CyZqaShXo9E27p/KR5si4HG1kqnCO4/ s8r9wcgWMFup+F4RKR//ZzPCEqw4SDRW79MRd3ps4x8w/aneYNjPSMyB7Er57cUyh85e 0OvMToQlUnGj2pHGDpTdpIFVAORh0u3opHvNgDUNzq0qxSg2zg5xg9jgfaNdGv/cnm8w kxakmKk0x7m1+LCytSzV76Wxie/ON/FCPPl3+5lxjeM8uGseWwKTTn2PoX3i/K8REQ7J OLjA== 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=NONE sp=NONE dis=NONE) header.from=sntech.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf35-20020a1709077f2300b007ade22f401bsi17843093ejc.759.2022.11.23.01.55.08; Wed, 23 Nov 2022 01:55:30 -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=NONE sp=NONE dis=NONE) header.from=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236905AbiKWJBv (ORCPT + 89 others); Wed, 23 Nov 2022 04:01:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236893AbiKWJBt (ORCPT ); Wed, 23 Nov 2022 04:01:49 -0500 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B82961025D6; Wed, 23 Nov 2022 01:01:47 -0800 (PST) Received: from ip5b412258.dynamic.kabel-deutschland.de ([91.65.34.88] helo=phil.localnet) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oxldM-0006px-PE; Wed, 23 Nov 2022 10:01:32 +0100 From: Heiko Stuebner To: mturquette@baylibre.com, sboyd@kernel.org, mturquette@linaro.org, Xiu Jianfeng Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] clk: rockchip: Fix memory leak in rockchip_clk_register_pll() Date: Wed, 23 Nov 2022 10:01:30 +0100 Message-ID: <6301679.31r3eYUQgx@phil> In-Reply-To: <20221123032237.64567-1-xiujianfeng@huawei.com> References: <20221123032237.64567-1-xiujianfeng@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_SPF_HELO_TEMPERROR 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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; > } >