Skip to contentSkip to conversation

drivers/macintosh/smu.c: Mark expected switch fall-through

PATCH Applied Stephen Rothwell 5 participants 8 messages Jul 30, 2019 – Aug 2, 2019 Linux for power macintosh

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/macintosh/smu.c: Mark expected switch fall-through

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 <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
---
 drivers/macintosh/smu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/macintosh/smu.c +1 -0
index 276065c888bc..23f1f41c8602 100644
@@ -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;
Signature · 5 lines
2.22.0

-- 
Cheers,
Stephen Rothwell
#1 lore raw

Hi all,

Quoted 9 lines · On Tue, 30 Jul 2019 14:37:04 +1000 Stephen Rothwell <[email protected]>…

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;
   ~~~~~~~~~~~~~~~~~~^~~~~~~
Quoted 8 lines

drivers/macintosh/smu.c:855:2: note: here
case SMU_I2C_TRANSFER_STDSUB:
^~~~

Cc Benjamin Herrenschmidt <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
Fixes 0365ba7fb1fa ("[PATCH] ppc64: SMU driver update & i2c support")

Sorry, forgot :-)

Signature · 2 lines
Cheers,
Stephen Rothwell
#2 lore raw
In reply to Stephen Rothwell
Quoted 25 lines · Stephen Rothwell

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 <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
---
 drivers/macintosh/smu.c | 1 +
 1 file changed, 1 insertion(+)
drivers/macintosh/smu.c +0 -0
index 276065c888bc..23f1f41c8602 100644

drivers/macintosh/smu.c int smu_queue_i2c(struct smu_i2c_cmd *cmd) · line 858

Quoted 7 lines
drivers/macintosh/smu.c +1 -0
@@ -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

#3 lore raw

Hi Michael,

Quoted 3 lines · On Wed, 31 Jul 2019 00:28:55 +1000 Michael Ellerman <[email protected]> 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 ...

Signature · 2 lines
Cheers,
Stephen Rothwell
Reviewed-by
#4 lore raw
In reply to Michael Ellerman
Quoted 21 lines · Michael Ellerman
Quoted 20 lines · Stephen Rothwell

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 <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
---
 drivers/macintosh/smu.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

drivers/macintosh/smu.c int smu_queue_i2c(struct smu_i2c_cmd *cmd) · line 858

Quoted 12 lines
drivers/macintosh/smu.c +1 -0
index 276065c888bc..23f1f41c8602 100644
@@ -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;
Signature · 1 line
Kees Cook
#5 lore raw
Quoted 10 lines · Kees Cook
Quoted 4 lines

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.

#6 lore raw
In reply to Kees Cook
Quoted 64 lines · Kees Cook
Quoted 21 lines · Michael Ellerman
Quoted 20 lines · Stephen Rothwell

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 <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>
---
 drivers/macintosh/smu.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

drivers/macintosh/smu.c int smu_queue_i2c(struct smu_i2c_cmd *cmd) · line 858

Quoted 12 lines
drivers/macintosh/smu.c +1 -0
index 276065c888bc..23f1f41c8602 100644
@@ -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;
Quoted 1 line

Thanks.

cheers

#7 lore raw
In reply to Stephen Rothwell
Quoted 9 lines · Stephen Rothwell

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;
   ~~~~~~~~~~~~~~~~~~^~~~~~~
Quoted 8 lines

drivers/macintosh/smu.c:855:2: note: here
case SMU_I2C_TRANSFER_STDSUB:
^~~~

Cc Benjamin Herrenschmidt <[email protected]>
Cc Gustavo A. R. Silva <[email protected]>
Cc Kees Cook <[email protected]>

Applied to powerpc fixes, thanks.

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

cheers