Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp372818pxb; Wed, 13 Apr 2022 03:10:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTPPzeta3SdNuVRhAToSHtWu6QhFGiFs2Onhid78ojpeEmfo4ec+nJ2toi+NqPHVIB837r X-Received: by 2002:a17:902:dac5:b0:158:5db6:3503 with SMTP id q5-20020a170902dac500b001585db63503mr15489157plx.76.1649844647207; Wed, 13 Apr 2022 03:10:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649844647; cv=none; d=google.com; s=arc-20160816; b=uTIZKvCcK4dK4DyfqJEW2lmhBWi4FlZA9YFbCruJrKfMGdbuLLyQHXIDZDPQqSEOo/ uR2rbRhTiA83GgLrCikwXLS9iV6UVED4WLW2pwmv2a8UdVuKae7aiElk5vIktZ4n9WOy /+pAPzIzkCw0rzsIb82TJtojtH8FermN0c9ldCSclf4bJ7jP44UMDaKU0wBhVOMsoEF/ RaQ9S0miwfqN//666ViGHbs9c53DYRu0Y1emcwoDCe0U66VsuB4Mr33UbTDp6PRiu+wI YxerQ3LkUtELmqL6bPee8Jym+S8QpGO2qHRRxCiTJ+AaeZF7iKsmsgamHwpssDfJrMIu Hu1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=EvuJzQp96B8cTDCcG+qyKDAB37NSc3zpMTaTjtbLzLE=; b=emESmKpRColDbsOjCaz+LBTWUMvU2n0ufS6z5iXEldf9ZY6k5TkKo0zHMU3wiun8Q/ sTolz5Osidy1jFxXoN1S5J3G/ZH2ogyzfQipJ/bbHwPbFg+qpyrdR2nxg/r5hfnUg9pw lCWwDbPkHEne3Y45u3yWWGRT8i+2rIL4kirHF3lFBYF+z4OUU2Ar5/bmaCZvwjUGKZsX basV+r36vyNMmDlrqtA/pxwnfQ82NcIoYXfE3J6cooPBFQ1ZFJsZBp2wcanX+KhZU3Uv fdGZdINx+AxfrQP2wldXUrd4vbiie7w1QirpXAwHZObDz1eQlFUPj5GPh/HfJkUtO/h4 F7Uw== 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 b14-20020a056a000a8e00b004fa939797d0si15262612pfl.2.2022.04.13.03.10.31; Wed, 13 Apr 2022 03:10:47 -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 S233913AbiDMIoQ (ORCPT + 99 others); Wed, 13 Apr 2022 04:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233330AbiDMIoP (ORCPT ); Wed, 13 Apr 2022 04:44:15 -0400 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 108234ECD9; Wed, 13 Apr 2022 01:41:55 -0700 (PDT) Received: by mail-qv1-f53.google.com with SMTP id b17so1052920qvf.12; Wed, 13 Apr 2022 01:41:55 -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; bh=EvuJzQp96B8cTDCcG+qyKDAB37NSc3zpMTaTjtbLzLE=; b=l2/9tgmUxRwiW999l7KguZ00THK6zjctwfXGJMdpOivvF7CUVb0KzwuXDtKkFyhnxe Wi06Ty3kuMm2j6y84DsuGrpx93tJjnxVmtQPcFCa5LG36vpLneW295eeHdpZ/atVNLUK jyazwzEnv4NujCQvaruON53yYnNt/Rn2Rt87A76mFuYJ4L12kn2D3MSPERjZ/tzkn1vk 547BWr3QTqigrVIkRbo+KIkcUEu3VFnL1aGJi+pK5Q1iUK0Su7GulitAV/792zmhcLIA nYR7J8j0QLWhwbxYQ+wpj4cwOw76K5Bpy2IzZWwyV937m9K/3yFvxx1v9Pz3fSP5djKY IVvQ== X-Gm-Message-State: AOAM5301PTUMH3MS6gBjulws91Yzqw5OQHKINnctLzp8V/N9tBaF1RfZ nKl2xr7Fk5+nppiFpJqxVJunkSB5l8yX6w== X-Received: by 2002:a05:6214:2421:b0:444:3fa7:716e with SMTP id gy1-20020a056214242100b004443fa7716emr13446567qvb.43.1649839313998; Wed, 13 Apr 2022 01:41:53 -0700 (PDT) Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com. [209.85.128.176]) by smtp.gmail.com with ESMTPSA id b126-20020a37b284000000b0069a11927e57sm10459028qkf.101.2022.04.13.01.41.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Apr 2022 01:41:53 -0700 (PDT) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-2eba37104a2so14963417b3.0; Wed, 13 Apr 2022 01:41:53 -0700 (PDT) X-Received: by 2002:a81:413:0:b0:2ec:31d7:7e60 with SMTP id 19-20020a810413000000b002ec31d77e60mr10993822ywe.62.1649839313333; Wed, 13 Apr 2022 01:41:53 -0700 (PDT) MIME-Version: 1.0 References: <1649837953-10984-1-git-send-email-baihaowen@meizu.com> In-Reply-To: <1649837953-10984-1-git-send-email-baihaowen@meizu.com> From: Geert Uytterhoeven Date: Wed, 13 Apr 2022 10:41:42 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V2] clk: renesas: Fix memory leak of 'cpg' To: Haowen Bai Cc: Michael Turquette , Stephen Boyd , Linux-Renesas , linux-clk , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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_H2,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 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