Skip to contentSkip to conversation

lib/siphash.c: mark expected switch fall-throughs

PATCH In review Stephen Rothwell 4 participants 5 messages Apr 16, 2019 – Apr 25, 2019 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/siphash.c: mark expected switch fall-throughs

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

This patch aims to suppress up to 18 missing-break-in-switch false positives on some architectures.

Cc Jason A. Donenfeld <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
---
 lib/siphash.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

Build tested on PowerPC.

lib/siphash.c +18 -18
index 3ae58b4edad6..c47bb6ff2149 100644
@@ -68,11 +68,11 @@ u64 __siphash_aligned(const void *data, size_t len, const siphash_key_t *key)
 						  bytemask_from_count(left)));
 #else
 	switch (left) {
-	case 7: b |= ((u64)end[6]) << 48;
-	case 6: b |= ((u64)end[5]) << 40;
-	case 5: b |= ((u64)end[4]) << 32;
+	case 7: b |= ((u64)end[6]) << 48; /* fall through */
+	case 6: b |= ((u64)end[5]) << 40; /* fall through */
+	case 5: b |= ((u64)end[4]) << 32; /* fall through */
 	case 4: b |= le32_to_cpup(data); break;
-	case 3: b |= ((u64)end[2]) << 16;
+	case 3: b |= ((u64)end[2]) << 16; /* fall through */
 	case 2: b |= le16_to_cpup(data); break;
 	case 1: b |= end[0];
 	}
@@ -101,11 +101,11 @@ u64 __siphash_unaligned(const void *data, size_t len, const siphash_key_t *key)
 						  bytemask_from_count(left)));
 #else
 	switch (left) {
-	case 7: b |= ((u64)end[6]) << 48;
-	case 6: b |= ((u64)end[5]) << 40;
-	case 5: b |= ((u64)end[4]) << 32;
+	case 7: b |= ((u64)end[6]) << 48; /* fall through */
+	case 6: b |= ((u64)end[5]) << 40; /* fall through */
+	case 5: b |= ((u64)end[4]) << 32; /* fall through */
 	case 4: b |= get_unaligned_le32(end); break;
-	case 3: b |= ((u64)end[2]) << 16;
+	case 3: b |= ((u64)end[2]) << 16; /* fall through */
 	case 2: b |= get_unaligned_le16(end); break;
 	case 1: b |= end[0];
 	}
@@ -268,11 +268,11 @@ u32 __hsiphash_aligned(const void *data, size_t len, const hsiphash_key_t *key)
 						  bytemask_from_count(left)));
 #else
 	switch (left) {
-	case 7: b |= ((u64)end[6]) << 48;
-	case 6: b |= ((u64)end[5]) << 40;
-	case 5: b |= ((u64)end[4]) << 32;
+	case 7: b |= ((u64)end[6]) << 48; /* fall through */
+	case 6: b |= ((u64)end[5]) << 40; /* fall through */
+	case 5: b |= ((u64)end[4]) << 32; /* fall through */
 	case 4: b |= le32_to_cpup(data); break;
-	case 3: b |= ((u64)end[2]) << 16;
+	case 3: b |= ((u64)end[2]) << 16; /* fall through */
 	case 2: b |= le16_to_cpup(data); break;
 	case 1: b |= end[0];
 	}
@@ -301,11 +301,11 @@ u32 __hsiphash_unaligned(const void *data, size_t len,
 						  bytemask_from_count(left)));
 #else
 	switch (left) {
-	case 7: b |= ((u64)end[6]) << 48;
-	case 6: b |= ((u64)end[5]) << 40;
-	case 5: b |= ((u64)end[4]) << 32;
+	case 7: b |= ((u64)end[6]) << 48; /* fall through */
+	case 6: b |= ((u64)end[5]) << 40; /* fall through */
+	case 5: b |= ((u64)end[4]) << 32; /* fall through */
 	case 4: b |= get_unaligned_le32(end); break;
-	case 3: b |= ((u64)end[2]) << 16;
+	case 3: b |= ((u64)end[2]) << 16; /* fall through */
 	case 2: b |= get_unaligned_le16(end); break;
 	case 1: b |= end[0];
 	}
@@ -431,7 +431,7 @@ u32 __hsiphash_aligned(const void *data, size_t len, const hsiphash_key_t *key)
 		v0 ^= m;
 	}
 	switch (left) {
-	case 3: b |= ((u32)end[2]) << 16;
+	case 3: b |= ((u32)end[2]) << 16; /* fall through */
 	case 2: b |= le16_to_cpup(data); break;
 	case 1: b |= end[0];
 	}
@@ -454,7 +454,7 @@ u32 __hsiphash_unaligned(const void *data, size_t len,
 		v0 ^= m;
 	}
 	switch (left) {
-	case 3: b |= ((u32)end[2]) << 16;
+	case 3: b |= ((u32)end[2]) << 16; /* fall through */
 	case 2: b |= get_unaligned_le16(end); break;
 	case 1: b |= end[0];
 	}
Signature · 7 lines
2.20.1



-- 
Cheers,
Stephen Rothwell
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Stephen Rothwell

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

This patch aims to suppress up to 18 missing-break-in-switch false positives on some architectures.

Cc Jason A. Donenfeld <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>

Looks good to me, thanks for this.

Perhaps Greg can take it through his tree?

#2 lore raw
Quoted 13 lines · Jason A. Donenfeld
Quoted 11 lines · Stephen Rothwell

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

This patch aims to suppress up to 18 missing-break-in-switch false positives on some architectures.

Cc Jason A. Donenfeld <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
Quoted 5 lines

Looks good to me, thanks for this.

Perhaps Greg can take it through his tree?

Me? Ok, fine, I'll go queue it up...

#3 lore raw
Quoted 14 lines · Greg Kroah-Hartman
Quoted 13 lines · Jason A. Donenfeld
Quoted 11 lines · Stephen Rothwell

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

This patch aims to suppress up to 18 missing-break-in-switch false positives on some architectures.

Cc Jason A. Donenfeld <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
Quoted 8 lines
Quoted 5 lines

Looks good to me, thanks for this.

Perhaps Greg can take it through his tree?

Me? Ok, fine, I'll go queue it up...

Thanks, Greg.
--
Gustavo

#4 lore raw
In reply to Greg Kroah-Hartman

Hi Greg,

Quoted 15 lines · On Thu, 25 Apr 2019 19:46:15 +0200 Greg Kroah-Hartman…
Quoted 13 lines · Jason A. Donenfeld
Quoted 11 lines · Stephen Rothwell

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

This patch aims to suppress up to 18 missing-break-in-switch false positives on some architectures.

Cc Jason A. Donenfeld <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
Quoted 7 lines
Quoted 5 lines

Looks good to me, thanks for this.

Perhaps Greg can take it through his tree?

Me? Ok, fine, I'll go queue it up...

Excellent, thanks.

Signature · 2 lines
Cheers,
Stephen Rothwell