Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp328902lfv; Wed, 13 Apr 2022 04:57:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHLl3lXbsbtXYrKSx/wUcdYL47/cSBBMz7kwAfLGyLrL4AeK1wZ1O/mAXScnjagmV/8w1y X-Received: by 2002:a50:bf0f:0:b0:410:c512:cb6f with SMTP id f15-20020a50bf0f000000b00410c512cb6fmr43520919edk.262.1649851061646; Wed, 13 Apr 2022 04:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649851061; cv=none; d=google.com; s=arc-20160816; b=YV4sI5R7WLraU6oXUe1sJHlGTJGKmYFwIAsdjm+9wGKvkId1iYr+7N62yI8bvDkJj+ SsdWgIMTlqUjd1YfWReRoy09QKmGtYnIjZqxaZ20AVnjI8oh3nMsISr68PUHTJ+W58S4 BhbnCe7OuIi5DNfvpdpZuOPSQxX5WO3s0sKKRxVe4zX6FgHlbkmBiqpLd4ryBOT9zhTN ZaQ/qzXdifoKWFB5eE3H3TZtVWFFYW+j2Zy3VVRvkYoT+9ZOX8lCCJRpaMalgB6sLG1d orJJrYYJEmZYPau00OOSpLisQ1qmidf7A+wqZ/Uxn8PyCkrr145dxyMlnNMp3NhvrYmr A8qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=2ORQRTvhMO+ytXVKIcvZFy0TUwXvc8Vv8AW31o0FEXg=; b=ZqL6npII1H7JdP7XFv0oXjgsthOEom0e0Jr9no0ov+80963ZGa2CNobY6wpPIpkfYb DG6ZujHNEJqJUQ45u4ohodFC4s1jgjPdH+PGu5ta6lwl9H9p0Y3lUIqb45jYuUJ3dVpm 90qDm+htbpMIgp/PpDiDf8IX2hQBpwIGWuDBgmQFsuxrxZtn/I2IF7l396j+tVmKz/Bx Nkg6bgP85THYlcIs8srwjmqVR3HfwGbC1xV+LqGvMwlobKjRPisutPIAs5Qf+MCHBA6W xN700epDrnx3vLgGukcld5+HvnR4iUE/VNavDq3OQ6MUZ3jUF0Zd5IPALkBZ9k8ysoWU N3jA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id tc14-20020a1709078d0e00b006e0db7cb13esi8262013ejc.468.2022.04.13.04.57.16; Wed, 13 Apr 2022 04:57:41 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234452AbiDMJ1G (ORCPT + 99 others); Wed, 13 Apr 2022 05:27:06 -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) X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, NICE_REPLY_A,SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE 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 在 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