* [PATCH v2] iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin()
@ 2026-03-10 3:45 Josh Poimboeuf
2026-03-10 11:36 ` Andy Shevchenko
2026-03-10 14:57 ` Nuno Sá
0 siblings, 2 replies; 5+ messages in thread
From: Josh Poimboeuf @ 2026-03-10 3:45 UTC (permalink / raw)
To: linux-iio
Cc: linux-kernel, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Peter Zijlstra, Nathan Chancellor,
Arnd Bergmann
If 'pin' is not one of its expected values, the value of
'int_out_ctrl_shift' is undefined. With UBSAN enabled, this causes
Clang to generate undefined behavior, resulting in the following
warning:
drivers/iio/imu/bmi160/bmi160_core.o: warning: objtool: bmi160_setup_irq() falls through to next function __cfi_bmi160_core_runtime_resume()
Prevent the UB and improve error handling by returning an error if 'pin'
has an unexpected value.
While at it, simplify the code a bit by moving the 'pin_name' assignment
to the first switch statement.
Fixes: 895bf81e6bbf ("iio:bmi160: add drdy interrupt support")
Reported-by: Arnd Bergmann <arnd@arndb.de>
Closes: https://lore.kernel.org/a426d669-58bb-4be1-9eaa-6f3d83109e2d@app.fastmail.com
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
drivers/iio/imu/bmi160/bmi160_core.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
index 5f47708b4c5d..4abb83b75e2e 100644
--- a/drivers/iio/imu/bmi160/bmi160_core.c
+++ b/drivers/iio/imu/bmi160/bmi160_core.c
@@ -573,12 +573,16 @@ static int bmi160_config_pin(struct regmap *regmap, enum bmi160_int_pin pin,
int_out_ctrl_shift = BMI160_INT1_OUT_CTRL_SHIFT;
int_latch_mask = BMI160_INT1_LATCH_MASK;
int_map_mask = BMI160_INT1_MAP_DRDY_EN;
+ pin_name = "INT1";
break;
case BMI160_PIN_INT2:
int_out_ctrl_shift = BMI160_INT2_OUT_CTRL_SHIFT;
int_latch_mask = BMI160_INT2_LATCH_MASK;
int_map_mask = BMI160_INT2_MAP_DRDY_EN;
+ pin_name = "INT2";
break;
+ default:
+ return -EINVAL;
}
int_out_ctrl_mask = BMI160_INT_OUT_CTRL_MASK << int_out_ctrl_shift;
@@ -612,17 +616,8 @@ static int bmi160_config_pin(struct regmap *regmap, enum bmi160_int_pin pin,
ret = bmi160_write_conf_reg(regmap, BMI160_REG_INT_MAP,
int_map_mask, int_map_mask,
write_usleep);
- if (ret) {
- switch (pin) {
- case BMI160_PIN_INT1:
- pin_name = "INT1";
- break;
- case BMI160_PIN_INT2:
- pin_name = "INT2";
- break;
- }
+ if (ret)
dev_err(dev, "Failed to configure %s IRQ pin", pin_name);
- }
return ret;
}
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin()
2026-03-10 3:45 [PATCH v2] iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin() Josh Poimboeuf
@ 2026-03-10 11:36 ` Andy Shevchenko
2026-03-10 16:29 ` Josh Poimboeuf
2026-03-10 14:57 ` Nuno Sá
1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-03-10 11:36 UTC (permalink / raw)
To: Josh Poimboeuf
Cc: linux-iio, linux-kernel, Jonathan Cameron, David Lechner,
Nuno Sá,
Andy Shevchenko, Peter Zijlstra, Nathan Chancellor,
Arnd Bergmann
On Mon, Mar 09, 2026 at 08:45:45PM -0700, Josh Poimboeuf wrote:
> If 'pin' is not one of its expected values, the value of
> 'int_out_ctrl_shift' is undefined. With UBSAN enabled, this causes
> Clang to generate undefined behavior, resulting in the following
> warning:
>
> drivers/iio/imu/bmi160/bmi160_core.o: warning: objtool: bmi160_setup_irq() falls through to next function __cfi_bmi160_core_runtime_resume()
>
> Prevent the UB and improve error handling by returning an error if 'pin'
> has an unexpected value.
>
> While at it, simplify the code a bit by moving the 'pin_name' assignment
> to the first switch statement.
Thanks!
Are you aware of this: https://bugzilla.kernel.org/show_bug.cgi?id=219192?
Perhaps also needs to be addressed? (I haven't checked if it's already done
or not.)
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin()
2026-03-10 11:36 ` Andy Shevchenko
@ 2026-03-10 16:29 ` Josh Poimboeuf
0 siblings, 0 replies; 5+ messages in thread
From: Josh Poimboeuf @ 2026-03-10 16:29 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-iio, linux-kernel, Jonathan Cameron, David Lechner,
Nuno Sá,
Andy Shevchenko, Peter Zijlstra, Nathan Chancellor,
Arnd Bergmann
On Tue, Mar 10, 2026 at 01:36:16PM +0200, Andy Shevchenko wrote:
> On Mon, Mar 09, 2026 at 08:45:45PM -0700, Josh Poimboeuf wrote:
> > If 'pin' is not one of its expected values, the value of
> > 'int_out_ctrl_shift' is undefined. With UBSAN enabled, this causes
> > Clang to generate undefined behavior, resulting in the following
> > warning:
> >
> > drivers/iio/imu/bmi160/bmi160_core.o: warning: objtool: bmi160_setup_irq() falls through to next function __cfi_bmi160_core_runtime_resume()
> >
> > Prevent the UB and improve error handling by returning an error if 'pin'
> > has an unexpected value.
> >
> > While at it, simplify the code a bit by moving the 'pin_name' assignment
> > to the first switch statement.
>
> Thanks!
> Are you aware of this: https://bugzilla.kernel.org/show_bug.cgi?id=219192?
> Perhaps also needs to be addressed? (I haven't checked if it's already done
> or not.)
I'll be out the rest of this week, but I'll take a look when I get back.
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Thanks!
--
Josh
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin()
2026-03-10 3:45 [PATCH v2] iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin() Josh Poimboeuf
2026-03-10 11:36 ` Andy Shevchenko
@ 2026-03-10 14:57 ` Nuno Sá
2026-03-15 12:22 ` Jonathan Cameron
1 sibling, 1 reply; 5+ messages in thread
From: Nuno Sá @ 2026-03-10 14:57 UTC (permalink / raw)
To: Josh Poimboeuf, linux-iio
Cc: linux-kernel, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, Peter Zijlstra, Nathan Chancellor,
Arnd Bergmann
On Mon, 2026-03-09 at 20:45 -0700, Josh Poimboeuf wrote:
> If 'pin' is not one of its expected values, the value of
> 'int_out_ctrl_shift' is undefined. With UBSAN enabled, this causes
> Clang to generate undefined behavior, resulting in the following
> warning:
>
> drivers/iio/imu/bmi160/bmi160_core.o: warning: objtool: bmi160_setup_irq() falls through to next
> function __cfi_bmi160_core_runtime_resume()
>
> Prevent the UB and improve error handling by returning an error if 'pin'
> has an unexpected value.
>
> While at it, simplify the code a bit by moving the 'pin_name' assignment
> to the first switch statement.
>
> Fixes: 895bf81e6bbf ("iio:bmi160: add drdy interrupt support")
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Closes: https://lore.kernel.org/a426d669-58bb-4be1-9eaa-6f3d83109e2d@app.fastmail.com
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
> drivers/iio/imu/bmi160/bmi160_core.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
> index 5f47708b4c5d..4abb83b75e2e 100644
> --- a/drivers/iio/imu/bmi160/bmi160_core.c
> +++ b/drivers/iio/imu/bmi160/bmi160_core.c
> @@ -573,12 +573,16 @@ static int bmi160_config_pin(struct regmap *regmap, enum bmi160_int_pin pin,
> int_out_ctrl_shift = BMI160_INT1_OUT_CTRL_SHIFT;
> int_latch_mask = BMI160_INT1_LATCH_MASK;
> int_map_mask = BMI160_INT1_MAP_DRDY_EN;
> + pin_name = "INT1";
> break;
> case BMI160_PIN_INT2:
> int_out_ctrl_shift = BMI160_INT2_OUT_CTRL_SHIFT;
> int_latch_mask = BMI160_INT2_LATCH_MASK;
> int_map_mask = BMI160_INT2_MAP_DRDY_EN;
> + pin_name = "INT2";
> break;
> + default:
> + return -EINVAL;
> }
> int_out_ctrl_mask = BMI160_INT_OUT_CTRL_MASK << int_out_ctrl_shift;
>
> @@ -612,17 +616,8 @@ static int bmi160_config_pin(struct regmap *regmap, enum bmi160_int_pin pin,
> ret = bmi160_write_conf_reg(regmap, BMI160_REG_INT_MAP,
> int_map_mask, int_map_mask,
> write_usleep);
> - if (ret) {
> - switch (pin) {
> - case BMI160_PIN_INT1:
> - pin_name = "INT1";
> - break;
> - case BMI160_PIN_INT2:
> - pin_name = "INT2";
> - break;
> - }
> + if (ret)
> dev_err(dev, "Failed to configure %s IRQ pin", pin_name);
> - }
>
> return ret;
> }
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin()
2026-03-10 14:57 ` Nuno Sá
@ 2026-03-15 12:22 ` Jonathan Cameron
0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2026-03-15 12:22 UTC (permalink / raw)
To: Nuno Sá
Cc: Josh Poimboeuf, linux-iio, linux-kernel, David Lechner,
Nuno Sá,
Andy Shevchenko, Peter Zijlstra, Nathan Chancellor,
Arnd Bergmann
On Tue, 10 Mar 2026 14:57:19 +0000
Nuno Sá <noname.nuno@gmail.com> wrote:
> On Mon, 2026-03-09 at 20:45 -0700, Josh Poimboeuf wrote:
> > If 'pin' is not one of its expected values, the value of
> > 'int_out_ctrl_shift' is undefined. With UBSAN enabled, this causes
> > Clang to generate undefined behavior, resulting in the following
> > warning:
> >
> > drivers/iio/imu/bmi160/bmi160_core.o: warning: objtool: bmi160_setup_irq() falls through to next
> > function __cfi_bmi160_core_runtime_resume()
> >
> > Prevent the UB and improve error handling by returning an error if 'pin'
> > has an unexpected value.
> >
> > While at it, simplify the code a bit by moving the 'pin_name' assignment
> > to the first switch statement.
> >
> > Fixes: 895bf81e6bbf ("iio:bmi160: add drdy interrupt support")
> > Reported-by: Arnd Bergmann <arnd@arndb.de>
> > Closes: https://lore.kernel.org/a426d669-58bb-4be1-9eaa-6f3d83109e2d@app.fastmail.com
> > Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> > ---
>
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-15 12:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-10 3:45 [PATCH v2] iio: imu: bmi160: Remove potential undefined behavior in bmi160_config_pin() Josh Poimboeuf
2026-03-10 11:36 ` Andy Shevchenko
2026-03-10 16:29 ` Josh Poimboeuf
2026-03-10 14:57 ` Nuno Sá
2026-03-15 12:22 ` Jonathan Cameron
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®