diff mbox series

hwmon: (oxp-sensors) Add missing breaks to fix -Wimplicit-fallthrough with clang

Message ID 20240828-hwmon-oxp-sensors-fix-clang-implicit-fallthrough-v1-1-dc48496ac67a@kernel.org (mailing list archive)
State Accepted
Headers show
Series hwmon: (oxp-sensors) Add missing breaks to fix -Wimplicit-fallthrough with clang | expand

Commit Message

Nathan Chancellor Aug. 28, 2024, 6:05 p.m. UTC
clang warns (or errors due to CONFIG_WERROR):

  drivers/hwmon/oxp-sensors.c:481:3: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
  drivers/hwmon/oxp-sensors.c:553:3: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
  drivers/hwmon/oxp-sensors.c:556:2: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
  drivers/hwmon/oxp-sensors.c:607:3: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]

Clang is a little more pedantic than GCC, which does not warn when
falling through to a case that is just break or return. Clang's version
is more in line with the kernel's own stance in deprecated.rst, which
states that all switch/case blocks must end in either break,
fallthrough, continue, goto, or return. Add the missing breaks to
silence the warnings.

Fixes: b82b38a49926 ("hwmon: (oxp-sensors) Add support for multiple new devices.")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/hwmon/oxp-sensors.c | 4 ++++
 1 file changed, 4 insertions(+)


---
base-commit: ebb75a3c5265ceeebd2b0708d013735e5eafbb69
change-id: 20240828-hwmon-oxp-sensors-fix-clang-implicit-fallthrough-b6e97424c46d

Best regards,

Comments

Guenter Roeck Aug. 28, 2024, 8:34 p.m. UTC | #1
On Wed, Aug 28, 2024 at 11:05:35AM -0700, Nathan Chancellor wrote:
> clang warns (or errors due to CONFIG_WERROR):
> 
>   drivers/hwmon/oxp-sensors.c:481:3: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
>   drivers/hwmon/oxp-sensors.c:553:3: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
>   drivers/hwmon/oxp-sensors.c:556:2: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
>   drivers/hwmon/oxp-sensors.c:607:3: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
> 
> Clang is a little more pedantic than GCC, which does not warn when
> falling through to a case that is just break or return. Clang's version
> is more in line with the kernel's own stance in deprecated.rst, which
> states that all switch/case blocks must end in either break,
> fallthrough, continue, goto, or return. Add the missing breaks to
> silence the warnings.
> 
> Fixes: b82b38a49926 ("hwmon: (oxp-sensors) Add support for multiple new devices.")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Applied.

Thanks,
Guenter
diff mbox series

Patch

diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
index b6d06370469d..83730d931824 100644
--- a/drivers/hwmon/oxp-sensors.c
+++ b/drivers/hwmon/oxp-sensors.c
@@ -478,6 +478,7 @@  static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 			default:
 				break;
 			}
+			break;
 		default:
 			break;
 		}
@@ -550,9 +551,11 @@  static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 			default:
 				break;
 			}
+			break;
 		default:
 			break;
 		}
+		break;
 	default:
 		break;
 	}
@@ -604,6 +607,7 @@  static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
 			default:
 				break;
 			}
+			break;
 		default:
 			break;
 		}