public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org,
	Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH] scsi: aic94xx: Fix fall-through warning for Clang
Date: Thu, 01 Jul 2021 09:40:56 -0700	[thread overview]
Message-ID: <6ddc71efad6cd45e45991028a7656eab203df12d.camel@perches.com> (raw)
In-Reply-To: <20210701010433.GA57746@embeddedor>

On Wed, 2021-06-30 at 20:04 -0500, Gustavo A. R. Silva wrote:
> In preparation to enable -Wimplicit-fallthrough for Clang, fix a
> warning by explicitly adding a fallthrough; statement.
> 
> Notice that this seems to be a Duff device for performance[1]. So,
> although the code looks a bit _funny_, I didn't want to refactor
> or modify it beyond merely adding a fallthrough marking, which
> might be the least disruptive way to fix this issue.

If you read the surrounding calling code, it appears it's
not performant.

 * @start has to be the _base_ element start, since the
 * linked list entries's offset is from this pointer.
 * Some linked list entries use only the first id, in which case
 * you can pass 0xFF for the second.

> diff --git a/drivers/scsi/aic94xx/aic94xx_sds.c b/drivers/scsi/aic94xx/aic94xx_sds.c
[]
> @@ -718,10 +718,12 @@ static void *asd_find_ll_by_id(void * const start, const u8 id0, const u8 id1)
>  	do {
>  		switch (id1) {
>  		default:
> -			if (el->id1 == id1)
> +			if (el->id1 == id1) {
> +			fallthrough;
>  		case 0xFF:
>  				if (el->id0 == id0)
>  					return el;
> +			}
>  		}
>  		el = start + le16_to_cpu(el->next);
>  	} while (el != start);

And this is still horrible code to read.

I think the below is rather more sensible and it doesn't change
the defconfig with aic94xx object size.

$ size drivers/scsi/aic94xx/aic94xx_sds.o*
   text	   data	    bss	    dec	    hex	filename
  10010	    192	      0	  10202	   27da	drivers/scsi/aic94xx/aic94xx_sds.o.new
  10010	    192	      0	  10202	   27da	drivers/scsi/aic94xx/aic94xx_sds.o.old
---
 drivers/scsi/aic94xx/aic94xx_sds.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/aic94xx/aic94xx_sds.c b/drivers/scsi/aic94xx/aic94xx_sds.c
index 297a66770260c..069278f6d6cea 100644
--- a/drivers/scsi/aic94xx/aic94xx_sds.c
+++ b/drivers/scsi/aic94xx/aic94xx_sds.c
@@ -717,11 +717,14 @@ static void *asd_find_ll_by_id(void * const start, const u8 id0, const u8 id1)
 
 	do {
 		switch (id1) {
-		default:
-			if (el->id1 == id1)
 		case 0xFF:
-				if (el->id0 == id0)
-					return el;
+			if (el->id0 == id0)
+				return el;
+			break;
+		default:
+			if (el->id0 == id0 && el->id1 == id1)
+				return el;
+			break;
 		}
 		el = start + le16_to_cpu(el->next);
 	} while (el != start);


      reply	other threads:[~2021-07-01 16:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-01  1:04 [PATCH] scsi: aic94xx: Fix fall-through warning for Clang Gustavo A. R. Silva
2021-07-01 16:40 ` Joe Perches [this message]

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=6ddc71efad6cd45e45991028a7656eab203df12d.camel@perches.com \
    --to=joe@perches.com \
    --cc=gustavoars@kernel.org \
    --cc=jejb@linux.ibm.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /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