From: Andre Przywara <andre.przywara@arm.com>
To: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>
Cc: Marek Vasut <marex@denx.de>, Michal Simek <michal.simek@amd.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
u-boot@lists.denx.de
Subject: [PATCH 02/18] zlib: annotate switch/case fallthrough cases
Date: Thu, 27 Mar 2025 15:32:57 +0000 [thread overview]
Message-ID: <20250327153313.2105227-3-andre.przywara@arm.com> (raw)
In-Reply-To: <20250327153313.2105227-1-andre.przywara@arm.com>
The inflate state machine in zlib uses switch/case fall-through's
extensively, as it sometimes advances the state, and lets the
conveniently placed next case statement handle the new state already.
The pattern here is:
state->mode = LEN;
case LEN:
Annotate those occasions with the "fallthrough;" macro, to let compilers
know this is fine when using -Wimplicit-fallthrough.
This mimics the upstream commit 76f70abbc73f:
Author: Mark Adler <madler@alumni.caltech.edu>
Date: Sun Mar 27 00:12:38 2022 -0700
Subject: Add fallthrough comments for gcc.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
lib/zlib/inflate.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/lib/zlib/inflate.c b/lib/zlib/inflate.c
index b4c72cc2c5c..2b7a464f74f 100644
--- a/lib/zlib/inflate.c
+++ b/lib/zlib/inflate.c
@@ -420,6 +420,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
if (state->flags & 0x0200) CRC2(state->check, hold);
INITBITS();
state->mode = TIME;
+ fallthrough;
case TIME:
NEEDBITS(32);
if (state->head != Z_NULL)
@@ -427,6 +428,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
if (state->flags & 0x0200) CRC4(state->check, hold);
INITBITS();
state->mode = OS;
+ fallthrough;
case OS:
NEEDBITS(16);
if (state->head != Z_NULL) {
@@ -436,6 +438,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
if (state->flags & 0x0200) CRC2(state->check, hold);
INITBITS();
state->mode = EXLEN;
+ fallthrough;
case EXLEN:
if (state->flags & 0x0400) {
NEEDBITS(16);
@@ -448,6 +451,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
else if (state->head != Z_NULL)
state->head->extra = Z_NULL;
state->mode = EXTRA;
+ fallthrough;
case EXTRA:
if (state->flags & 0x0400) {
copy = state->length;
@@ -471,6 +475,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
}
state->length = 0;
state->mode = NAME;
+ fallthrough;
case NAME:
if (state->flags & 0x0800) {
if (have == 0) goto inf_leave;
@@ -492,6 +497,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
state->head->name = Z_NULL;
state->length = 0;
state->mode = COMMENT;
+ fallthrough;
case COMMENT:
if (state->flags & 0x1000) {
if (have == 0) goto inf_leave;
@@ -512,6 +518,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
else if (state->head != Z_NULL)
state->head->comment = Z_NULL;
state->mode = HCRC;
+ fallthrough;
case HCRC:
if (state->flags & 0x0200) {
NEEDBITS(16);
@@ -535,6 +542,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
strm->adler = state->check = REVERSE(hold);
INITBITS();
state->mode = DICT;
+ fallthrough;
case DICT:
if (state->havedict == 0) {
RESTORE();
@@ -542,9 +550,11 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
}
strm->adler = state->check = adler32(0L, Z_NULL, 0);
state->mode = TYPE;
+ fallthrough;
case TYPE:
schedule();
if (flush == Z_BLOCK) goto inf_leave;
+ fallthrough;
case TYPEDO:
if (state->last) {
BYTEBITS();
@@ -590,6 +600,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
state->length));
INITBITS();
state->mode = COPY;
+ fallthrough;
case COPY:
copy = state->length;
if (copy) {
@@ -625,6 +636,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
Tracev((stderr, "inflate: table sizes ok\n"));
state->have = 0;
state->mode = LENLENS;
+ fallthrough;
case LENLENS:
while (state->have < state->ncode) {
NEEDBITS(3);
@@ -646,6 +658,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
Tracev((stderr, "inflate: code lengths ok\n"));
state->have = 0;
state->mode = CODELENS;
+ fallthrough;
case CODELENS:
while (state->have < state->nlen + state->ndist) {
for (;;) {
@@ -720,6 +733,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
}
Tracev((stderr, "inflate: codes ok\n"));
state->mode = LEN;
+ fallthrough;
case LEN:
schedule();
if (have >= 6 && left >= 258) {
@@ -764,6 +778,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
}
state->extra = (unsigned)(this.op) & 15;
state->mode = LENEXT;
+ fallthrough;
case LENEXT:
if (state->extra) {
NEEDBITS(state->extra);
@@ -772,6 +787,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
}
Tracevv((stderr, "inflate: length %u\n", state->length));
state->mode = DIST;
+ fallthrough;
case DIST:
for (;;) {
this = state->distcode[BITS(state->distbits)];
@@ -797,6 +813,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
state->offset = (unsigned)this.val;
state->extra = (unsigned)(this.op) & 15;
state->mode = DISTEXT;
+ fallthrough;
case DISTEXT:
if (state->extra) {
NEEDBITS(state->extra);
@@ -817,6 +834,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
}
Tracevv((stderr, "inflate: distance %u\n", state->offset));
state->mode = MATCH;
+ fallthrough;
case MATCH:
if (left == 0) goto inf_leave;
copy = out - left;
@@ -872,6 +890,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
}
#ifdef GUNZIP
state->mode = LENGTH;
+ fallthrough;
case LENGTH:
if (state->wrap && state->flags) {
NEEDBITS(32);
@@ -885,6 +904,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
}
#endif
state->mode = DONE;
+ fallthrough;
case DONE:
ret = Z_STREAM_END;
goto inf_leave;
@@ -894,6 +914,7 @@ __rcode int ZEXPORT inflate(z_streamp strm, int flush)
case MEM:
return Z_MEM_ERROR;
case SYNC:
+ fallthrough;
default:
return Z_STREAM_ERROR;
}
--
2.25.1
next prev parent reply other threads:[~2025-03-27 15:33 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-27 15:32 [PATCH 00/18] Annotate switch/case fallthrough cases Andre Przywara
2025-03-27 15:32 ` [PATCH 01/18] spl: mmc: properly annotate fallthrough Andre Przywara
2025-03-29 0:06 ` Tom Rini
2025-03-27 15:32 ` Andre Przywara [this message]
2025-03-31 16:13 ` [PATCH 02/18] zlib: annotate switch/case fallthrough cases Tom Rini
2025-03-27 15:32 ` [PATCH 03/18] gadget: f_thor: annotate switch/case fallthrough Andre Przywara
2025-03-31 8:01 ` Mattijs Korpershoek
2025-03-27 15:32 ` [PATCH 04/18] use proper fallthrough annotations Andre Przywara
2025-03-31 14:11 ` Tom Rini
2025-03-27 15:33 ` [PATCH 05/18] net/net: fix switch/case " Andre Przywara
2025-03-31 15:55 ` Tom Rini
2025-04-08 22:29 ` Tom Rini
2025-04-08 23:53 ` Andre Przywara
2025-04-09 1:46 ` Tom Rini
2025-04-09 10:41 ` Andre Przywara
2025-04-09 14:15 ` Tom Rini
2025-03-27 15:33 ` [PATCH 06/18] fastboot: annotate switch/case fallthrough case Andre Przywara
2025-03-31 8:04 ` Mattijs Korpershoek
2025-03-27 15:33 ` [PATCH 07/18] net: sun8i-emac: annotate fallthrough Andre Przywara
2025-03-27 15:33 ` [PATCH 08/18] usb: ohci-hcd: annotate switch/case fallthrough Andre Przywara
2025-03-27 15:33 ` [PATCH 09/18] usb: xhci: annotate switch/case fallthrough properly Andre Przywara
2025-03-31 15:57 ` Tom Rini
2025-03-27 15:33 ` [PATCH 10/18] video: annotate switch/case fall-through Andre Przywara
2025-03-31 16:01 ` Tom Rini
2025-03-27 15:33 ` [PATCH 11/18] net: e1000: annotate switch/case fallthrough Andre Przywara
2025-03-27 15:33 ` [PATCH 12/18] mtd: ubi: annotate fallthrough Andre Przywara
2025-03-28 5:03 ` Heiko Schocher
2025-03-27 15:33 ` [PATCH 13/18] arm: mach-k3: am62p: annotate switch/case fallthrough Andre Przywara
2025-03-31 14:11 ` Tom Rini
2025-03-27 15:33 ` [PATCH 14/18] mtd: spi-nor-tiny: " Andre Przywara
2025-03-31 16:07 ` Tom Rini
2025-03-27 15:33 ` [PATCH 15/18] mtd: rawnand: nand_base: " Andre Przywara
2025-03-28 8:26 ` Michael Nazzareno Trimarchi
2025-03-27 15:33 ` [PATCH 16/18] cmd: pmic: " Andre Przywara
2025-03-31 16:09 ` Tom Rini
2025-03-27 15:33 ` [PATCH 17/18] cmd: spl: " Andre Przywara
2025-03-31 16:09 ` Tom Rini
2025-03-27 15:33 ` [PATCH 18/18] [DO NOT MERGE] Makefile: enable switch/case fallthrough warnings Andre Przywara
2025-03-28 16:07 ` Tom Rini
2025-03-28 10:28 ` [PATCH 00/18] Annotate switch/case fallthrough cases Heinrich Schuchardt
2025-03-28 10:39 ` Andre Przywara
2025-03-28 13:45 ` Andre Przywara
2025-03-28 13:49 ` Tom Rini
2025-04-10 1:46 ` (subset) " Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250327153313.2105227-3-andre.przywara@arm.com \
--to=andre.przywara@arm.com \
--cc=ilias.apalodimas@linaro.org \
--cc=marex@denx.de \
--cc=michal.simek@amd.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox