linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] cpufreq: Use int type to store negative error codes
@ 2025-09-02 11:45 Qianfeng Rong
  2025-09-02 11:45 ` [PATCH v3 1/3] " Qianfeng Rong
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Qianfeng Rong @ 2025-09-02 11:45 UTC (permalink / raw)
  To: Rafael J. Wysocki, Viresh Kumar,
	open list:CPU FREQUENCY SCALING FRAMEWORK, open list
  Cc: Qianfeng Rong

The 'ret' variable usually is used to store returns from some functions,
which return either zero on success or negative error codes on failure.

Storing the negative error codes in unsigned type, doesn't cause an issue
at runtime but can be confusing.  Additionally, assigning negative error
codes to unsigned type may trigger a GCC warning when the -Wsign-conversion
flag is enabled.

Change "ret" from unsigned int to int type.  No effect on runtime.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
Change in v2:
- Modified commit message.

Changes in v3:
- Split each driver into a separate patch.
- In drivers/cpufreq/powernow-k7.c, remove the 'unsigned int ret' variable
  from the powernow_decode_bios() function; since it is only used in one
  place, this simplifies the code.
---
Qianfeng Rong (3):
  cpufreq: Use int type to store negative error codes
  cpufreq: powernow: Use int type to store negative error codes
  cpufreq: speedstep-lib: Use int type to store negative error codes

 drivers/cpufreq/cpufreq.c       |  2 +-
 drivers/cpufreq/powernow-k7.c   |  4 +---
 drivers/cpufreq/speedstep-lib.c | 12 ++++++------
 drivers/cpufreq/speedstep-lib.h | 10 +++++-----
 4 files changed, 13 insertions(+), 15 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/3] cpufreq: Use int type to store negative error codes
  2025-09-02 11:45 [PATCH v3 0/3] cpufreq: Use int type to store negative error codes Qianfeng Rong
@ 2025-09-02 11:45 ` Qianfeng Rong
  2025-09-03  4:12   ` Viresh Kumar
  2025-09-02 11:45 ` [PATCH v3 2/3] cpufreq: powernow: " Qianfeng Rong
  2025-09-02 11:45 ` [PATCH v3 3/3] cpufreq: speedstep-lib: " Qianfeng Rong
  2 siblings, 1 reply; 8+ messages in thread
From: Qianfeng Rong @ 2025-09-02 11:45 UTC (permalink / raw)
  To: Rafael J. Wysocki, Viresh Kumar,
	open list:CPU FREQUENCY SCALING FRAMEWORK, open list
  Cc: Qianfeng Rong

Change the 'ret' variable in store_scaling_setspeed() from unsigned int to
int, as it needs to store either negative error codes or zero returned
by kstrtouint().

No effect on runtime.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/cpufreq/cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/3] cpufreq: powernow: Use int type to store negative error codes
  2025-09-02 11:45 [PATCH v3 0/3] cpufreq: Use int type to store negative error codes Qianfeng Rong
  2025-09-02 11:45 ` [PATCH v3 1/3] " Qianfeng Rong
