Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp843953pxb; Wed, 13 Apr 2022 13:49:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyvfozEVoIbGlq8C3QvTf5RxyXzuKISdSB9Ii1AzItRZXXmEx/Vg+e7ilnzL847ioJYLM6 X-Received: by 2002:a63:907:0:b0:374:b3c2:2df2 with SMTP id 7-20020a630907000000b00374b3c22df2mr35628855pgj.614.1649882969403; Wed, 13 Apr 2022 13:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649882969; cv=none; d=google.com; s=arc-20160816; b=0jIbK6u/b+YCuJkmv5Uj9Kl+7vXrSMot16NcJ2tJxUuZPLC2GviDudVDDUs7QEbu/F sCj1lNv0YG1ym7RgRfeVXlnqdI6ZmqszN+Oj3iFgAXtfz1Tto3g7twNWtwt+HG/OLXMO pXGezO9xViI2GX7ONajz6KXWKRm8psialF4Vx8t82cHsKd6lNj0IE1a+nLrjdxElhnJY LEqE1BJlc3LayvhUxLD9xCnycohgaZiuGyzZfP1q8ZBaAUZ7wXq+6Lp+pBblKpqUFUut 4Mx42oFMU/BQsVjS+1jp7kdRBj7qLU+w7ji4fQddqlt6aF5HacYmsfZ3QRkXFpKkSLr0 XOAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=3xzZbf7yCPQbubYnoXDCApZ1GnjboAJQYdeUzM9Xxqg=; b=dXZiTGPB8T6+o5Pcq4r8U8Kqtt32sQVYKofXhQzPkpa11puBBJ97tx87NEfLFZxrYG z7z0/Uf37spBkszLUSBw1S+r69p1aNGZLMQ9x51I8uPFfuZX37Pqgru648e/bCUoSgjZ YKAqkfPfXzfx/iUAWWaVoNHySBW0DHzyvRvYCH/+naVgQe7C0PGROkJBbxE1XhzIiWGc ZuBELP9LtGS3KRXWCzsP+l5IEkGa/nDVbSs9jvSQSh7ohHoVcVKFk7Ph56oatia/yxeC qZZxX7QMx/rAVqw/qBlWkM8MpkpBjBnJSoPm/LkwZMRqysDGWAthGcBytsWgSgRjjRXJ ahtg== 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 t16-20020a170902e85000b00153b2d1651fsi16657729plg.295.2022.04.13.13.49.14; Wed, 13 Apr 2022 13:49:29 -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 S234923AbiDMKm2 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 13 Apr 2022 06:42:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiDMKm0 (ORCPT ); Wed, 13 Apr 2022 06:42:26 -0400 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5935F532F0; Wed, 13 Apr 2022 03:40:05 -0700 (PDT) Received: by mail-qt1-f182.google.com with SMTP id ay4so1013122qtb.11; Wed, 13 Apr 2022 03:40:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ylLDxaJE5bKp2Ipxy025DYGxQ1jbgF00xKv8pZHsTdY=; b=oz3fr6RZJToVCHHEOSV+FDoSpSVpzuTIeEprD6AL3ex7sZNTzpgBV3+KN7pn88Vm+I MmtKFaup9QRd+Ywh/9Ik8TxVnZ5MiXHKxt2AluI9GCGZh0A5c+vMqatvCqOrAstZjM33 04aHApUOwZ6JIwEyFDotYjrYLuZkn8ut9UtnYfcsMhbkCs68CtCCJwVQYFyecw3qgko4 ImNPqZNJcbF8TjoZZlX+Z4XB0o4IR4rZN0znVTBfTzgXCNS6ehbbd5pNXjMOzrcOFvlK Rs4PnvH7zj/LxZnR9k65WATjvtdBgAJdBipek1FIUZfzl/HtQSkP0PNRwCtkBMEkPXS2 MXvw== X-Gm-Message-State: AOAM530Y5xrMPiXVVK2J0ev9ezhBgz8iMPN2gY7BogP7Co6gZbcoFi/6 ym0HoI0RLvXM7IZS0Ycf0oj1p+iP3XbQng== X-Received: by 2002:a05:622a:1447:b0:2e1:c405:b05b with SMTP id v7-20020a05622a144700b002e1c405b05bmr6688814qtx.626.1649846404071; Wed, 13 Apr 2022 03:40:04 -0700 (PDT) Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com. [209.85.219.181]) by smtp.gmail.com with ESMTPSA id i137-20020a379f8f000000b0069befb1e28fsm8559784qke.97.2022.04.13.03.40.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Apr 2022 03:40:03 -0700 (PDT) Received: by mail-yb1-f181.google.com with SMTP id f38so2952916ybi.3; Wed, 13 Apr 2022 03:40:03 -0700 (PDT) X-Received: by 2002:a5b:24e:0:b0:63d:cba0:3d55 with SMTP id g14-20020a5b024e000000b0063dcba03d55mr28271889ybp.613.1649846403436; Wed, 13 Apr 2022 03:40:03 -0700 (PDT) MIME-Version: 1.0 References: <1649837953-10984-1-git-send-email-baihaowen@meizu.com> <05f14aa0-4001-d08d-610e-12749437ec9a@meizu.com> In-Reply-To: <05f14aa0-4001-d08d-610e-12749437ec9a@meizu.com> From: Geert Uytterhoeven Date: Wed, 13 Apr 2022 12:39:52 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V2] clk: renesas: Fix memory leak of 'cpg' To: baihaowen Cc: Michael Turquette , Stephen Boyd , Linux-Renesas , linux-clk , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 Haowen, On Wed, Apr 13, 2022 at 11:24 AM baihaowen wrote: > 在 4/13/22 4:41 PM, Geert Uytterhoeven 写道: > > 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 > Could you show me how and when cpg & clks free ? They are never freed, as they stay in-use for the lifetime of the system. 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