lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <503af4a57ca6daeb3e42a9be136dcd21e6d6e23d.camel@perches.com>
Date:   Sat, 17 Oct 2020 12:00:01 -0700
From:   Joe Perches <joe@...ches.com>
To:     Julia Lawall <julia.lawall@...ia.fr>
Cc:     trix@...hat.com, linux-kernel@...r.kernel.org,
        cocci <cocci@...teme.lip6.fr>, alsa-devel@...a-project.org,
        clang-built-linux@...glegroups.com, linux-iio@...r.kernel.org,
        nouveau@...ts.freedesktop.org, storagedev@...rochip.com,
        dri-devel@...ts.freedesktop.org,
        virtualization@...ts.linux-foundation.org,
        keyrings@...r.kernel.org, linux-mtd@...ts.infradead.org,
        ath10k@...ts.infradead.org,
        linux-stm32@...md-mailman.stormreply.com,
        usb-storage@...ts.one-eyed-alien.net,
        linux-watchdog@...r.kernel.org, devel@...verdev.osuosl.org,
        linux-samsung-soc@...r.kernel.org, linux-scsi@...r.kernel.org,
        linux-nvdimm@...ts.01.org, amd-gfx@...ts.freedesktop.org,
        linux-acpi@...r.kernel.org, intel-wired-lan@...ts.osuosl.org,
        industrypack-devel@...ts.sourceforge.net,
        linux-pci@...r.kernel.org, spice-devel@...ts.freedesktop.org,
        MPT-FusionLinux.pdl@...adcom.com, linux-media@...r.kernel.org,
        linux-serial@...r.kernel.org, linux-nfc@...ts.01.org,
        linux-pm@...r.kernel.org, linux-can@...r.kernel.org,
        linux-block@...r.kernel.org, linux-gpio@...r.kernel.org,
        xen-devel@...ts.xenproject.org, linux-amlogic@...ts.infradead.org,
        openipmi-developer@...ts.sourceforge.net,
        platform-driver-x86@...r.kernel.org,
        linux-integrity@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org, linux-edac@...r.kernel.org,
        netdev@...r.kernel.org, linux-usb@...r.kernel.org,
        linux-wireless@...r.kernel.org,
        linux-security-module@...r.kernel.org,
        linux-crypto@...r.kernel.org, patches@...nsource.cirrus.com,
        bpf@...r.kernel.org, ocfs2-devel@....oracle.com,
        linux-power@...rohmeurope.com
Subject: Re: [Cocci] [RFC] treewide: cleanup unreachable breaks

On Sat, 2020-10-17 at 20:21 +0200, Julia Lawall wrote:
> On Sat, 17 Oct 2020, Joe Perches wrote:
> > On Sat, 2020-10-17 at 09:09 -0700, trix@...hat.com wrote:
> > > From: Tom Rix <trix@...hat.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.
> > 
> > Early acks/individual patches by subsystem would be good.
> > Better still would be an automated cocci script.
> 
> Coccinelle is not especially good at this, because it is based on control
> flow, and a return or goto diverts the control flow away from the break.
> A hack to solve the problem is to put an if around the return or goto, but
> that gives the break a meaningless file name and line number.  I collected
> the following list, but it only has 439 results, so fewer than clang.  But
> maybe there are some files that are not considered by clang in the x86
> allyesconfig configuration.
> 
> Probably checkpatch is the best solution here, since it is not
> configuration sensitive and doesn't care about control flow.

Likely the clang compiler is the best option here.

It might be useful to add -Wunreachable-code-break to W=1
or just always enable it if it isn't already enabled.

diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 95e4cdb94fe9..3819787579d5 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -32,6 +32,7 @@ KBUILD_CFLAGS += $(call cc-option, -Wunused-but-set-variable)
 KBUILD_CFLAGS += $(call cc-option, -Wunused-const-variable)
 KBUILD_CFLAGS += $(call cc-option, -Wpacked-not-aligned)
 KBUILD_CFLAGS += $(call cc-option, -Wstringop-truncation)
+KBUILD_CFLAGS += $(call cc-option, -Wunreachable-code-break)
 # The following turn off the warnings enabled by -Wextra
 KBUILD_CFLAGS += -Wno-missing-field-initializers
 KBUILD_CFLAGS += -Wno-sign-compare

(and thank you Tom for pushing this forward)

checkpatch can't find instances like:

	case FOO:
		if (foo)
			return 1;
		else
			return 2;
		break;

As it doesn't track flow and relies on the number
of tabs to be the same for any goto/return and break;

checkpatch will warn on:

	case FOO:
		...
		goto bar;
		break;


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