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 03C78CA0FED for ; Fri, 5 Sep 2025 14:34:42 +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:MIME-Version:References:In-Reply-To:Message-ID:Subject:CC:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UVUe42D5SrQpiUnvULbUkLwkdDTYsiByc8B4Cz3t2Nc=; b=fVO+wc+gFuF7ZZQpAhCLnXvmxq cKjo6buxYWONPaIVUT2dGoG0zHO67UzDTrhT7pcE8zmojUaVgeD8oBqXj44sCwAVpeO/9pYHmneeQ +T9rKrcjMfia51as2sYdYEZdDZCCv+GpNKB8BXjGfuuzqQyDRoYBqfNQinq4TwcDyv7OWXM0Mg9Te iOxy3eTB2d4UYZJe/Jlo8bMj1LcsET3qWN7OFmYnZJ3AmtlqrG+fF7bhRzJQ3eCp2nzaH9rqqW6kf OtSdaEnwFqyauZH2nfKg7+F4Qb6TxRtZ04D8UIWW3uSRN+4ZFXzbJC5MtnS6dGK5JILCRwNGaELaJ kc9q7e4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uuXWM-00000002Lyg-199Q; Fri, 05 Sep 2025 14:34:34 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uuT0c-00000000pUb-2sKW for linux-arm-kernel@lists.infradead.org; Fri, 05 Sep 2025 09:45:31 +0000 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4cJBGj5KWJz6GFrx; Fri, 5 Sep 2025 17:42:53 +0800 (CST) Received: from frapeml500008.china.huawei.com (unknown [7.182.85.71]) by mail.maildlp.com (Postfix) with ESMTPS id C6DA11402F7; Fri, 5 Sep 2025 17:45:24 +0800 (CST) Received: from localhost (10.203.177.15) by frapeml500008.china.huawei.com (7.182.85.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 5 Sep 2025 11:45:22 +0200 Date: Fri, 5 Sep 2025 10:45:21 +0100 From: Jonathan Cameron To: "Rafael J. Wysocki" CC: Zihuan Zhang , 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 , , , , , , , , , Subject: Re: [PATCH v4 02/10] ACPI: processor: thermal: Use scope-based cleanup helper Message-ID: <20250905104521.00003944@huawei.com> In-Reply-To: References: <20250903131733.57637-1-zhangzihuan@kylinos.cn> <20250903131733.57637-3-zhangzihuan@kylinos.cn> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.203.177.15] X-ClientProxiedBy: lhrpeml100002.china.huawei.com (7.191.160.241) To frapeml500008.china.huawei.com (7.182.85.71) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250905_024531_004551_971A287B X-CRM114-Status: GOOD ( 24.16 ) 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, 3 Sep 2025 15:23:31 +0200 "Rafael J. Wysocki" wrote: > 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/acpi/processor_thermal.c | 37 ++++++++++++++++++-------------- > > 1 file changed, 21 insertions(+), 16 deletions(-) > > > > diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_= thermal.c > > index 1219adb11ab9..5043f17d27b7 100644 > > --- a/drivers/acpi/processor_thermal.c > > +++ b/drivers/acpi/processor_thermal.c > > @@ -62,19 +62,14 @@ static int phys_package_first_cpu(int cpu) > > return 0; > > } > > > > -static int cpu_has_cpufreq(unsigned int cpu) > > +static bool cpu_has_cpufreq(unsigned int cpu) > > { > > - struct cpufreq_policy *policy; > > + struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D cp= ufreq_cpu_get(cpu); I'd put the order back as it was. See docs in cleanup.h, it is fine to declare local variables inline if they are being use with __free() That way if the simple check on acpi_process_cpu_freq_init fails no get needs to occur. So something like static bool cpu_has_cpufreq(unsigned int cpu) { if (!acpi_processor_cpufreq_init) return 0; struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D cpufreq_cpu_g= et(cpu); return policy !=3D NULL; //Personally I find !! on a pointer a bit weird :) } > > > > if (!acpi_processor_cpufreq_init) > > return 0; > > > > - policy =3D cpufreq_cpu_get(cpu); > > - if (policy) { > > - cpufreq_cpu_put(policy); > > - return 1; > > - } > > - return 0; > > + return !!policy; > > } > > > > static int cpufreq_get_max_state(unsigned int cpu) > > @@ -93,9 +88,23 @@ static int cpufreq_get_cur_state(unsigned int cpu) > > return reduction_step(cpu); > > } > > > > +static long long cpufreq_get_max_freq(unsigned int cpu) > > +{ > > + long long max_freq; > > + struct cpufreq_policy *policy __free(put_cpufreq_policy) =3D > > + cpufreq_cpu_get(cpu); Format consistently. If you are going to wrap to 80 chars here then do it for the cpu_has_cpufreq() line that is identical to this. > > + > > + if (!policy) > > + return -EINVAL; > > + > > + max_freq =3D (policy->cpuinfo.max_freq * > > + (100 - reduction_step(cpu) * cpufreq_thermal_reduction_= pctg)) / 100; > > + > > + return max_freq; > > +} > > + > > static int cpufreq_set_cur_state(unsigned int cpu, int state) > > { > > - struct cpufreq_policy *policy; > > struct acpi_processor *pr; > > unsigned long max_freq; > > int i, ret; > > @@ -120,14 +129,10 @@ static int cpufreq_set_cur_state(unsigned int cpu= , int state) > > if (unlikely(!freq_qos_request_active(&pr->thermal_req)= )) > > continue; > > > > - policy =3D cpufreq_cpu_get(i); > > - if (!policy) > > - return -EINVAL; > > - > > - max_freq =3D (policy->cpuinfo.max_freq * > > - (100 - reduction_step(i) * cpufreq_thermal_= reduction_pctg)) / 100; > > + max_freq =3D cpufreq_get_max_freq(cpu); > > > > - cpufreq_cpu_put(policy); > > + if (max_freq =3D=3D -EINVAL) > > + return -EINVAL; =20 >=20 > Please also move the code below to the new function so it does not > need to return a value. >=20 > > > > ret =3D freq_qos_update_request(&pr->thermal_req, max_f= req); > > if (ret < 0) { > > -- =20 >=20