Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib: Revert use of fallthrough pseudo-keyword in lib/

The following build error for powerpc64 was reported by Nathan Chancellor:

"$ scripts/config --file arch/powerpc/configs/powernv_defconfig -e KERNEL_XZ

$ make -skj"$(nproc)" ARCH=powerpc CROSS_COMPILE=powerpc64le-linux- distclean powernv_defconfig zImage
...
In file included from arch/powerpc/boot/../../../lib/decompress_unxz.c:234,
from arch/powerpc/boot/decompress.c:38:
arch/powerpc/boot/../../../lib/xz/xz_dec_stream.c: In function 'dec_main':
arch/powerpc/boot/../../../lib/xz/xz_dec_stream.c:586:4: error: 'fallthrough' undeclared (first use in this function)
586 | fallthrough;
| ^~~~~~~~~~~

This will end up affecting distribution configurations such as Debian
and OpenSUSE according to my testing. I am not sure what the solution
is, the PowerPC wrapper does not set -D__KERNEL__ so I am not sure
that compiler_attributes.h can be safely included."

In order to avoid these sort of problems, it seems that the best
solution is to use /* fall through */ comments instead of the
fallthrough pseudo-keyword macro in lib/, for now.

Reported-by: Nathan Chancellor <natechancellor@gmail.com>
Fixes: df561f6688fe ("treewide: Use fallthrough pseudo-keyword")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-and-tested-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Gustavo A. R. Silva and committed by
Linus Torvalds
6a9dc5fd 9907ab37

