linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through
@ 2019-07-30  4:37 Stephen Rothwell
  2019-07-30  4:45 ` Stephen Rothwell
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Stephen Rothwell @ 2019-07-30  4:37 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Michael Ellerman
  Cc: PowerPC, Gustavo A. R. Silva, Kees Cook, Linux kernel Mailing List

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

Mark switch cases where we are expecting to fall through.

This patch fixes the following warning (Building: powerpc):

drivers/macintosh/smu.c: In function 'smu_queue_i2c':
drivers/macintosh/smu.c:854:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
   cmd->info.devaddr &= 0xfe;
   ~~~~~~~~~~~~~~~~~~^~~~~~~
drivers/macintosh/smu.c:855:2: note: here
  case SMU_I2C_TRANSFER_STDSUB:
  ^~~~

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
---
 drivers/macintosh/smu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index 276065c888bc..23f1f41c8602 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -852,6 +852,7 @@ int smu_queue_i2c(struct smu_i2c_cmd *cmd)
 		break;
 	case SMU_I2C_TRANSFER_COMBINED:
 		cmd->info.devaddr &= 0xfe;
+		/* fall through */
 	case SMU_I2C_TRANSFER_STDSUB:
 		if (cmd->info.sublen > 3)
 			return -EINVAL;
-- 
2.22.0

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through
  2019-07-30  4:37 [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through Stephen Rothwell
@ 2019-07-30  4:45 ` Stephen Rothwell
  2019-07-30 14:28 ` Michael Ellerman
  2019-08-02  2:28 ` Michael Ellerman
  2 siblings, 0 replies; 8+ messages in thread
From: Stephen Rothwell @ 2019-07-30  4:45 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Michael Ellerman
  Cc: PowerPC, Gustavo A. R. Silva, Kees Cook, Linux kernel Mailing List

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

Hi all,

On Tue, 30 Jul 2019 14:37:04 +1000 Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>
> Mark switch cases where we are expecting to fall through.
> 
> This patch fixes the following warning (Building: powerpc):
> 
> drivers/macintosh/smu.c: In function 'smu_queue_i2c':
> drivers/macintosh/smu.c:854:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
>    cmd->info.devaddr &= 0xfe;
>    ~~~~~~~~~~~~~~~~~~^~~~~~~
> drivers/macintosh/smu.c:855:2: note: here
>   case SMU_I2C_TRANSFER_STDSUB:
>   ^~~~
> 
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>

Fixes: 0365ba7fb1fa ("[PATCH] ppc64: SMU driver update & i2c support")

