mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Jonathan Cameron <jic23@kernel.org>, Kees Cook <keescook@chromium.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	Gwendal Grignou <gwendal@chromium.org>
Subject: Re: [PATCH] iio: cros_ec_accel_legacy: Mark expected switch fall-throughs
Date: Wed, 20 Feb 2019 12:47:08 -0600	[thread overview]
Message-ID: <89471d5e-fab7-9d00-8b3e-562a5a510fa6@embeddedor.com> (raw)
In-Reply-To: <20190220183425.202d4d40@archlinux>



On 2/20/19 12:34 PM, Jonathan Cameron wrote:
> On Wed, 20 Feb 2019 10:20:39 -0800
> Kees Cook <keescook@chromium.org> wrote:
> 
>> On Mon, Oct 8, 2018 at 10:24 AM Gustavo A. R. Silva
>> <gustavo@embeddedor.com> wrote:
>>>
>>> In preparation to enabling -Wimplicit-fallthrough, mark switch cases
>>> where we are expecting to fall through.
>>>
>>> Addresses-Coverity-ID: 1397962 ("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;
>>>                 }  
>>
>> Shouldn't these actually be "break;"s ? It seems like the loop is
>> stepping through X, Y, and Z. The _result_ is accidentally the same:
>>
>> X: set X, Y, and Z
>> Y: set Y and Z
>> Z: set Z
>>
>> result: X, Y, and Z are set correctly. But the code is technically wrong.
>>

Yeah. Actually, we can even take the switch and for out of the equation,
and the code can be rewritten as follows:

ec_accel_channels[X].scan_index = Y;
ec_accel_channels[Y].scan_index = X;
ec_accel_channels[Z].scan_index = Z;

if (state->sensor_num == MOTIONSENSE_LOC_LID)
	state->sign[X] = state->sign[Z] = -1;
else
	state->sign[X] = state->sign[Y] = state->sign[Z] = 1;

> 
> Agreed, it's 'novel'.  Waiting for Gwendal or someone else to come
> back and check it wasn't meant to be doing something else.
> 

We've been waiting 5 months for Gwendal. :/

Thanks
--
Gustavo

  reply	other threads:[~2019-02-20 18:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-08 17:23 Gustavo A. R. Silva
2018-10-08 20:30 ` Jonathan Cameron
2019-02-12 21:50   ` Gustavo A. R. Silva
2019-02-20 18:20 ` Kees Cook
2019-02-20 18:34   ` Jonathan Cameron
2019-02-20 18:47     ` Gustavo A. R. Silva [this message]
2019-02-21  1:23       ` Kees Cook
2019-02-21  1:48         ` Gustavo A. R. Silva

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=89471d5e-fab7-9d00-8b3e-562a5a510fa6@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=gwendal@chromium.org \
    --cc=jic23@kernel.org \
    --cc=keescook@chromium.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®