+64 -64
+2 -2
lib/asn1_decoder.c
··· 381 381 case ASN1_OP_END_SET_ACT: 382 382 if (unlikely(!(flags & FLAG_MATCHED))) 383 383 goto tag_mismatch; 384 - fallthrough; 384 + /* fall through */ 385 385 386 386 case ASN1_OP_END_SEQ: 387 387 case ASN1_OP_END_SET_OF: ··· 448 448 pc += asn1_op_lengths[op]; 449 449 goto next_op; 450 450 } 451 - fallthrough; 451 + /* fall through */ 452 452 453 453 case ASN1_OP_ACT: 454 454 ret = actions[machine[pc + 1]](context, hdr, tag, data + tdp, len);
+1 -1
lib/assoc_array.c
··· 1113 1113 index_key)) 1114 1114 goto found_leaf; 1115 1115 } 1116 - fallthrough; 1116 + /* fall through */ 1117 1117 case assoc_array_walk_tree_empty: 1118 1118 case assoc_array_walk_found_wrong_shortcut: 1119 1119 default:
+2 -2
lib/bootconfig.c
··· 817 817 q - 2); 818 818 break; 819 819 } 820 - fallthrough; 820 + /* fall through */ 821 821 case '=': 822 822 ret = xbc_parse_kv(&p, q, c); 823 823 break; ··· 826 826 break; 827 827 case '#': 828 828 q = skip_comment(q); 829 - fallthrough; 829 + /* fall through */ 830 830 case ';': 831 831 case '\n': 832 832 ret = xbc_parse_key(&p, q);
+5 -5
lib/cmdline.c
··· 132 132 case 'E': 133 133 case 'e': 134 134 ret <<= 10; 135 - fallthrough; 135 + /* fall through */ 136 136 case 'P': 137 137 case 'p': 138 138 ret <<= 10; 139 - fallthrough; 139 + /* fall through */ 140 140 case 'T': 141 141 case 't': 142 142 ret <<= 10; 143 - fallthrough; 143 + /* fall through */ 144 144 case 'G': 145 145 case 'g': 146 146 ret <<= 10; 147 - fallthrough; 147 + /* fall through */ 148 148 case 'M': 149 149 case 'm': 150 150 ret <<= 10; 151 - fallthrough; 151 + /* fall through */ 152 152 case 'K': 153 153 case 'k': 154 154 ret <<= 10;
+1 -1
lib/dim/net_dim.c
··· 233 233 schedule_work(&dim->work); 234 234 break; 235 235 } 236 - fallthrough; 236 + /* fall through */ 237 237 case DIM_START_MEASURE: 238 238 dim_update_sample(end_sample.event_ctr, end_sample.pkt_ctr, 239 239 end_sample.byte_ctr, &dim->start_sample);
+2 -2
lib/dim/rdma_dim.c
··· 59 59 break; 60 60 case DIM_STATS_WORSE: 61 61 dim_turn(dim); 62 - fallthrough; 62 + /* fall through */ 63 63 case DIM_STATS_BETTER: 64 64 step_res = rdma_dim_step(dim); 65 65 if (step_res == DIM_ON_EDGE) ··· 94 94 schedule_work(&dim->work); 95 95 break; 96 96 } 97 - fallthrough; 97 + /* fall through */ 98 98 case DIM_START_MEASURE: 99 99 dim->state = DIM_MEASURE_IN_PROGRESS; 100 100 dim_update_sample_with_comps(curr_sample->event_ctr, 0, 0,
+1 -1
lib/glob.c
··· 102 102 break; 103 103 case '\\': 104 104 d = *pat++; 105 - fallthrough; 105 + /* fall through */ 106 106 default: /* Literal character */ 107 107 literal: 108 108 if (c == d) {
+18 -18
lib/siphash.c
··· 68 68 bytemask_from_count(left))); 69 69 #else 70 70 switch (left) { 71 - case 7: b |= ((u64)end[6]) << 48; fallthrough; 72 - case 6: b |= ((u64)end[5]) << 40; fallthrough; 73 - case 5: b |= ((u64)end[4]) << 32; fallthrough; 71 + case 7: b |= ((u64)end[6]) << 48; /* fall through */ 72 + case 6: b |= ((u64)end[5]) << 40; /* fall through */ 73 + case 5: b |= ((u64)end[4]) << 32; /* fall through */ 74 74 case 4: b |= le32_to_cpup(data); break; 75 - case 3: b |= ((u64)end[2]) << 16; fallthrough; 75 + case 3: b |= ((u64)end[2]) << 16; /* fall through */ 76 76 case 2: b |= le16_to_cpup(data); break; 77 77 case 1: b |= end[0]; 78 78 } ··· 101 101 bytemask_from_count(left))); 102 102 #else 103 103 switch (left) { 104 - case 7: b |= ((u64)end[6]) << 48; fallthrough; 105 - case 6: b |= ((u64)end[5]) << 40; fallthrough; 106 - case 5: b |= ((u64)end[4]) << 32; fallthrough; 104 + case 7: b |= ((u64)end[6]) << 48; /* fall through */ 105 + case 6: b |= ((u64)end[5]) << 40; /* fall through */ 106 + case 5: b |= ((u64)end[4]) << 32; /* fall through */ 107 107 case 4: b |= get_unaligned_le32(end); break; 108 - case 3: b |= ((u64)end[2]) << 16; fallthrough; 108 + case 3: b |= ((u64)end[2]) << 16; /* fall through */ 109 109 case 2: b |= get_unaligned_le16(end); break; 110 110 case 1: b |= end[0]; 111 111 } ··· 268 268 bytemask_from_count(left))); 269 269 #else 270 270 switch (left) { 271 - case 7: b |= ((u64)end[6]) << 48; fallthrough; 272 - case 6: b |= ((u64)end[5]) << 40; fallthrough; 273 - case 5: b |= ((u64)end[4]) << 32; fallthrough; 271 + case 7: b |= ((u64)end[6]) << 48; /* fall through */ 272 + case 6: b |= ((u64)end[5]) << 40; /* fall through */ 273 + case 5: b |= ((u64)end[4]) << 32; /* fall through */ 274 274 case 4: b |= le32_to_cpup(data); break; 275 - case 3: b |= ((u64)end[2]) << 16; fallthrough; 275 + case 3: b |= ((u64)end[2]) << 16; /* fall through */ 276 276 case 2: b |= le16_to_cpup(data); break; 277 277 case 1: b |= end[0]; 278 278 } ··· 301 301 bytemask_from_count(left))); 302 302 #else 303 303 switch (left) { 304 - case 7: b |= ((u64)end[6]) << 48; fallthrough; 305 - case 6: b |= ((u64)end[5]) << 40; fallthrough; 306 - case 5: b |= ((u64)end[4]) << 32; fallthrough; 304 + case 7: b |= ((u64)end[6]) << 48; /* fall through */ 305 + case 6: b |= ((u64)end[5]) << 40; /* fall through */ 306 + case 5: b |= ((u64)end[4]) << 32; /* fall through */ 307 307 case 4: b |= get_unaligned_le32(end); break; 308 - case 3: b |= ((u64)end[2]) << 16; fallthrough; 308 + case 3: b |= ((u64)end[2]) << 16; /* fall through */ 309 309 case 2: b |= get_unaligned_le16(end); break; 310 310 case 1: b |= end[0]; 311 311 } ··· 431 431 v0 ^= m; 432 432 } 433 433 switch (left) { 434 - case 3: b |= ((u32)end[2]) << 16; fallthrough; 434 + case 3: b |= ((u32)end[2]) << 16; /* fall through */ 435 435 case 2: b |= le16_to_cpup(data); break; 436 436 case 1: b |= end[0]; 437 437 } ··· 454 454 v0 ^= m; 455 455 } 456 456 switch (left) { 457 - case 3: b |= ((u32)end[2]) << 16; fallthrough; 457 + case 3: b |= ((u32)end[2]) << 16; /* fall through */ 458 458 case 2: b |= get_unaligned_le16(end); break; 459 459 case 1: b |= end[0]; 460 460 }
+1 -1
lib/ts_fsm.c
··· 193 193 TOKEN_MISMATCH(); 194 194 195 195 block_idx++; 196 - fallthrough; 196 + /* fall through */ 197 197 198 198 case TS_FSM_ANY: 199 199 if (next == NULL)
+7 -7
lib/vsprintf.c
··· 1265 1265 1266 1266 case 'R': 1267 1267 reversed = true; 1268 - fallthrough; 1268 + /* fall through */ 1269 1269 1270 1270 default: 1271 1271 separator = ':'; ··· 1682 1682 switch (*(++fmt)) { 1683 1683 case 'L': 1684 1684 uc = true; 1685 - fallthrough; 1685 + /* fall through */ 1686 1686 case 'l': 1687 1687 index = guid_index; 1688 1688 break; ··· 2219 2219 case 'S': 2220 2220 case 's': 2221 2221 ptr = dereference_symbol_descriptor(ptr); 2222 - fallthrough; 2222 + /* fall through */ 2223 2223 case 'B': 2224 2224 return symbol_string(buf, end, ptr, spec, fmt); 2225 2225 case 'R': ··· 2450 2450 2451 2451 case 'x': 2452 2452 spec->flags |= SMALL; 2453 - fallthrough; 2453 + /* fall through */ 2454 2454 2455 2455 case 'X': 2456 2456 spec->base = 16; ··· 2468 2468 * utility, treat it as any other invalid or 2469 2469 * unsupported format specifier. 2470 2470 */ 2471 - fallthrough; 2471 + /* fall through */ 2472 2472 2473 2473 default: 2474 2474 WARN_ONCE(1, "Please remove unsupported %%%c in format string\n", *fmt); ··· 3411 3411 break; 3412 3412 case 'i': 3413 3413 base = 0; 3414 - fallthrough; 3414 + /* fall through */ 3415 3415 case 'd': 3416 3416 is_sign = true; 3417 - fallthrough; 3417 + /* fall through */ 3418 3418 case 'u': 3419 3419 break; 3420 3420 case '%':
+2 -2
lib/xz/xz_dec_lzma2.c
··· 1043 1043 1044 1044 s->lzma2.sequence = SEQ_LZMA_PREPARE; 1045 1045 1046 - fallthrough; 1046 + /* fall through */ 1047 1047 1048 1048 case SEQ_LZMA_PREPARE: 1049 1049 if (s->lzma2.compressed < RC_INIT_BYTES) ··· 1055 1055 s->lzma2.compressed -= RC_INIT_BYTES; 1056 1056 s->lzma2.sequence = SEQ_LZMA_RUN; 1057 1057 1058 - fallthrough; 1058 + /* fall through */ 1059 1059 1060 1060 case SEQ_LZMA_RUN: 1061 1061 /*
+8 -8
lib/xz/xz_dec_stream.c
··· 583 583 if (ret != XZ_OK) 584 584 return ret; 585 585 586 - fallthrough; 586 + /* fall through */ 587 587 588 588 case SEQ_BLOCK_START: 589 589 /* We need one byte of input to continue. */ ··· 608 608 s->temp.pos = 0; 609 609 s->sequence = SEQ_BLOCK_HEADER; 610 610 611 - fallthrough; 611 + /* fall through */ 612 612 613 613 case SEQ_BLOCK_HEADER: 614 614 if (!fill_temp(s, b)) ··· 620 620 621 621 s->sequence = SEQ_BLOCK_UNCOMPRESS; 622 622 623 - fallthrough; 623 + /* fall through */ 624 624 625 625 case SEQ_BLOCK_UNCOMPRESS: 626 626 ret = dec_block(s, b); ··· 629 629 630 630 s->sequence = SEQ_BLOCK_PADDING; 631 631 632 - fallthrough; 632 + /* fall through */ 633 633 634 634 case SEQ_BLOCK_PADDING: 635 635 /* ··· 651 651 652 652 s->sequence = SEQ_BLOCK_CHECK; 653 653 654 - fallthrough; 654 + /* fall through */ 655 655 656 656 case SEQ_BLOCK_CHECK: 657 657 if (s->check_type == XZ_CHECK_CRC32) { ··· 675 675 676 676 s->sequence = SEQ_INDEX_PADDING; 677 677 678 - fallthrough; 678 + /* fall through */ 679 679 680 680 case SEQ_INDEX_PADDING: 681 681 while ((s->index.size + (b->in_pos - s->in_start)) ··· 699 699 700 700 s->sequence = SEQ_INDEX_CRC32; 701 701 702 - fallthrough; 702 + /* fall through */ 703 703 704 704 case SEQ_INDEX_CRC32: 705 705 ret = crc32_validate(s, b); ··· 709 709 s->temp.size = STREAM_HEADER_SIZE; 710 710 s->sequence = SEQ_STREAM_FOOTER; 711 711 712 - fallthrough; 712 + /* fall through */ 713 713 714 714 case SEQ_STREAM_FOOTER: 715 715 if (!fill_temp(s, b))
+5 -5
lib/zstd/bitstream.h
··· 259 259 bitD->bitContainer = *(const BYTE *)(bitD->start); 260 260 switch (srcSize) { 261 261 case 7: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[6]) << (sizeof(bitD->bitContainer) * 8 - 16); 262 - fallthrough; 262 + /* fall through */ 263 263 case 6: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[5]) << (sizeof(bitD->bitContainer) * 8 - 24); 264 - fallthrough; 264 + /* fall through */ 265 265 case 5: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[4]) << (sizeof(bitD->bitContainer) * 8 - 32); 266 - fallthrough; 266 + /* fall through */ 267 267 case 4: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[3]) << 24; 268 - fallthrough; 268 + /* fall through */ 269 269 case 3: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[2]) << 16; 270 - fallthrough; 270 + /* fall through */ 271 271 case 2: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[1]) << 8; 272 272 default:; 273 273 }
+1 -1
lib/zstd/compress.c
··· 3182 3182 zcs->outBuffFlushedSize = 0; 3183 3183 zcs->stage = zcss_flush; /* pass-through to flush stage */ 3184 3184 } 3185 - fallthrough; 3185 + /* fall through */ 3186 3186 3187 3187 case zcss_flush: { 3188 3188 size_t const toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize;
+6 -6
lib/zstd/decompress.c
··· 442 442 case set_repeat: 443 443 if (dctx->litEntropy == 0) 444 444 return ERROR(dictionary_corrupted); 445 - fallthrough; 445 + /* fall through */ 446 446 case set_compressed: 447 447 if (srcSize < 5) 448 448 return ERROR(corruption_detected); /* srcSize >= MIN_CBLOCK_SIZE == 3; here we need up to 5 for case 3 */ ··· 1768 1768 return 0; 1769 1769 } 1770 1770 dctx->expected = 0; /* not necessary to copy more */ 1771 - fallthrough; 1771 + /* fall through */ 1772 1772 1773 1773 case ZSTDds_decodeFrameHeader: 1774 1774 memcpy(dctx->headerBuffer + ZSTD_frameHeaderSize_prefix, src, dctx->expected); ··· 2309 2309 switch (zds->stage) { 2310 2310 case zdss_init: 2311 2311 ZSTD_resetDStream(zds); /* transparent reset on starting decoding a new frame */ 2312 - fallthrough; 2312 + /* fall through */ 2313 2313 2314 2314 case zdss_loadHeader: { 2315 2315 size_t const hSize = ZSTD_getFrameParams(&zds->fParams, zds->headerBuffer, zds->lhSize); ··· 2376 2376 } 2377 2377 zds->stage = zdss_read; 2378 2378 } 2379 - fallthrough; 2379 + /* fall through */ 2380 2380 2381 2381 case zdss_read: { 2382 2382 size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds->dctx); ··· 2405 2405 zds->stage = zdss_load; 2406 2406 /* pass-through */ 2407 2407 } 2408 - fallthrough; 2408 + /* fall through */ 2409 2409 2410 2410 case zdss_load: { 2411 2411 size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds->dctx); ··· 2438 2438 /* pass-through */ 2439 2439 } 2440 2440 } 2441 - fallthrough; 2441 + /* fall through */ 2442 2442 2443 2443 case zdss_flush: { 2444 2444 size_t const toFlushSize = zds->outEnd - zds->outStart;
+2 -2
lib/zstd/huf_compress.c
··· 556 556 n = srcSize & ~3; /* join to mod 4 */ 557 557 switch (srcSize & 3) { 558 558 case 3: HUF_encodeSymbol(&bitC, ip[n + 2], CTable); HUF_FLUSHBITS_2(&bitC); 559 - fallthrough; 559 + /* fall through */ 560 560 case 2: HUF_encodeSymbol(&bitC, ip[n + 1], CTable); HUF_FLUSHBITS_1(&bitC); 561 - fallthrough; 561 + /* fall through */ 562 562 case 1: HUF_encodeSymbol(&bitC, ip[n + 0], CTable); HUF_FLUSHBITS(&bitC); 563 563 case 0: 564 564 default:;