Skip to contentSkip to conversation

byteorder: fix warning due to type mismatch in be32 array code

PATCH In review Ben Dooks (Codethink) 2 participants 2 messages Nov 4, 2019 – Nov 15, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 byteorder: fix warning due to type mismatch in be32 array code

The loop should use a "size_t" as the len parameter is a size_t which should silence the following warning:

./include/linux/byteorder/generic.h:195:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘unsigned int’} [-Wsign-compare] ./include/linux/byteorder/generic.h:203:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘unsigned int’} [-Wsign-compare]

---
Cc: [email protected]

---
 include/linux/byteorder/generic.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/byteorder/generic.h +2 -2
index 4b13e0a3e15b..c9a4c96c9943 100644
@@ -190,7 +190,7 @@ static inline void be64_add_cpu(__be64 *var, u64 val)
 
 static inline void cpu_to_be32_array(__be32 *dst, const u32 *src, size_t len)
 {
-	int i;
+	size_t i;
 
 	for (i = 0; i < len; i++)
 		dst[i] = cpu_to_be32(src[i]);
@@ -198,7 +198,7 @@ static inline void cpu_to_be32_array(__be32 *dst, const u32 *src, size_t len)
 
 static inline void be32_to_cpu_array(u32 *dst, const __be32 *src, size_t len)
 {
-	int i;
+	size_t i;
 
 	for (i = 0; i < len; i++)
 		dst[i] = be32_to_cpu(src[i]);
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Ben,

CC Arnd.

Quoted 7 lines · Ben Dooks (Codethink)

The loop should use a "size_t" as the len parameter is a size_t which should silence the following warning:

./include/linux/byteorder/generic.h:195:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘unsigned int’} [-Wsign-compare] ./include/linux/byteorder/generic.h:203:16: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘unsigned int’} [-Wsign-compare]

Thanks for your patch!

include/linux/byteorder/generic.h static inline void be64_add_cpu(__be64 *var, u64 val) · line 196

Quoted 11 lines
include/linux/byteorder/generic.h +1 -1
@@ -190,7 +190,7 @@ static inline void be64_add_cpu(__be64 *var, u64 val)
 
 static inline void cpu_to_be32_array(__be32 *dst, const u32 *src, size_t len)
 {
-       int i;
+       size_t i;
 
        for (i = 0; i < len; i++)
                dst[i] = cpu_to_be32(src[i]);

Alternatively, you can follow the approach a few lines above:

        while (len--)
                *dst++ = cpu_to_be32(*src++);

Regardless:

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds