Skip to contentSkip to conversation

arm64: csum: cast to the proper type

PATCH Applied Alex Elder 3 participants 3 messages Mar 15, 2021 arm64

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

PATCH 1/1 arm64: csum: cast to the proper type

The last line of ip_fast_csum() calls csum_fold(), forcing the type of the argument passed to be u32. But csum_fold() takes a __wsum argument (which is __u32 __bitwise for arm64). As long as we're forcing the cast, cast it to the right type.

---

With this patch in place, quite a few "different base types" sparse warnings go away on a full arm64 kernel build. More specifically:
warning: incorrect type in argument 1 (different base types)
expected restricted __wsum [usertype] csum
got unsigned int [usertype]

-Alex

 arch/arm64/include/asm/checksum.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/checksum.h +1 -1
index 93a161b3bf3fe..dc52b733675db 100644
@@ -37,7 +37,7 @@ static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
 	} while (--n > 0);
 
 	sum += ((sum >> 32) | (sum << 32));
-	return csum_fold((__force u32)(sum >> 32));
+	return csum_fold((__force __wsum)(sum >> 32));
 }
 #define ip_fast_csum ip_fast_csum
 
Signature · 1 line
2.27.0
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Alex Elder

The last line of ip_fast_csum() calls csum_fold(), forcing the type of the argument passed to be u32. But csum_fold() takes a __wsum argument (which is __u32 __bitwise for arm64). As long as we're forcing the cast, cast it to the right type.

Oddly, the commit adding the cast does specifically speak about converting to __wsum, so I'm not sure what happened there... :/

Anyway, this seems to make sense.

Quoted 28 lines

---

With this patch in place, quite a few "different base types" sparse warnings go away on a full arm64 kernel build. More specifically:
warning: incorrect type in argument 1 (different base types)
expected restricted __wsum [usertype] csum
got unsigned int [usertype]

-Alex

  arch/arm64/include/asm/checksum.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/checksum.h +1 -1
index 93a161b3bf3fe..dc52b733675db 100644
@@ -37,7 +37,7 @@ static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
  	} while (--n > 0);
 
  	sum += ((sum >> 32) | (sum << 32));
-	return csum_fold((__force u32)(sum >> 32));
+	return csum_fold((__force __wsum)(sum >> 32));
  }
  #define ip_fast_csum ip_fast_csum
 
maintainer Applied
#2 lore raw
In reply to Alex Elder
Quoted 4 lines · Alex Elder

The last line of ip_fast_csum() calls csum_fold(), forcing the type of the argument passed to be u32. But csum_fold() takes a __wsum argument (which is __u32 __bitwise for arm64). As long as we're forcing the cast, cast it to the right type.

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: csum: cast to the proper type

      https://git.kernel.org/arm64/c/0710442a88d1

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev