[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0jZ+4Ze2t8pw1MPUqzFYFr7g7h6Y-f=gwsmUgbvSThYGg@mail.gmail.com>
Date: Fri, 29 Aug 2025 18:52:41 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Qianfeng Rong <rongqianfeng@...o.com>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>, Viresh Kumar <viresh.kumar@...aro.org>, linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] cpufreq: Use int type to store negative error codes
On Fri, Aug 29, 2025 at 10:44 AM Qianfeng Rong <rongqianfeng@...o.com> wrote:
>
> Change the 'ret' variable from unsigned int to int to store negative error
> codes directly or returned by other functions.
You need to say upfront that this is about speedstep_get_freqs() specifically.
> Change the return type of
> the speedstep_get_freqs() function from unsigned int to int as well.
>
> Storing the negative error codes in unsigned type, doesn't cause an issue
> at runtime but it's ugly as pants.
Which isn't really a technical term.
> Additionally, assigning negative error codes to unsigned type may trigger a GCC warning
> when the -Wsign-conversion flag is enabled.
Is the latter a motivation for this change?
> No effect on runtime.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@...o.com>
> ---
> drivers/cpufreq/cpufreq.c | 2 +-
> drivers/cpufreq/powernow-k7.c | 2 +-
> drivers/cpufreq/speedstep-lib.c | 12 ++++++------
> drivers/cpufreq/speedstep-lib.h | 10 +++++-----
> 4 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index a615c98d80ca..f47096683abb 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -914,7 +914,7 @@ static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
> const char *buf, size_t count)
> {
> unsigned int freq = 0;
> - unsigned int ret;
> + int ret;
>
> if (!policy->governor || !policy->governor->store_setspeed)
> return -EINVAL;
> diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
> index 31039330a3ba..88616cd14353 100644
> --- a/drivers/cpufreq/powernow-k7.c
> +++ b/drivers/cpufreq/powernow-k7.c
> @@ -451,7 +451,7 @@ static int powernow_decode_bios(int maxfid, int startvid)
> unsigned int i, j;
> unsigned char *p;
> unsigned int etuple;
> - unsigned int ret;
> + int ret;
>
> etuple = cpuid_eax(0x80000001);
>
> diff --git a/drivers/cpufreq/speedstep-lib.c b/drivers/cpufreq/speedstep-lib.c
> index 0b66df4ed513..f8b42e981635 100644
> --- a/drivers/cpufreq/speedstep-lib.c
> +++ b/drivers/cpufreq/speedstep-lib.c
> @@ -378,16 +378,16 @@ EXPORT_SYMBOL_GPL(speedstep_detect_processor);
> * DETECT SPEEDSTEP SPEEDS *
> *********************************************************************/
>
> -unsigned int speedstep_get_freqs(enum speedstep_processor processor,
> - unsigned int *low_speed,
> - unsigned int *high_speed,
> - unsigned int *transition_latency,
> - void (*set_state) (unsigned int state))
> +int speedstep_get_freqs(enum speedstep_processor processor,
> + unsigned int *low_speed,
> + unsigned int *high_speed,
> + unsigned int *transition_latency,
> + void (*set_state)(unsigned int state))
> {
> unsigned int prev_speed;
> - unsigned int ret = 0;
> unsigned long flags;
> ktime_t tv1, tv2;
> + int ret = 0;
>
> if ((!processor) || (!low_speed) || (!high_speed) || (!set_state))
> return -EINVAL;
> diff --git a/drivers/cpufreq/speedstep-lib.h b/drivers/cpufreq/speedstep-lib.h
> index dc762ea786be..48329647d4c4 100644
> --- a/drivers/cpufreq/speedstep-lib.h
> +++ b/drivers/cpufreq/speedstep-lib.h
> @@ -41,8 +41,8 @@ extern unsigned int speedstep_get_frequency(enum speedstep_processor processor);
> * SPEEDSTEP_LOW; the second argument is zero so that no
> * cpufreq_notify_transition calls are initiated.
> */
> -extern unsigned int speedstep_get_freqs(enum speedstep_processor processor,
> - unsigned int *low_speed,
> - unsigned int *high_speed,
> - unsigned int *transition_latency,
> - void (*set_state) (unsigned int state));
> +extern int speedstep_get_freqs(enum speedstep_processor processor,
> + unsigned int *low_speed,
> + unsigned int *high_speed,
> + unsigned int *transition_latency,
> + void (*set_state)(unsigned int state));
> --
Powered by blists - more mailing lists