* [PATCH] drm/amd/pm: clean up redundant comparisons with 0
@ 2023-11-07 8:29 José Pekkarinen
2023-11-07 14:08 ` Guenter Roeck
0 siblings, 1 reply; 5+ messages in thread
From: José Pekkarinen @ 2023-11-07 8:29 UTC (permalink / raw)
To: evan.quan, alexander.deucher, christian.koenig, Xinhui.Pan, skhan
Cc: José Pekkarinen, airlied, daniel, jdelvare, linux, amd-gfx,
dri-devel, linux-kernel, linux-hwmon, linux-kernel-mentees
There is a couple of function return checks of functions that return
unsigned values, and local variables to hold them are also unsigned, so
checking if they are negative will always return false. This patch will
remove them, as well as the never reached code.
drivers/gpu/drm/amd/pm/amdgpu_pm.c:2801:5-8: WARNING: Unsigned expression compared with zero: val < 0
drivers/gpu/drm/amd/pm/amdgpu_pm.c:2814:5-8: WARNING: Unsigned expression compared with zero: val < 0
Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
---
drivers/gpu/drm/amd/pm/amdgpu_pm.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index 8bb2da13826f..e7bb1d324084 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
@@ -2798,8 +2798,6 @@ static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
unsigned int val;
val = amdgpu_hwmon_get_power(dev, AMDGPU_PP_SENSOR_GPU_AVG_POWER);
- if (val < 0)
- return val;
return sysfs_emit(buf, "%u\n", val);
}
@@ -2811,8 +2809,6 @@ static ssize_t amdgpu_hwmon_show_power_input(struct device *dev,
unsigned int val;
val = amdgpu_hwmon_get_power(dev, AMDGPU_PP_SENSOR_GPU_INPUT_POWER);
- if (val < 0)
- return val;
return sysfs_emit(buf, "%u\n", val);
}
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/amd/pm: clean up redundant comparisons with 0
2023-11-07 8:29 [PATCH] drm/amd/pm: clean up redundant comparisons with 0 José Pekkarinen
@ 2023-11-07 14:08 ` Guenter Roeck
2023-11-07 17:26 ` José Pekkarinen
0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2023-11-07 14:08 UTC (permalink / raw)
To: José Pekkarinen, evan.quan, alexander.deucher,
christian.koenig, Xinhui.Pan, skhan
Cc: airlied, daniel, jdelvare, amd-gfx, dri-devel, linux-kernel,
linux-hwmon, linux-kernel-mentees
On 11/7/23 00:29, José Pekkarinen wrote:
> There is a couple of function return checks of functions that return
> unsigned values, and local variables to hold them are also unsigned, so
> checking if they are negative will always return false. This patch will
> remove them, as well as the never reached code.
>
> drivers/gpu/drm/amd/pm/amdgpu_pm.c:2801:5-8: WARNING: Unsigned expression compared with zero: val < 0
> drivers/gpu/drm/amd/pm/amdgpu_pm.c:2814:5-8: WARNING: Unsigned expression compared with zero: val < 0
>
> Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
> ---
> drivers/gpu/drm/amd/pm/amdgpu_pm.c | 4 ----
> 1 file changed, 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> index 8bb2da13826f..e7bb1d324084 100644
> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> @@ -2798,8 +2798,6 @@ static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
> unsigned int val;
>
> val = amdgpu_hwmon_get_power(dev, AMDGPU_PP_SENSOR_GPU_AVG_POWER);
> - if (val < 0)
> - return val;
>
This is reporting errors returned from amdgpu_hwmon_get_power() as large integers.
Guenter
> return sysfs_emit(buf, "%u\n", val);
> }
> @@ -2811,8 +2809,6 @@ static ssize_t amdgpu_hwmon_show_power_input(struct device *dev,
> unsigned int val;
>
> val = amdgpu_hwmon_get_power(dev, AMDGPU_PP_SENSOR_GPU_INPUT_POWER);
> - if (val < 0)
> - return val;
>
> return sysfs_emit(buf, "%u\n", val);
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/amd/pm: clean up redundant comparisons with 0
2023-11-07 14:08 ` Guenter Roeck
@ 2023-11-07 17:26 ` José Pekkarinen
2023-11-07 18:03 ` Guenter Roeck
0 siblings, 1 reply; 5+ messages in thread
From: José Pekkarinen @ 2023-11-07 17:26 UTC (permalink / raw)
To: Guenter Roeck
Cc: evan.quan, alexander.deucher, christian.koenig, Xinhui.Pan, skhan,
airlied, daniel, jdelvare, amd-gfx, dri-devel, linux-kernel,
linux-hwmon, linux-kernel-mentees
On 2023-11-07 16:08, Guenter Roeck wrote:
> On 11/7/23 00:29, José Pekkarinen wrote:
>> There is a couple of function return checks of functions that return
>> unsigned values, and local variables to hold them are also unsigned,
>> so
>> checking if they are negative will always return false. This patch
>> will
>> remove them, as well as the never reached code.
>>
>> drivers/gpu/drm/amd/pm/amdgpu_pm.c:2801:5-8: WARNING: Unsigned
>> expression compared with zero: val < 0
>> drivers/gpu/drm/amd/pm/amdgpu_pm.c:2814:5-8: WARNING: Unsigned
>> expression compared with zero: val < 0
>>
>> Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
>> ---
>> drivers/gpu/drm/amd/pm/amdgpu_pm.c | 4 ----
>> 1 file changed, 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>> b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>> index 8bb2da13826f..e7bb1d324084 100644
>> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>> @@ -2798,8 +2798,6 @@ static ssize_t
>> amdgpu_hwmon_show_power_avg(struct device *dev,
>> unsigned int val;
>> val = amdgpu_hwmon_get_power(dev,
>> AMDGPU_PP_SENSOR_GPU_AVG_POWER);
>> - if (val < 0)
>> - return val;
>>
>
> This is reporting errors returned from amdgpu_hwmon_get_power() as
> large integers.
Alright, that case it is a false positive, thanks for the comment!
José.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] drm/amd/pm: clean up redundant comparisons with 0
2023-11-07 17:26 ` José Pekkarinen
@ 2023-11-07 18:03 ` Guenter Roeck
2023-11-08 7:02 ` José Pekkarinen
0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2023-11-07 18:03 UTC (permalink / raw)
To: José Pekkarinen
Cc: evan.quan, alexander.deucher, christian.koenig, Xinhui.Pan, skhan,
airlied, daniel, jdelvare, amd-gfx, dri-devel, linux-kernel,
linux-hwmon, linux-kernel-mentees
On 11/7/23 09:26, José Pekkarinen wrote:
> On 2023-11-07 16:08, Guenter Roeck wrote:
>> On 11/7/23 00:29, José Pekkarinen wrote:
>>> There is a couple of function return checks of functions that return
>>> unsigned values, and local variables to hold them are also unsigned, so
>>> checking if they are negative will always return false. This patch will
>>> remove them, as well as the never reached code.
>>>
>>> drivers/gpu/drm/amd/pm/amdgpu_pm.c:2801:5-8: WARNING: Unsigned expression compared with zero: val < 0
>>> drivers/gpu/drm/amd/pm/amdgpu_pm.c:2814:5-8: WARNING: Unsigned expression compared with zero: val < 0
>>>
>>> Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
>>> ---
>>> drivers/gpu/drm/amd/pm/amdgpu_pm.c | 4 ----
>>> 1 file changed, 4 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>>> index 8bb2da13826f..e7bb1d324084 100644
>>> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>>> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>>> @@ -2798,8 +2798,6 @@ static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
>>> unsigned int val;
>>> val = amdgpu_hwmon_get_power(dev, AMDGPU_PP_SENSOR_GPU_AVG_POWER);
>>> - if (val < 0)
>>> - return val;
>>>
>>
>> This is reporting errors returned from amdgpu_hwmon_get_power() as
>> large integers.
>
> Alright, that case it is a false positive, thanks for the comment!
>
No, it isn't a false positive. The fix is wrong. The variable should be declared
'int val', not 'unsigned int val'.
Guenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/amd/pm: clean up redundant comparisons with 0
2023-11-07 18:03 ` Guenter Roeck
@ 2023-11-08 7:02 ` José Pekkarinen
0 siblings, 0 replies; 5+ messages in thread
From: José Pekkarinen @ 2023-11-08 7:02 UTC (permalink / raw)
To: Guenter Roeck
Cc: evan.quan, alexander.deucher, christian.koenig, Xinhui.Pan, skhan,
airlied, daniel, jdelvare, amd-gfx, dri-devel, linux-kernel,
linux-hwmon, linux-kernel-mentees
On 2023-11-07 20:03, Guenter Roeck wrote:
> On 11/7/23 09:26, José Pekkarinen wrote:
>> On 2023-11-07 16:08, Guenter Roeck wrote:
>>> On 11/7/23 00:29, José Pekkarinen wrote:
>>>> There is a couple of function return checks of functions that return
>>>> unsigned values, and local variables to hold them are also unsigned,
>>>> so
>>>> checking if they are negative will always return false. This patch
>>>> will
>>>> remove them, as well as the never reached code.
>>>>
>>>> drivers/gpu/drm/amd/pm/amdgpu_pm.c:2801:5-8: WARNING: Unsigned
>>>> expression compared with zero: val < 0
>>>> drivers/gpu/drm/amd/pm/amdgpu_pm.c:2814:5-8: WARNING: Unsigned
>>>> expression compared with zero: val < 0
>>>>
>>>> Signed-off-by: José Pekkarinen <jose.pekkarinen@foxhound.fi>
>>>> ---
>>>> drivers/gpu/drm/amd/pm/amdgpu_pm.c | 4 ----
>>>> 1 file changed, 4 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>>>> b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>>>> index 8bb2da13826f..e7bb1d324084 100644
>>>> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>>>> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
>>>> @@ -2798,8 +2798,6 @@ static ssize_t
>>>> amdgpu_hwmon_show_power_avg(struct device *dev,
>>>> unsigned int val;
>>>> val = amdgpu_hwmon_get_power(dev,
>>>> AMDGPU_PP_SENSOR_GPU_AVG_POWER);
>>>> - if (val < 0)
>>>> - return val;
>>>>
>>>
>>> This is reporting errors returned from amdgpu_hwmon_get_power() as
>>> large integers.
>>
>> Alright, that case it is a false positive, thanks for the
>> comment!
>>
>
>
> No, it isn't a false positive. The fix is wrong. The variable should be
> declared
> 'int val', not 'unsigned int val'.
Sorry I may have missunderstood your comment, I certainly can do the
minor fix then.
Thanks!
José.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-08 11:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-07 8:29 [PATCH] drm/amd/pm: clean up redundant comparisons with 0 José Pekkarinen
2023-11-07 14:08 ` Guenter Roeck
2023-11-07 17:26 ` José Pekkarinen
2023-11-07 18:03 ` Guenter Roeck
2023-11-08 7:02 ` José Pekkarinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox