Skip to contentSkip to conversation

byteorder: fix -Wsign-compare warnings

PATCH New Jeffle Xu 1 participant 2 messages Jan 26, 2021

lore
Share & tools
lore

Jeffle Xu

author
#0 lore raw

PATCH 1/2 byteorder: fix -Wsign-compare warnings

warning: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Wsign-compare]

           for (i = 0; i < len; i++)
---
 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.27.0
author
#1 lore raw

PATCH 2/2 thread_info: fix -Wsign-compare warnings

warning: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Wsign-compare]

           if (unlikely(sz >= 0 && sz < bytes)) {
---
 include/linux/thread_info.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/thread_info.h +3 -3
index c8a974cead73..11b4b36116fa 100644
@@ -179,15 +179,15 @@ __bad_copy_from(void);
 extern void __compiletime_error("copy destination size is too small")
 __bad_copy_to(void);
 
-static inline void copy_overflow(int size, unsigned long count)
+static inline void copy_overflow(unsigned long size, unsigned long count)
 {
-	WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
+	WARN(1, "Buffer overflow detected (%lu < %lu)!\n", size, count);
 }
 
 static __always_inline __must_check bool
 check_copy_size(const void *addr, size_t bytes, bool is_source)
 {
-	int sz = __compiletime_object_size(addr);
+	size_t sz = __compiletime_object_size(addr);
 	if (unlikely(sz >= 0 && sz < bytes)) {
 		if (!__builtin_constant_p(bytes))
 			copy_overflow(sz, bytes);
Signature · 1 line
2.27.0