2020-01-20 13:08:08

by chenzhou

[permalink] [raw]
Subject: [PATCH -next] backlight: qcom-wled: fix unsigned comparison to zero

Fixes coccicheck warning:
./drivers/video/backlight/qcom-wled.c:1104:5-15:
WARNING: Unsigned expression compared with zero: string_len > 0

The unsigned variable string_len is assigned a return value from the call
to wled_configure, which may return negative error code.

Fixes: 775d2ffb4af6 ("backlight: qcom-wled: Restructure the driver for WLED3")
Signed-off-by: Chen Zhou <[email protected]>
---
drivers/video/backlight/qcom-wled.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c
index d46052d..3d276b3 100644
--- a/drivers/video/backlight/qcom-wled.c
+++ b/drivers/video/backlight/qcom-wled.c
@@ -956,8 +956,8 @@ static int wled_configure(struct wled *wled, int version)
struct wled_config *cfg = &wled->cfg;
struct device *dev = wled->dev;
const __be32 *prop_addr;
- u32 size, val, c, string_len;
- int rc, i, j;
+ u32 size, val, c;
+ int rc, i, j, string_len;

const struct wled_u32_opts *u32_opts = NULL;
const struct wled_u32_opts wled3_opts[] = {
--
2.7.4


2020-01-22 00:40:50

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH -next] backlight: qcom-wled: fix unsigned comparison to zero

On Mon 20 Jan 05:01 PST 2020, Chen Zhou wrote:

> Fixes coccicheck warning:
> ./drivers/video/backlight/qcom-wled.c:1104:5-15:
> WARNING: Unsigned expression compared with zero: string_len > 0
>
> The unsigned variable string_len is assigned a return value from the call
> to wled_configure, which may return negative error code.
>

Afaict string_len is the return value of
of_property_count_elems_of_size(), rather than wled_configure(). (And
please append () to function names to make it even more obvious)

Except for that your patch looks good, so please update the commit
message and add my Reviewed-by: Bjorn Andersson <[email protected]>

Regards,
Bjorn

> Fixes: 775d2ffb4af6 ("backlight: qcom-wled: Restructure the driver for WLED3")
> Signed-off-by: Chen Zhou <[email protected]>
> ---
> drivers/video/backlight/qcom-wled.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c
> index d46052d..3d276b3 100644
> --- a/drivers/video/backlight/qcom-wled.c
> +++ b/drivers/video/backlight/qcom-wled.c
> @@ -956,8 +956,8 @@ static int wled_configure(struct wled *wled, int version)
> struct wled_config *cfg = &wled->cfg;
> struct device *dev = wled->dev;
> const __be32 *prop_addr;
> - u32 size, val, c, string_len;
> - int rc, i, j;
> + u32 size, val, c;
> + int rc, i, j, string_len;
>
> const struct wled_u32_opts *u32_opts = NULL;
> const struct wled_u32_opts wled3_opts[] = {
> --
> 2.7.4
>

2020-01-22 01:22:42

by chenzhou

[permalink] [raw]
Subject: Re: [PATCH -next] backlight: qcom-wled: fix unsigned comparison to zero

Hi Bjorn,

On 2020/1/22 8:39, Bjorn Andersson wrote:
> On Mon 20 Jan 05:01 PST 2020, Chen Zhou wrote:
>
>> Fixes coccicheck warning:
>> ./drivers/video/backlight/qcom-wled.c:1104:5-15:
>> WARNING: Unsigned expression compared with zero: string_len > 0
>>
>> The unsigned variable string_len is assigned a return value from the call
>> to wled_configure, which may return negative error code.
>>
>
> Afaict string_len is the return value of
> of_property_count_elems_of_size(), rather than wled_configure(). (And
> please append () to function names to make it even more obvious)
>
> Except for that your patch looks good, so please update the commit
> message and add my Reviewed-by: Bjorn Andersson <[email protected]>
>
> Regards,
> Bjorn

Thanks for your review, i will fix this in next version.

Thanks,
Chen Zhou

>
>> Fixes: 775d2ffb4af6 ("backlight: qcom-wled: Restructure the driver for WLED3")
>> Signed-off-by: Chen Zhou <[email protected]>
>> ---
>> drivers/video/backlight/qcom-wled.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c
>> index d46052d..3d276b3 100644
>> --- a/drivers/video/backlight/qcom-wled.c
>> +++ b/drivers/video/backlight/qcom-wled.c
>> @@ -956,8 +956,8 @@ static int wled_configure(struct wled *wled, int version)
>> struct wled_config *cfg = &wled->cfg;
>> struct device *dev = wled->dev;
>> const __be32 *prop_addr;
>> - u32 size, val, c, string_len;
>> - int rc, i, j;
>> + u32 size, val, c;
>> + int rc, i, j, string_len;
>>
>> const struct wled_u32_opts *u32_opts = NULL;
>> const struct wled_u32_opts wled3_opts[] = {
>> --
>> 2.7.4
>>
>
> .
>