2022-04-06 11:53:51

by Marco Pagani

[permalink] [raw]
Subject: [PATCH] fpga: altera-pr-ip: fix unsigned comparison with less than zero

Fix the "comparison with less than zero" warning reported by
cppcheck for the unsigned (size_t) parameter "count" of the
"alt_pr_fpga_write()" function.

Signed-off-by: Marco Pagani <[email protected]>
---
drivers/fpga/altera-pr-ip-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/fpga/altera-pr-ip-core.c b/drivers/fpga/altera-pr-ip-core.c
index be0667968d33..2ff3d8e46a0c 100644
--- a/drivers/fpga/altera-pr-ip-core.c
+++ b/drivers/fpga/altera-pr-ip-core.c
@@ -108,7 +108,7 @@ static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf,
u32 *buffer_32 = (u32 *)buf;
size_t i = 0;

- if (count <= 0)
+ if (count == 0)
return -EINVAL;

/* Write out the complete 32-bit chunks */
--
2.35.1


2022-04-06 17:08:09

by Tom Rix

[permalink] [raw]
Subject: Re: [PATCH] fpga: altera-pr-ip: fix unsigned comparison with less than zero


On 4/5/22 11:53 AM, Marco Pagani wrote:
> Fix the "comparison with less than zero" warning reported by
> cppcheck for the unsigned (size_t) parameter "count" of the
> "alt_pr_fpga_write()" function.
>
> Signed-off-by: Marco Pagani <[email protected]>
> ---
> drivers/fpga/altera-pr-ip-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/fpga/altera-pr-ip-core.c b/drivers/fpga/altera-pr-ip-core.c
> index be0667968d33..2ff3d8e46a0c 100644
> --- a/drivers/fpga/altera-pr-ip-core.c
> +++ b/drivers/fpga/altera-pr-ip-core.c
> @@ -108,7 +108,7 @@ static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf,
> u32 *buffer_32 = (u32 *)buf;
> size_t i = 0;
>
> - if (count <= 0)
> + if (count == 0)
> return -EINVAL;

Reviewed-by: Tom Rix <[email protected]>

>
> /* Write out the complete 32-bit chunks */

2022-04-07 19:51:20

by Xu Yilun

[permalink] [raw]
Subject: Re: [PATCH] fpga: altera-pr-ip: fix unsigned comparison with less than zero

On Wed, Apr 06, 2022 at 07:18:21AM -0700, Tom Rix wrote:
>
> On 4/5/22 11:53 AM, Marco Pagani wrote:
> > Fix the "comparison with less than zero" warning reported by
> > cppcheck for the unsigned (size_t) parameter "count" of the
> > "alt_pr_fpga_write()" function.
> >
> > Signed-off-by: Marco Pagani <[email protected]>
> > ---
> > drivers/fpga/altera-pr-ip-core.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/fpga/altera-pr-ip-core.c b/drivers/fpga/altera-pr-ip-core.c
> > index be0667968d33..2ff3d8e46a0c 100644
> > --- a/drivers/fpga/altera-pr-ip-core.c
> > +++ b/drivers/fpga/altera-pr-ip-core.c
> > @@ -108,7 +108,7 @@ static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf,
> > u32 *buffer_32 = (u32 *)buf;
> > size_t i = 0;
> > - if (count <= 0)
> > + if (count == 0)
> > return -EINVAL;
>
> Reviewed-by: Tom Rix <[email protected]>

Acked-by: Xu Yilun <[email protected]>

>
> > /* Write out the complete 32-bit chunks */

2022-04-21 16:53:39

by Moritz Fischer

[permalink] [raw]
Subject: Re: [PATCH] fpga: altera-pr-ip: fix unsigned comparison with less than zero

Marco,

On Tue, Apr 05, 2022 at 08:53:49PM +0200, Marco Pagani wrote:
> Fix the "comparison with less than zero" warning reported by
> cppcheck for the unsigned (size_t) parameter "count" of the
> "alt_pr_fpga_write()" function.
>
Should this have a Reported-by: tag?
> Signed-off-by: Marco Pagani <[email protected]>
> ---
> drivers/fpga/altera-pr-ip-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/fpga/altera-pr-ip-core.c b/drivers/fpga/altera-pr-ip-core.c
> index be0667968d33..2ff3d8e46a0c 100644
> --- a/drivers/fpga/altera-pr-ip-core.c
> +++ b/drivers/fpga/altera-pr-ip-core.c
> @@ -108,7 +108,7 @@ static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf,
> u32 *buffer_32 = (u32 *)buf;
> size_t i = 0;
>
> - if (count <= 0)
> + if (count == 0)
> return -EINVAL;

if (!count)
return -EINVAL?
>
> /* Write out the complete 32-bit chunks */
> --
> 2.35.1

Cheers,
Moritz
>

2022-04-22 19:14:10

by Marco Pagani

[permalink] [raw]
Subject: Re: [PATCH] fpga: altera-pr-ip: fix unsigned comparison with less than zero

On 2022-04-20 06:24, Moritz Fischer wrote:
> Marco,
>
> On Tue, Apr 05, 2022 at 08:53:49PM +0200, Marco Pagani wrote:
>> Fix the "comparison with less than zero" warning reported by
>> cppcheck for the unsigned (size_t) parameter "count" of the
>> "alt_pr_fpga_write()" function.
>>
> Should this have a Reported-by: tag?

I found this problem using the "cppcheck" tool, as reported in the
commit log. I did not find any previous report of this. Am I missing
something?

>> Signed-off-by: Marco Pagani <[email protected]>
>> ---
>> drivers/fpga/altera-pr-ip-core.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/fpga/altera-pr-ip-core.c b/drivers/fpga/altera-pr-ip-core.c
>> index be0667968d33..2ff3d8e46a0c 100644
>> --- a/drivers/fpga/altera-pr-ip-core.c
>> +++ b/drivers/fpga/altera-pr-ip-core.c
>> @@ -108,7 +108,7 @@ static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf,
>> u32 *buffer_32 = (u32 *)buf;
>> size_t i = 0;
>>
>> - if (count <= 0)
>> + if (count == 0)
>> return -EINVAL;
>
> if (!count)
> return -EINVAL?

Ok, I'll change that in v2.

>>
>> /* Write out the complete 32-bit chunks */
>> --
>> 2.35.1
>
> Cheers,
> Moritz
>>
>

Cheers,
Marco