From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BEE3C433FE for ; Wed, 13 Apr 2022 09:24:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234455AbiDMJ1I (ORCPT ); Wed, 13 Apr 2022 05:27:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234423AbiDMJ1B (ORCPT ); Wed, 13 Apr 2022 05:27:01 -0400 Received: from mail.meizu.com (edge05.meizu.com [157.122.146.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C1E0DEE0; Wed, 13 Apr 2022 02:24:36 -0700 (PDT) Received: from IT-EXMB-1-125.meizu.com (172.16.1.125) by mz-mail12.meizu.com (172.16.1.108) with Microsoft SMTP Server (TLS) id 14.3.487.0; Wed, 13 Apr 2022 17:24:36 +0800 Received: from [172.16.137.70] (172.16.137.70) by IT-EXMB-1-125.meizu.com (172.16.1.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Wed, 13 Apr 2022 17:24:34 +0800 Message-ID: <05f14aa0-4001-d08d-610e-12749437ec9a@meizu.com> Date: Wed, 13 Apr 2022 17:24:33 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH V2] clk: renesas: Fix memory leak of 'cpg' To: Geert Uytterhoeven CC: Michael Turquette , Stephen Boyd , Linux-Renesas , linux-clk , Linux Kernel Mailing List References: <1649837953-10984-1-git-send-email-baihaowen@meizu.com> From: baihaowen In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [172.16.137.70] X-ClientProxiedBy: IT-EXMB-1-126.meizu.com (172.16.1.126) To IT-EXMB-1-125.meizu.com (172.16.1.125) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 4/13/22 4:41 PM, Geert Uytterhoeven 写道: > Hi Haowen, > > On Wed, Apr 13, 2022 at 10:30 AM Haowen Bai wrote: >> Fix this issue by freeing the cpg when exiting the function in the >> error/normal path. >> >> Signed-off-by: Haowen Bai > Thanks for your patch! > >> --- a/drivers/clk/renesas/clk-r8a73a4.c >> +++ b/drivers/clk/renesas/clk-r8a73a4.c >> @@ -215,7 +215,7 @@ static void __init r8a73a4_cpg_clocks_init(struct device_node *np) >> >> cpg->reg = of_iomap(np, 0); >> if (WARN_ON(cpg->reg == NULL)) >> - return; >> + goto out_free_cpg; > Note that this is a fatal error, i.e. no chance the system will survive this, > so cleaning up is moot. > >> for (i = 0; i < num_clks; ++i) { >> const char *name; >> @@ -233,6 +233,9 @@ static void __init r8a73a4_cpg_clocks_init(struct device_node *np) >> } >> >> of_clk_add_provider(np, of_clk_src_onecell_get, &cpg->data); >> +out_free_cpg: >> + kfree(cpg); >> + kfree(clks); > Both cpg and clks are still used after returning from this function, > through the registered clocks and clock provider. > >> } >> CLK_OF_DECLARE(r8a73a4_cpg_clks, "renesas,r8a73a4-cpg-clocks", >> r8a73a4_cpg_clocks_init); > NAKed-by: Geert Uytterhoeven > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like that. > -- Linus Torvalds Dear Geert Uytterhoeven Could you show me how and when cpg & clks free ? -- Haowen Bai