@ 2025-09-02 11:45 ` Qianfeng Rong
  2025-09-03  4:14   ` Viresh Kumar
  2025-09-02 11:45 ` [PATCH v3 3/3] cpufreq: speedstep-lib: " Qianfeng Rong
  2 siblings, 1 reply; 8+ messages in thread
From: Qianfeng Rong @ 2025-09-02 11:45 UTC (permalink / raw)
  To: Rafael J. Wysocki, Viresh Kumar,
	open list:CPU FREQUENCY SCALING FRAMEWORK, open list
  Cc: Qianfeng Rong

In powernow_decode_bios(), the 'ret' variable stores either negative error
codes or zero returned by get_ranges(), so it needs to be changed to int
type.  However, since the 'ret' variable is only used once and can be
simplified to 'return get_ranges()', it is better to remove the 'ret'
variable.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
 drivers/cpufreq/powernow-k7.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
index 31039330a3ba..72430c3c5500 100644
--- a/drivers/cpufreq/powernow-k7.c
+++ b/drivers/cpufreq/powernow-k7.c
@@ -451,7 +451,6 @@ static int powernow_decode_bios(int maxfid, int startvid)
 	unsigned int i, j;
 	unsigned char *p;
 	unsigned int etuple;
-	unsigned int ret;
 
 	etuple = cpuid_eax(0x80000001);
 
@@ -500,8 +499,7 @@ static int powernow_decode_bios(int maxfid, int startvid)
 				    (startvid == pst->startvid)) {
 					print_pst_entry(pst, j);
 					p = (char *)pst + sizeof(*pst);
-					ret = get_ranges(p);
-					return ret;
+					return get_ranges(p);
 				} else {
 					unsigned int k;
 					p = (char *)pst + sizeof(*pst);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 3/3] cpufreq: speedstep-lib: Use int type to store negative error codes
  2025-09-02 11:45 [PATCH v3 0/3] cpufreq: Use int type to store negative error codes Qianfeng Rong
  2025-09-02 11:45 ` [PATCH v3 1/3] " Qianfeng Rong
  2025-09-02 11:45 ` [PATCH v3 2/3] cpufreq: powernow: " Qianfeng Rong
@ 2025-09-02 11:45 ` Qianfeng Rong
  2025-09-03  4:13   ` Viresh Kumar
  2 siblings, 1 reply; 8+ messages in thread
From: Qianfeng Rong @ 2025-09-02 11:45 UTC (permalink / raw)
  To: Rafael J. Wysocki, Viresh Kumar,
	open list:CPU FREQUENCY SCALING FRAMEWORK, open list
  Cc: Qianfeng Rong

Change the return type of the speedstep_get_freqs() function from unsigned
int to int because it may return negative error codes.  For the same
reason, change the 'ret' variables to int type as well.

No effect on runtime.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/cpufreq/speedstep-lib.c | 12 ++++++------
 drivers/cpufreq/speedstep-lib.h | 10 +++++-----
 2 files changed, 11 insertions(+), 11 deletions(-)

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));
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/3] cpufreq: Use int type to store negative error codes
  2025-09-02 11:45 ` [PATCH v3 1/3] " Qianfeng Rong
@ 2025-09-03  4:12   ` Viresh Kumar
  0 siblings, 0 replies; 8+ messages in thread
From: Viresh Kumar @ 2025-09-03  4:12 UTC (permalink / raw)
  To: Qianfeng Rong
  Cc: Rafael J. Wysocki, open list:CPU FREQUENCY SCALING FRAMEWORK,
	open list

On 02-09-25, 19:45, Qianfeng Rong wrote:
> Change the 'ret' variable in store_scaling_setspeed() from unsigned int to
> int, as it needs to store either negative error codes or zero returned
> by kstrtouint().
> 
> No effect on runtime.
> 
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
>  drivers/cpufreq/cpufreq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 3/3] cpufreq: speedstep-lib: Use int type to store negative error codes
  2025-09-02 11:45 ` [PATCH v3 3/3] cpufreq: speedstep-lib: " Qianfeng Rong
@ 2025-09-03  4:13   ` Viresh Kumar
  0 siblings, 0 replies; 8+ messages in thread
From: Viresh Kumar @ 2025-09-03  4:13 UTC (permalink / raw)
  To: Qianfeng Rong
  Cc: Rafael J. Wysocki, open list:CPU FREQUENCY SCALING FRAMEWORK,
	open list

On 02-09-25, 19:45, Qianfeng Rong wrote:
> Change the return type of the speedstep_get_freqs() function from unsigned
> int to int because it may return negative error codes.  For the same
> reason, change the 'ret' variables to int type as well.
> 
> No effect on runtime.
> 
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
>  drivers/cpufreq/speedstep-lib.c | 12 ++++++------
>  drivers/cpufreq/speedstep-lib.h | 10 +++++-----
>  2 files changed, 11 insertions(+), 11 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 2/3] cpufreq: powernow: Use int type to store negative error codes
  2025-09-02 11:45 ` [PATCH v3 2/3] cpufreq: powernow: " Qianfeng Rong
@ 2025-09-03  4:14   ` Viresh Kumar
  2025-09-03  6:50     ` Qianfeng Rong
  0 siblings, 1 reply; 8+ messages in thread
From: Viresh Kumar @ 2025-09-03  4:14 UTC (permalink / raw)
  To: Qianfeng Rong
  Cc: Rafael J. Wysocki, open list:CPU FREQUENCY SCALING FRAMEWORK,
	open list

$Subject is incorrect.

On 02-09-25, 19:45, Qianfeng Rong wrote:
> In powernow_decode_bios(), the 'ret' variable stores either negative error
> codes or zero returned by get_ranges(), so it needs to be changed to int
> type.

You don't need to mention this now. You are making a different change.

> However, since the 'ret' variable is only used once and can be
> simplified to 'return get_ranges()', it is better to remove the 'ret'
> variable.
> 
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
>  drivers/cpufreq/powernow-k7.c | 4 +---

There should be a `---` line in between these two statements, you have
corrupted your patch somehow.

>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
> index 31039330a3ba..72430c3c5500 100644
> --- a/drivers/cpufreq/powernow-k7.c
> +++ b/drivers/cpufreq/powernow-k7.c
> @@ -451,7 +451,6 @@ static int powernow_decode_bios(int maxfid, int startvid)
>  	unsigned int i, j;
>  	unsigned char *p;
>  	unsigned int etuple;
> -	unsigned int ret;
>  
>  	etuple = cpuid_eax(0x80000001);
>  
> @@ -500,8 +499,7 @@ static int powernow_decode_bios(int maxfid, int startvid)
>  				    (startvid == pst->startvid)) {
>  					print_pst_entry(pst, j);
>  					p = (char *)pst + sizeof(*pst);
> -					ret = get_ranges(p);
> -					return ret;
> +					return get_ranges(p);
>  				} else {
>  					unsigned int k;
>  					p = (char *)pst + sizeof(*pst);
> -- 
> 2.34.1

-- 
viresh

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 2/3] cpufreq: powernow: Use int type to store negative error codes
  2025-09-03  4:14   ` Viresh Kumar
@ 2025-09-03  6:50     ` Qianfeng Rong
  0 siblings, 0 replies; 8+ messages in thread
From: Qianfeng Rong @ 2025-09-03  6:50 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael J. Wysocki, open list:CPU FREQUENCY SCALING FRAMEWORK,
	open list


在 2025/9/3 12:14, Viresh Kumar 写道:
> $Subject is incorrect.
>
> On 02-09-25, 19:45, Qianfeng Rong wrote:
>> In powernow_decode_bios(), the 'ret' variable stores either negative error
>> codes or zero returned by get_ranges(), so it needs to be changed to int
>> type.
> You don't need to mention this now. You are making a different change.


Okay, since this patch is no longer part of this series, I will send a
patch for thismodification separately later, thank you.


>
>> However, since the 'ret' variable is only used once and can be
>> simplified to 'return get_ranges()', it is better to remove the 'ret'
>> variable.
>>
>> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
>>   drivers/cpufreq/powernow-k7.c | 4 +---
> There should be a `---` line in between these two statements, you have
> corrupted your patch somehow.
>
Ah this is my bad.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-03  6:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-02 11:45 [PATCH v3 0/3] cpufreq: Use int type to store negative error codes Qianfeng Rong
2025-09-02 11:45 ` [PATCH v3 1/3] " Qianfeng Rong
2025-09-03  4:12   ` Viresh Kumar
2025-09-02 11:45 ` [PATCH v3 2/3] cpufreq: powernow: " Qianfeng Rong
2025-09-03  4:14   ` Viresh Kumar
2025-09-03  6:50     ` Qianfeng Rong
2025-09-02 11:45 ` [PATCH v3 3/3] cpufreq: speedstep-lib: " Qianfeng Rong
2025-09-03  4:13   ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).