Skip to contentSkip to conversation

fpga: altera-pr-ip: fix unsigned comparison with less than zero

PATCH Superseded Marco Pagani 4 participants 5 messages Apr 6, 2022 – Apr 22, 2022 FPGA manager framework

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/fpga/altera-pr-ip-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/altera-pr-ip-core.c +1 -1
index be0667968d33..2ff3d8e46a0c 100644
@@ -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 */
Signature · 1 line
2.35.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Marco Pagani

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.

---
  drivers/fpga/altera-pr-ip-core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/altera-pr-ip-core.c +0 -0
index be0667968d33..2ff3d8e46a0c 100644

drivers/fpga/altera-pr-ip-core.c static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf, · line 112

Quoted 6 lines
drivers/fpga/altera-pr-ip-core.c +1 -1
@@ -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;
Quoted 2 lines
drivers/fpga/altera-pr-ip-core.c +0 -0
  	/* Write out the complete 32-bit chunks */
maintainer Acked-by
#2 lore raw
Quoted 11 lines · Tom Rix
Quoted 9 lines · Marco Pagani

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.

---
  drivers/fpga/altera-pr-ip-core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

drivers/fpga/altera-pr-ip-core.c static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf, · line 111

Quoted 10 lines
drivers/fpga/altera-pr-ip-core.c +1 -1
index be0667968d33..2ff3d8e46a0c 100644
@@ -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;
Quoted 2 lines
Quoted 2 lines
drivers/fpga/altera-pr-ip-core.c +0 -0
  	/* Write out the complete 32-bit chunks */
maintainer
#3 lore raw
In reply to Marco Pagani

Marco,

Quoted 4 lines · Marco Pagani

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?

Quoted 10 lines
---
 drivers/fpga/altera-pr-ip-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/altera-pr-ip-core.c +0 -0
index be0667968d33..2ff3d8e46a0c 100644

drivers/fpga/altera-pr-ip-core.c static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf, · line 112

Quoted 6 lines
drivers/fpga/altera-pr-ip-core.c +1 -1
@@ -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?

Quoted 4 lines
drivers/fpga/altera-pr-ip-core.c +0 -0
 	/* Write out the complete 32-bit chunks */
Signature · 1 line
2.35.1

Cheers,
Moritz

Quoted 1 line
#4 lore raw
Quoted 8 lines · Moritz Fischer

Marco,

Quoted 4 lines · Marco Pagani

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?

Quoted 13 lines
Quoted 13 lines
---
 drivers/fpga/altera-pr-ip-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fpga/altera-pr-ip-core.c +0 -0
index be0667968d33..2ff3d8e46a0c 100644
@@ -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;
 
Quoted 6 lines

drivers/fpga/altera-pr-ip-core.c static int alt_pr_fpga_write(struct fpga_manager *mgr, const char *buf, · line 112

Quoted 3 lines
drivers/fpga/altera-pr-ip-core.c +1 -1
-	if (count <= 0)
+	if (count == 0)
 		return -EINVAL;

if (!count)
return -EINVAL?

Ok, I'll change that in v2.

Quoted 9 lines
Quoted 4 lines
drivers/fpga/altera-pr-ip-core.c +0 -0
 	/* Write out the complete 32-bit chunks */
Signature · 1 line
2.35.1

Cheers,
Moritz

Quoted 1 line

Cheers,
Marco