linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: accel: cros_ec_accel_legacy: Mark expected switch fall-throughs
@ 2018-08-15 16:38 Gustavo A. R. Silva
  2018-08-15 17:27 ` Marcus Folkesson
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2018-08-15 16:38 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler
  Cc: linux-iio, linux-kernel, Gustavo A. R. Silva

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;
 		}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: accel: cros_ec_accel_legacy: Mark expected switch fall-throughs
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Marcus Folkesson @ 2018-08-15 17:27 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1511 bytes --]

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.
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;
	}


Best regards,
Marcus Folkesson


> -- 
> 2.7.4
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: accel: cros_ec_accel_legacy: Mark expected switch fall-throughs
  2018-08-15 17:27 ` Marcus Folkesson
@ 2018-08-15 17:50   ` Gustavo A. R. Silva
  2018-08-18 15:34     ` Marcus Folkesson
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2018-08-15 17:50 UTC (permalink / raw)
  To: Marcus Folkesson
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: accel: cros_ec_accel_legacy: Mark expected switch fall-throughs
  2018-08-15 17:50   ` Gustavo A. R. Silva
@ 2018-08-18 15:34     ` Marcus Folkesson
  2018-08-19 16:20       ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Marcus Folkesson @ 2018-08-18 15:34 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2903 bytes --]

Hi Gutavo,

Sorry for the delay.

On Wed, Aug 15, 2018 at 12:50:10PM -0500, Gustavo A. R. Silva wrote:
> 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?

Well, I guess it is a matter of taste after all.
I don't think the number of axis will change, but just put the break in
place is good enough.

Anyway, If we choose to not use the switch, I think we should remove the
for-loop as well, eg:

	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] = -1;
		state->sign[Y] = 1;
		state->sign[Z] = -1;
	} else {
		state->sign[X] = 1;
		state->sign[Y] = 1;
		state->sign[Z] = 1;
	}

But someone else may like to give their point of view on this change.

> 
> Thanks for the feedback.
> --
> Gustavo

Best regards
Marcus Folkesson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] iio: accel: cros_ec_accel_legacy: Mark expected switch fall-throughs
  2018-08-18 15:34     ` Marcus Folkesson
@ 2018-08-19 16:20       ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2018-08-19 16:20 UTC (permalink / raw)
  To: Marcus Folkesson
  Cc: Gustavo A. R. Silva, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Sat, 18 Aug 2018 17:34:40 +0200
Marcus Folkesson <marcus.folkesson@gmail.com> wrote:

> Hi Gutavo,
> 
> Sorry for the delay.
> 
> On Wed, Aug 15, 2018 at 12:50:10PM -0500, Gustavo A. R. Silva wrote:
> > 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?  
> 
> Well, I guess it is a matter of taste after all.
> I don't think the number of axis will change, but just put the break in
> place is good enough.
> 
> Anyway, If we choose to not use the switch, I think we should remove the
> for-loop as well, eg:
> 
> 	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] = -1;
> 		state->sign[Y] = 1;
> 		state->sign[Z] = -1;
> 	} else {
> 		state->sign[X] = 1;
> 		state->sign[Y] = 1;
> 		state->sign[Z] = 1;
> 	}
> 
> But someone else may like to give their point of view on this change.

Looks like the right tidy up to me.  The original code was 'novel' :)

Jonathan
> 
> > 
> > Thanks for the feedback.
> > --
> > Gustavo  
> 
> Best regards
> Marcus Folkesson


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-19 16:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2018-08-18 15:34     ` Marcus Folkesson
2018-08-19 16:20       ` Jonathan Cameron

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).