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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29751CA0FF2 for ; Wed, 3 Sep 2025 17:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9LvNkoiJNwvEbI5/GhvG6oLSTV72XAkWAFny+OqQS8o=; b=OaT1ZnChjJ0teFFEckvC/u/VKd tzj1kfyZ7a+58alu13A1g8eXmu66nZLclO1dscdezIaIBd0x5q6fC2Qf5g905ODghscTYv9gwh68C rI3QVAyL6vL/5ETzUhdD9WwVZMtp5Cm3UAWCdPD9BHeLihbduMQ1X0reSWUlG2gaYsj3PO1Uij9Tf nXCIF00mxvC2Y8Cfr4/Dwe6Lk7Xo3pifUof3N9LJmPtn2ES22MvCTvo7zi6DphuzwlQPaaOxI+iEv vt7xte0BkrSNf8dvBOMVEPRZY56EUe9wTfoMrB72dTG77skT1Ndfl41AWV7SsvOUJynfAE/NDYwYJ w4xWuDTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1utrWL-00000007DWv-1ttC; Wed, 03 Sep 2025 17:43:45 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1utnnm-00000006dtE-2PqO for linux-arm-kernel@lists.infradead.org; Wed, 03 Sep 2025 13:45:30 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 08A5E60248 for ; Wed, 3 Sep 2025 13:45:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B10E0C4CEFA for ; Wed, 3 Sep 2025 13:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756907129; bh=6Bp49XvIiL/gpcZUSJHbjfPDkjkxFuVv8aVM1mwkppM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EtV1vxk9Knh7vuhM8x4HkCnMMQg77LBHWAZjfHt0hykdAtk0J7zkljpn1dRo8ALRy nJBjQbGoGlt335lc6Yejbwt37hjTv6p8SfDTunaRiW2oQzHQJq0rlhZtQ1LRmN6+mL IGnwxZAwUAyqQhCdqcZjg6unlXq+oHZaIHgAwNaLEtGxgemHO0ZOaXw9RabH2oRHjO 1NAsUX1pvy8xvLLbjRFOhcQ7OcGTcv3rYRTxHcZtSDX9/AS365g+6AYkmZe7Gug6n+ egQHkiSWI1KySu6kre/fm/A9KyjZ9fyn2Wecsk4AkYcdc4XAKirge13OlUIx7BdFSr JLHu0DYRXsxWw== Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-74381e207a0so4681245a34.0 for ; Wed, 03 Sep 2025 06:45:29 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCU7W1OS2ah/sxqHdpaBRZ1r4+ImKroMrqjQFRKDNYXgkn6G9JYcnJ/xHd8QRLoq5UfI133yfm98ubU1QLHFr6v9@lists.infradead.org X-Gm-Message-State: AOJu0YyLLnNtqLdAKkBWo73U9nLPqBYntnUt4DlCJtV2zRq57ldz5nbF mjaJ5AI6Yxu3Tnn8tH62TiUtNUIFrLpvcou8xVB6Qq5SUseP4DtCT6wcBJN2MVDasgGVfDiyEH0 OZ9t8Z02cF9TfaO+6i5ODdH5nEg3eV3Y= X-Google-Smtp-Source: AGHT+IFj7tJ0lfFEWygwFa+BeDrtHlIidd3MSLvzw4pQoHyU3fN8psDlEaELWcEJ9+cmnisQYq8U5lt0bInRpr2lJAs= X-Received: by 2002:a05:6830:6682:b0:745:9ba6:d32c with SMTP id 46e09a7af769-7459ba6d61bmr1062886a34.2.1756907128976; Wed, 03 Sep 2025 06:45:28 -0700 (PDT) MIME-Version: 1.0 References: <20250903131733.57637-1-zhangzihuan@kylinos.cn> <20250903131733.57637-8-zhangzihuan@kylinos.cn> In-Reply-To: <20250903131733.57637-8-zhangzihuan@kylinos.cn> From: "Rafael J. Wysocki" Date: Wed, 3 Sep 2025 15:45:17 +0200 X-Gmail-Original-Message-ID: X-Gm-Features: Ac12FXwBQmIxy8zPXuaWqJJ1Bp0qaxbUEME_ozpvMpdmoYPanY06xkhRVAoy8ys Message-ID: Subject: Re: [PATCH v4 07/10] powercap: dtpm_cpu: Use scope-based cleanup helper To: Zihuan Zhang Cc: "Rafael J . wysocki" , Viresh Kumar , Catalin Marinas , Will Deacon , Borislav Petkov , Dave Hansen , Srinivas Pandruvada , Michael Ellerman , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Jani Nikula , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Daniel Lezcano , Sascha Hauer , Shawn Guo , Eduardo Valentin , Keerthy , Ben Horgan , zhenglifeng , Zhang Rui , Len Brown , Lukasz Luba , Pengutronix Kernel Team , Beata Michalska , Fabio Estevam , Pavel Machek , Sumit Gupta , Prasanna Kumar T S M , Sudeep Holla , Yicong Yang , linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, imx@lists.linux.dev, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Sep 3, 2025 at 3:18=E2=80=AFPM Zihuan Zhang wrote: > > Replace the manual cpufreq_cpu_put() with __free(put_cpufreq_policy) > annotation for policy references. This reduces the risk of reference > counting mistakes and aligns the code with the latest kernel style. > > No functional change intended. > > Signed-off-by: Zihuan Zhang > --- > drivers/powercap/dtpm_cpu.c | 30 +++++++++++------------------- > 1 file changed, 11 insertions(+), 19 deletions(-) > > diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c > index 99390ec1481f..f76594185fa2 100644 > --- a/drivers/powercap/dtpm_cpu.c > +++ b/drivers/powercap/dtpm_cpu.c > @@ -144,19 +144,17 @@ static int update_pd_power_uw(struct dtpm *dtpm) > static void pd_release(struct dtpm *dtpm) > { > struct dtpm_cpu *dtpm_cpu =3D to_dtpm_cpu(dtpm); > - struct cpufreq_policy *policy; > > if (freq_qos_request_active(&dtpm_cpu->qos_req)) > freq_qos_remove_request(&dtpm_cpu->qos_req); > > - policy =3D cpufreq_cpu_get(dtpm_cpu->cpu); > - if (policy) { > + struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D > + cpufreq_cpu_get(dtpm_cpu->cpu); > + > + if (policy) > for_each_cpu(dtpm_cpu->cpu, policy->related_cpus) > per_cpu(dtpm_per_cpu, dtpm_cpu->cpu) =3D NULL; > > - cpufreq_cpu_put(policy); > - } > - > kfree(dtpm_cpu); > } > > @@ -192,7 +190,6 @@ static int cpuhp_dtpm_cpu_online(unsigned int cpu) > static int __dtpm_cpu_setup(int cpu, struct dtpm *parent) > { > struct dtpm_cpu *dtpm_cpu; > - struct cpufreq_policy *policy; > struct em_perf_state *table; > struct em_perf_domain *pd; > char name[CPUFREQ_NAME_LEN]; > @@ -202,21 +199,19 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *p= arent) > if (dtpm_cpu) > return 0; > > - policy =3D cpufreq_cpu_get(cpu); > + struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D > + cpufreq_cpu_get(cpu); > + > if (!policy) > return 0; > > pd =3D em_cpu_get(cpu); > - if (!pd || em_is_artificial(pd)) { > - ret =3D -EINVAL; > - goto release_policy; > - } > + if (!pd || em_is_artificial(pd)) > + return -EINVAL; > > dtpm_cpu =3D kzalloc(sizeof(*dtpm_cpu), GFP_KERNEL); > - if (!dtpm_cpu) { > - ret =3D -ENOMEM; > - goto release_policy; > - } > + if (!dtpm_cpu) > + return -ENOMEM; > > dtpm_init(&dtpm_cpu->dtpm, &dtpm_ops); > dtpm_cpu->cpu =3D cpu; > @@ -239,7 +234,6 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *par= ent) > if (ret < 0) > goto out_dtpm_unregister; So this change kind of goes against another recommendation given in cleanup= .h: * Lastly, given that the benefit of cleanup helpers is removal of * "goto", and that the "goto" statement can jump between scopes, the * expectation is that usage of "goto" and cleanup helpers is never * mixed in the same function. I.e. for a given routine, convert all * resources that need a "goto" cleanup to scope-based cleanup, or * convert none of them. > > - cpufreq_cpu_put(policy); > return 0; > > out_dtpm_unregister: > @@ -251,8 +245,6 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *par= ent) > per_cpu(dtpm_per_cpu, cpu) =3D NULL; > kfree(dtpm_cpu); > > -release_policy: > - cpufreq_cpu_put(policy); > return ret; > } > > --