Sorry, forgot :-)
-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through
  2019-07-30  4:37 [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through Stephen Rothwell
  2019-07-30  4:45 ` Stephen Rothwell
@ 2019-07-30 14:28 ` Michael Ellerman
  2019-07-30 14:41   ` Stephen Rothwell
  2019-07-30 17:07   ` Kees Cook
  2019-08-02  2:28 ` Michael Ellerman
  2 siblings, 2 replies; 8+ messages in thread
From: Michael Ellerman @ 2019-07-30 14:28 UTC (permalink / raw)
  To: Stephen Rothwell, Benjamin Herrenschmidt
  Cc: PowerPC, Gustavo A. R. Silva, Kees Cook, Linux kernel Mailing List

Stephen Rothwell <sfr@canb.auug.org.au> writes:
> Mark switch cases where we are expecting to fall through.
>
> This patch fixes the following warning (Building: powerpc):
>
> drivers/macintosh/smu.c: In function 'smu_queue_i2c':
> drivers/macintosh/smu.c:854:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
>    cmd->info.devaddr &= 0xfe;
>    ~~~~~~~~~~~~~~~~~~^~~~~~~
> drivers/macintosh/smu.c:855:2: note: here
>   case SMU_I2C_TRANSFER_STDSUB:
>   ^~~~
>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
> ---
>  drivers/macintosh/smu.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
> index 276065c888bc..23f1f41c8602 100644
> --- a/drivers/macintosh/smu.c
> +++ b/drivers/macintosh/smu.c
> @@ -852,6 +852,7 @@ int smu_queue_i2c(struct smu_i2c_cmd *cmd)
>  		break;
>  	case SMU_I2C_TRANSFER_COMBINED:
>  		cmd->info.devaddr &= 0xfe;
> +		/* fall through */
>  	case SMU_I2C_TRANSFER_STDSUB:
>  		if (cmd->info.sublen > 3)
>  			return -EINVAL;

Why do we think it's an expected fall through? I can't really convince
myself from the surrounding code that it's definitely intentional.

cheers

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

* Re: [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through
  2019-07-30 14:28 ` Michael Ellerman
@ 2019-07-30 14:41   ` Stephen Rothwell
  2019-07-30 17:07   ` Kees Cook
  1 sibling, 0 replies; 8+ messages in thread
From: Stephen Rothwell @ 2019-07-30 14:41 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Benjamin Herrenschmidt, PowerPC, Gustavo A. R. Silva, Kees Cook,
	Linux kernel Mailing List

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

Hi Michael,

On Wed, 31 Jul 2019 00:28:55 +1000 Michael Ellerman <mpe@ellerman.id.au> wrote:
>
> Why do we think it's an expected fall through? I can't really convince
> myself from the surrounding code that it's definitely intentional.

Its been that way since this code was introduced by commit

  0365ba7fb1fa ("[PATCH] ppc64: SMU driver update & i2c support")

in 2005 ...

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through
  2019-07-30 14:28 ` Michael Ellerman
  2019-07-30 14:41   ` Stephen Rothwell
@ 2019-07-30 17:07   ` Kees Cook
  2019-07-30 20:37     ` Benjamin Herrenschmidt
  2019-07-31 11:46     ` Michael Ellerman
  1 sibling, 2 replies; 8+ messages in thread
From: Kees Cook @ 2019-07-30 17:07 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Stephen Rothwell, Benjamin Herrenschmidt, PowerPC,
	Gustavo A. R. Silva, Linux kernel Mailing List

On Wed, Jul 31, 2019 at 12:28:55AM +1000, Michael Ellerman wrote:
> Stephen Rothwell <sfr@canb.auug.org.au> writes:
> > Mark switch cases where we are expecting to fall through.
> >
> > This patch fixes the following warning (Building: powerpc):
> >
> > drivers/macintosh/smu.c: In function 'smu_queue_i2c':
> > drivers/macintosh/smu.c:854:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
> >    cmd->info.devaddr &= 0xfe;
> >    ~~~~~~~~~~~~~~~~~~^~~~~~~
> > drivers/macintosh/smu.c:855:2: note: here
> >   case SMU_I2C_TRANSFER_STDSUB:
> >   ^~~~
> >
> > Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
> > Cc: Kees Cook <keescook@chromium.org>
> > Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > ---
> >  drivers/macintosh/smu.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
> > index 276065c888bc..23f1f41c8602 100644
> > --- a/drivers/macintosh/smu.c
> > +++ b/drivers/macintosh/smu.c
> > @@ -852,6 +852,7 @@ int smu_queue_i2c(struct smu_i2c_cmd *cmd)
> >  		break;
> >  	case SMU_I2C_TRANSFER_COMBINED:
> >  		cmd->info.devaddr &= 0xfe;
> > +		/* fall through */
> >  	case SMU_I2C_TRANSFER_STDSUB:
> >  		if (cmd->info.sublen > 3)
> >  			return -EINVAL;
> 
> Why do we think it's an expected fall through? I can't really convince
> myself from the surrounding code that it's definitely intentional.

Yeah, good question. Just now when I went looking for who
used SMU_I2C_TRANSFER_COMBINED, I found the only caller in
arch/powerpc/platforms/powermac/low_i2c.c and it is clearly using a
fall-through for building the command for "stdsub" and "combined",
so I think that's justification enough:

        switch(bus->mode) {
        case pmac_i2c_mode_std:
                if (subsize != 0)
                        return -EINVAL;
                cmd->info.type = SMU_I2C_TRANSFER_SIMPLE;
                break;
        case pmac_i2c_mode_stdsub:
        case pmac_i2c_mode_combined:
                if (subsize > 3 || subsize < 1)
                        return -EINVAL;
                cmd->info.sublen = subsize;
                /* that's big-endian only but heh ! */
                memcpy(&cmd->info.subaddr, ((char *)&subaddr) + (4 - subsize),
                       subsize);
                if (bus->mode == pmac_i2c_mode_stdsub)
                        cmd->info.type = SMU_I2C_TRANSFER_STDSUB;
                else
                        cmd->info.type = SMU_I2C_TRANSFER_COMBINED;


Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

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

* Re: [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through
  2019-07-30 17:07   ` Kees Cook
@ 2019-07-30 20:37     ` Benjamin Herrenschmidt
  2019-07-31 11:46     ` Michael Ellerman
  1 sibling, 0 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2019-07-30 20:37 UTC (permalink / raw)
  To: Kees Cook, Michael Ellerman
  Cc: Stephen Rothwell, PowerPC, Gustavo A. R. Silva,
	Linux kernel Mailing List

On Tue, 2019-07-30 at 10:07 -0700, Kees Cook wrote:
> 
> > Why do we think it's an expected fall through? I can't really
> > convince
> > myself from the surrounding code that it's definitely intentional.
> 
> Yeah, good question. Just now when I went looking for who
> used SMU_I2C_TRANSFER_COMBINED, I found the only caller in
> arch/powerpc/platforms/powermac/low_i2c.c and it is clearly using a
> fall-through for building the command for "stdsub" and "combined",
> so I think that's justification enough:

Yes, sorry for the delay, the fall through is intentional.

Cheers,
Ben.



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

* Re: [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through
  2019-07-30 17:07   ` Kees Cook
  2019-07-30 20:37     ` Benjamin Herrenschmidt
@ 2019-07-31 11:46     ` Michael Ellerman
  1 sibling, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2019-07-31 11:46 UTC (permalink / raw)
  To: Kees Cook
  Cc: Stephen Rothwell, Benjamin Herrenschmidt, PowerPC,
	Gustavo A. R. Silva, Linux kernel Mailing List

Kees Cook <keescook@chromium.org> writes:
> On Wed, Jul 31, 2019 at 12:28:55AM +1000, Michael Ellerman wrote:
>> Stephen Rothwell <sfr@canb.auug.org.au> writes:
>> > Mark switch cases where we are expecting to fall through.
>> >
>> > This patch fixes the following warning (Building: powerpc):
>> >
>> > drivers/macintosh/smu.c: In function 'smu_queue_i2c':
>> > drivers/macintosh/smu.c:854:21: warning: this statement may fall through [-Wimplicit-fallthrough=]
>> >    cmd->info.devaddr &= 0xfe;
>> >    ~~~~~~~~~~~~~~~~~~^~~~~~~
>> > drivers/macintosh/smu.c:855:2: note: here
>> >   case SMU_I2C_TRANSFER_STDSUB:
>> >   ^~~~
>> >
>> > Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>> > Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> > Cc: Kees Cook <keescook@chromium.org>
>> > Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
>> > ---
>> >  drivers/macintosh/smu.c | 1 +
>> >  1 file changed, 1 insertion(+)
>> >
>> > diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
>> > index 276065c888bc..23f1f41c8602 100644
>> > --- a/drivers/macintosh/smu.c
>> > +++ b/drivers/macintosh/smu.c
>> > @@ -852,6 +852,7 @@ int smu_queue_i2c(struct smu_i2c_cmd *cmd)
>> >  		break;
>> >  	case SMU_I2C_TRANSFER_COMBINED:
>> >  		cmd->info.devaddr &= 0xfe;
>> > +		/* fall through */
>> >  	case SMU_I2C_TRANSFER_STDSUB:
>> >  		if (cmd->info.sublen > 3)
>> >  			return -EINVAL;
>> 
>> Why do we think it's an expected fall through? I can't really convince
>> myself from the surrounding code that it's definitely intentional.
>
> Yeah, good question. Just now when I went looking for who
> used SMU_I2C_TRANSFER_COMBINED, I found the only caller in
> arch/powerpc/platforms/powermac/low_i2c.c and it is clearly using a
> fall-through for building the command for "stdsub" and "combined",
> so I think that's justification enough:
>
>         switch(bus->mode) {
>         case pmac_i2c_mode_std:
>                 if (subsize != 0)
>                         return -EINVAL;
>                 cmd->info.type = SMU_I2C_TRANSFER_SIMPLE;
>                 break;
>         case pmac_i2c_mode_stdsub:
>         case pmac_i2c_mode_combined:
>                 if (subsize > 3 || subsize < 1)
>                         return -EINVAL;
>                 cmd->info.sublen = subsize;
>                 /* that's big-endian only but heh ! */
>                 memcpy(&cmd->info.subaddr, ((char *)&subaddr) + (4 - subsize),
>                        subsize);
>                 if (bus->mode == pmac_i2c_mode_stdsub)
>                         cmd->info.type = SMU_I2C_TRANSFER_STDSUB;
>                 else
>                         cmd->info.type = SMU_I2C_TRANSFER_COMBINED;
>
>
> Reviewed-by: Kees Cook <keescook@chromium.org>

Thanks.

cheers

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

* Re: [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through
  2019-07-30  4:37 [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through Stephen Rothwell
  2019-07-30  4:45 ` Stephen Rothwell
  2019-07-30 14:28 ` Michael Ellerman
@ 2019-08-02  2:28 ` Michael Ellerman
  2 siblings, 0 replies; 8+ messages in thread
From: Michael Ellerman @ 2019-08-02  2:28 UTC (permalink / raw)
  To: Stephen Rothwell, Benjamin Herrenschmidt
  Cc: Linux kernel Mailing List, PowerPC, Kees Cook, Gustavo A. R. Silva

On Tue, 2019-07-30 at 04:37:04 UTC, Stephen Rothwell wrote:
> Mark switch cases where we are expecting to fall through.
> 
> This patch fixes the following warning (Building: powerpc):
> 
> drivers/macintosh/smu.c: In function 'smu_queue_i2c':
> drivers/macintosh/smu.c:854:21: warning: this statement may fall through [-=
> Wimplicit-fallthrough=3D]
>    cmd->info.devaddr &=3D 0xfe;
>    ~~~~~~~~~~~~~~~~~~^~~~~~~
> drivers/macintosh/smu.c:855:2: note: here
>   case SMU_I2C_TRANSFER_STDSUB:
>   ^~~~
> 
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/7440ea8b2a4430eef5120d0a7faac6c39304ae6d

cheers

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

end of thread, other threads:[~2019-08-02  2:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30  4:37 [PATCH] drivers/macintosh/smu.c: Mark expected switch fall-through Stephen Rothwell
2019-07-30  4:45 ` Stephen Rothwell
2019-07-30 14:28 ` Michael Ellerman
2019-07-30 14:41   ` Stephen Rothwell
2019-07-30 17:07   ` Kees Cook
2019-07-30 20:37     ` Benjamin Herrenschmidt
2019-07-31 11:46     ` Michael Ellerman
2019-08-02  2:28 ` Michael Ellerman

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