linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Marcus Folkesson <marcus.folkesson@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: accel: cros_ec_accel_legacy: Mark expected switch fall-throughs
Date: Wed, 15 Aug 2018 12:50:10 -0500	[thread overview]
Message-ID: <64cccc17-ebfe-205a-6b2c-2a72aae765b0@embeddedor.com> (raw)
In-Reply-To: <20180815172700.GA29039@gmail.com>

Hi Marcus,

On 8/15/18 12:27 PM, Marcus Folkesson wrote:
> Hi,
> 
> On Wed, Aug 15, 2018 at 11:38:52AM -0500, Gustavo A. R. Silva wrote:
>> In preparation to enabling -Wimplicit-fallthrough, mark switch cases
>> where we are expecting to fall through.
>>
>> Addresses-Coverity-ID: 1462408 ("Missing break in switch")
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
>>  drivers/iio/accel/cros_ec_accel_legacy.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/iio/accel/cros_ec_accel_legacy.c b/drivers/iio/accel/cros_ec_accel_legacy.c
>> index 063e89e..d609654 100644
>> --- a/drivers/iio/accel/cros_ec_accel_legacy.c
>> +++ b/drivers/iio/accel/cros_ec_accel_legacy.c
>> @@ -385,8 +385,10 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
>>  		switch (i) {
>>  		case X:
>>  			ec_accel_channels[X].scan_index = Y;
>> +			/* fall through */
>>  		case Y:
>>  			ec_accel_channels[Y].scan_index = X;
>> +			/* fall through */
>>  		case Z:
>>  			ec_accel_channels[Z].scan_index = Z;
>>  		}
> 
> Hum, I'm not sure we are supposed to fall through here, even if it does
> not hurt to do so.

Yeah. You're right. It doesn't hurt but is actually redundant. I think
the original intention was to break instead of falling through.

> I even think we can remove the switch and put that outside the for-loop,
> e.g:
> 
> 	ec_accel_channels[X].scan_index = Y;
> 	ec_accel_channels[Y].scan_index = X;
> 	ec_accel_channels[Z].scan_index = Z;
> 
> 	for (i = X ; i < MAX_AXIS; i++) {
> 		if (state->sensor_num == MOTIONSENSE_LOC_LID && i != Y)
> 			state->sign[i] = -1;
> 		else
> 			state->sign[i] = 1;
> 	}
> 

I like this, but the code clearly depends on MAX_AXIS. So, if MAX_AXIS
will be always 3, then the change you suggest is just fine. Otherwise,
it seems that adding a break to each case is the right way to go.

What do you think?

Thanks for the feedback.
--
Gustavo

  reply	other threads:[~2018-08-15 17:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-15 16:38 [PATCH] iio: accel: cros_ec_accel_legacy: Mark expected switch fall-throughs Gustavo A. R. Silva
2018-08-15 17:27 ` Marcus Folkesson
2018-08-15 17:50   ` Gustavo A. R. Silva [this message]
2018-08-18 15:34     ` Marcus Folkesson
2018-08-19 16:20       ` Jonathan Cameron

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=64cccc17-ebfe-205a-6b2c-2a72aae765b0@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcus.folkesson@gmail.com \
    --cc=pmeerw@pmeerw.net \
    /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;
as well as URLs for NNTP newsgroup(s).