Thread (19 messages) 19 messages, 11 authors, 2020-10-20

Re: [RFC] treewide: cleanup unreachable breaks

From: Dan Williams <hidden>
Date: 2020-10-17 21:01:41
Also in: alsa-devel, amd-gfx, bpf, dri-devel, intel-wired-lan, keyrings, linux-acpi, linux-amlogic, linux-arm-kernel, linux-block, linux-can, linux-crypto, linux-edac, linux-gpio, linux-iio, linux-integrity, linux-media, linux-pci, linux-pm, linux-samsung-soc, linux-scsi, linux-serial, linux-usb, linux-watchdog, linux-wireless, lkml, netdev, nouveau, nvdimm, ocfs2-devel, platform-driver-x86, virtualization, xen-devel

On Sat, Oct 17, 2020 at 9:10 AM [off-list ref] wrote:
From: Tom Rix <trix@redhat.com>

This is a upcoming change to clean up a new warning treewide.
I am wondering if the change could be one mega patch (see below) or
normal patch per file about 100 patches or somewhere half way by collecting
early acks.

clang has a number of useful, new warnings see
https://clang.llvm.org/docs/DiagnosticsReference.html

This change cleans up -Wunreachable-code-break
https://clang.llvm.org/docs/DiagnosticsReference.html#wunreachable-code-break
for 266 of 485 warnings in this week's linux-next, allyesconfig on x86_64.

The method of fixing was to look for warnings where the preceding statement
was a simple statement and by inspection made the subsequent break unneeded.
In order of frequency these look like

return and break

        switch (c->x86_vendor) {
        case X86_VENDOR_INTEL:
                intel_p5_mcheck_init(c);
                return 1;
-               break;

goto and break

        default:
                operation = 0; /* make gcc happy */
                goto fail_response;
-               break;

break and break
                case COLOR_SPACE_SRGB:
                        /* by pass */
                        REG_SET(OUTPUT_CSC_CONTROL, 0,
                                OUTPUT_CSC_GRPH_MODE, 0);
                        break;
-                       break;

The exception to the simple statement, is a switch case with a block
and the end of block is a return

                        struct obj_buffer *buff = r->ptr;
                        return scnprintf(str, PRIV_STR_SIZE,
                                        "size=%u\naddr=0x%X\n", buff->size,
                                        buff->addr);
                }
-               break;

Not considered obvious and excluded, breaks after
multi level switches
complicated if-else if-else blocks
panic() or similar calls

And there is an odd addition of a 'fallthrough' in drivers/tty/nozomi.c
[..]
quoted hunk ↗ jump to hunk
diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c
index 5a7c80053c62..2f250874b1a4 100644
--- a/drivers/nvdimm/claim.c
+++ b/drivers/nvdimm/claim.c
@@ -200,11 +200,10 @@ ssize_t nd_namespace_store(struct device *dev,
                }
                break;
        default:
                len = -EBUSY;
                goto out_attach;
-               break;
        }
Acked-by: Dan Williams <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help