2023-07-27 02:02:39

by Yang Li

[permalink] [raw]
Subject: [PATCH -next] platform/x86/amd/pmf: Fix unsigned comparison with less than zero

The return value from the call to amd_pmf_get_pprof_modes() is int.
However, the return value is being assigned to an unsigned char
variable 'mode', so making 'mode' an int.

silence the warning:
./drivers/platform/x86/amd/pmf/sps.c:183:5-9: WARNING: Unsigned expression compared with zero: mode < 0

Reported-by: Abaci Robot <[email protected]>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5995
Signed-off-by: Yang Li <[email protected]>
---
drivers/platform/x86/amd/pmf/sps.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/amd/pmf/sps.c b/drivers/platform/x86/amd/pmf/sps.c
index ab69d517a36a..a70e67749be3 100644
--- a/drivers/platform/x86/amd/pmf/sps.c
+++ b/drivers/platform/x86/amd/pmf/sps.c
@@ -176,7 +176,8 @@ int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf)

int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev)
{
- u8 mode, flag = 0;
+ u8 flag = 0;
+ int mode;
int src;

mode = amd_pmf_get_pprof_modes(dev);
--
2.20.1.7.g153144c



2023-07-31 15:07:17

by Hans de Goede

[permalink] [raw]
Subject: Re: [PATCH -next] platform/x86/amd/pmf: Fix unsigned comparison with less than zero

Hi,

On 7/27/23 03:43, Yang Li wrote:
> The return value from the call to amd_pmf_get_pprof_modes() is int.
> However, the return value is being assigned to an unsigned char
> variable 'mode', so making 'mode' an int.
>
> silence the warning:
> ./drivers/platform/x86/amd/pmf/sps.c:183:5-9: WARNING: Unsigned expression compared with zero: mode < 0
>
> Reported-by: Abaci Robot <[email protected]>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=5995
> Signed-off-by: Yang Li <[email protected]>

Thank you for your patch, I've applied this patch to my fixes
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=fixes

Note it will show up in my fixes branch once I've pushed my
local branch there, which might take a while.

I will include this patch in my next fixes pull-req to Linus
for the current kernel development cycle.

Regards,

Hans

> ---
> drivers/platform/x86/amd/pmf/sps.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/amd/pmf/sps.c b/drivers/platform/x86/amd/pmf/sps.c
> index ab69d517a36a..a70e67749be3 100644
> --- a/drivers/platform/x86/amd/pmf/sps.c
> +++ b/drivers/platform/x86/amd/pmf/sps.c
> @@ -176,7 +176,8 @@ int amd_pmf_get_pprof_modes(struct amd_pmf_dev *pmf)
>
> int amd_pmf_power_slider_update_event(struct amd_pmf_dev *dev)
> {
> - u8 mode, flag = 0;
> + u8 flag = 0;
> + int mode;
> int src;
>
> mode = amd_pmf_get_pprof_modes(dev);