* [PATCH] iio: core: Avoid BUG() on invalid clock types
@ 2026-08-23 22:25 Rishab Madhugiri
2026-08-23 22:48 ` Jonathan Cameron
2026-08-24 9:55 ` Andy Shevchenko
0 siblings, 2 replies; 8+ messages in thread
From: Rishab Madhugiri @ 2026-08-23 22:25 UTC (permalink / raw)
To: jic23; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel,
Rishab Madhugiri
Replace deprecated use of BUG() in default switch cases of
iio_get_time_ns() and current_timestamp_clock_show() with
WARN_ONCE() and return correct fallback or error codes.
Signed-off-by: Rishab Madhugiri <rishab.madhugiri@gmail.com>
---
drivers/iio/industrialio-core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 767a7794624a..c0411a29fe3f 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -341,7 +341,8 @@ s64 iio_get_time_ns(const struct iio_dev *indio_dev)
case CLOCK_TAI:
return ktime_get_clocktai_ns();
default:
- BUG();
+ WARN_ONCE(1, "Invalid clock type selected for IIO device\n");
+ return 0;
}
}
EXPORT_SYMBOL(iio_get_time_ns);
@@ -1518,7 +1519,8 @@ static ssize_t current_timestamp_clock_show(struct device *dev,
case CLOCK_TAI:
break;
default:
- BUG();
+ WARN_ONCE(1, "Invalid clock type selected for IIO device\n");
+ return -EINVAL;
}
return sysfs_emit(buf, "%s\n", clock_names[clk]);
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid BUG() on invalid clock types
2026-08-23 22:25 [PATCH] iio: core: Avoid BUG() on invalid clock types Rishab Madhugiri
@ 2026-08-23 22:48 ` Jonathan Cameron
2026-08-24 9:55 ` Andy Shevchenko
1 sibling, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2026-08-23 22:48 UTC (permalink / raw)
To: Rishab Madhugiri; +Cc: dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Sun, 23 Aug 2026 22:25:02 +0000
Rishab Madhugiri <rishab.madhugiri@gmail.com> wrote:
> Replace deprecated use of BUG() in default switch cases of
> iio_get_time_ns() and current_timestamp_clock_show() with
> WARN_ONCE() and return correct fallback or error codes.
This is there just to stop compilers moaning that we didn't handle
all the possible values in the switch statement. We can't actually
hit the BUG() unless we have a very unexpected bug or random memory
corruption.
So sure, lets move to the new way of handling these paths.
However, they aren't supposed to be possible. So
WARN_ON_ONCE() and no message is fine for these.
Jonathan
>
> Signed-off-by: Rishab Madhugiri <rishab.madhugiri@gmail.com>
> ---
> drivers/iio/industrialio-core.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 767a7794624a..c0411a29fe3f 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -341,7 +341,8 @@ s64 iio_get_time_ns(const struct iio_dev *indio_dev)
> case CLOCK_TAI:
> return ktime_get_clocktai_ns();
> default:
> - BUG();
> + WARN_ONCE(1, "Invalid clock type selected for IIO device\n");
> + return 0;
> }
> }
> EXPORT_SYMBOL(iio_get_time_ns);
> @@ -1518,7 +1519,8 @@ static ssize_t current_timestamp_clock_show(struct device *dev,
> case CLOCK_TAI:
> break;
> default:
> - BUG();
> + WARN_ONCE(1, "Invalid clock type selected for IIO device\n");
> + return -EINVAL;
> }
>
> return sysfs_emit(buf, "%s\n", clock_names[clk]);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid BUG() on invalid clock types
2026-08-23 22:25 [PATCH] iio: core: Avoid BUG() on invalid clock types Rishab Madhugiri
2026-08-23 22:48 ` Jonathan Cameron
@ 2026-08-24 9:55 ` Andy Shevchenko
2026-08-24 10:05 ` Joshua Crofts
1 sibling, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-08-24 9:55 UTC (permalink / raw)
To: Rishab Madhugiri; +Cc: jic23, dlechner, nuno.sa, andy, linux-iio, linux-kernel
On Sun, Aug 23, 2026 at 10:25:02PM +0000, Rishab Madhugiri wrote:
> Replace deprecated use of BUG() in default switch cases of
> iio_get_time_ns() and current_timestamp_clock_show() with
> WARN_ONCE() and return correct fallback or error codes.
Why?!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid BUG() on invalid clock types
2026-08-24 9:55 ` Andy Shevchenko
@ 2026-08-24 10:05 ` Joshua Crofts
2026-08-24 14:48 ` Andy Shevchenko
0 siblings, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-08-24 10:05 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Rishab Madhugiri, jic23, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
On Mon, 24 Aug 2026 12:55:47 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Sun, Aug 23, 2026 at 10:25:02PM +0000, Rishab Madhugiri wrote:
> > Replace deprecated use of BUG() in default switch cases of
> > iio_get_time_ns() and current_timestamp_clock_show() with
> > WARN_ONCE() and return correct fallback or error codes.
>
> Why?!
>
Because BUG() and BUG_ON() shouldn't be used anymore, no? Linus himself
said that he hates the macros.
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid BUG() on invalid clock types
2026-08-24 10:05 ` Joshua Crofts
@ 2026-08-24 14:48 ` Andy Shevchenko
2026-08-24 15:06 ` Joshua Crofts
0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-08-24 14:48 UTC (permalink / raw)
To: Joshua Crofts
Cc: Rishab Madhugiri, jic23, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
On Mon, Aug 24, 2026 at 12:05:03PM +0200, Joshua Crofts wrote:
> On Mon, 24 Aug 2026 12:55:47 +0300
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
>
> > On Sun, Aug 23, 2026 at 10:25:02PM +0000, Rishab Madhugiri wrote:
> > > Replace deprecated use of BUG() in default switch cases of
> > > iio_get_time_ns() and current_timestamp_clock_show() with
> > > WARN_ONCE() and return correct fallback or error codes.
> >
> > Why?!
>
> Because BUG() and BUG_ON() shouldn't be used anymore, no? Linus himself
> said that he hates the macros.
Why? Please, study the case. As for the above change, there are two questions
(at least):
- Why BUG() is deprecated? Where is it stated?
- What will WARN*() gain us here? (Note some specific kernel command line
parameter that may convert WARN to BUG)
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid BUG() on invalid clock types
2026-08-24 14:48 ` Andy Shevchenko
@ 2026-08-24 15:06 ` Joshua Crofts
2026-08-24 15:25 ` Andy Shevchenko
0 siblings, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-08-24 15:06 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Rishab Madhugiri, jic23, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
On Mon, 24 Aug 2026 at 16:48, Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Mon, Aug 24, 2026 at 12:05:03PM +0200, Joshua Crofts wrote:
> > On Mon, 24 Aug 2026 12:55:47 +0300
> > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> >
> > > On Sun, Aug 23, 2026 at 10:25:02PM +0000, Rishab Madhugiri wrote:
> > > > Replace deprecated use of BUG() in default switch cases of
> > > > iio_get_time_ns() and current_timestamp_clock_show() with
> > > > WARN_ONCE() and return correct fallback or error codes.
> > >
> > > Why?!
> >
> > Because BUG() and BUG_ON() shouldn't be used anymore, no? Linus himself
> > said that he hates the macros.
>
> Why? Please, study the case. As for the above change, there are two questions
> (at least):
> - Why BUG() is deprecated? Where is it stated?
https://docs.kernel.org/process/deprecated.html?hl=en-GB#bug-and-bug-on
> - What will WARN*() gain us here? (Note some specific kernel command line
> parameter that may convert WARN to BUG)
As Jonathan mentioned earlier, the original BUG() was there to prevent the
compiler from complaining that all possible values weren't handled. So BUG()
or WARN*() here is a placeholder. Just removing the BUG() call should be
valid since it's impossible to hit(?)
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid BUG() on invalid clock types
2026-08-24 15:06 ` Joshua Crofts
@ 2026-08-24 15:25 ` Andy Shevchenko
2026-08-25 23:48 ` Rishab M
0 siblings, 1 reply; 8+ messages in thread
From: Andy Shevchenko @ 2026-08-24 15:25 UTC (permalink / raw)
To: Joshua Crofts
Cc: Rishab Madhugiri, jic23, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
On Mon, Aug 24, 2026 at 05:06:24PM +0200, Joshua Crofts wrote:
> On Mon, 24 Aug 2026 at 16:48, Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> > On Mon, Aug 24, 2026 at 12:05:03PM +0200, Joshua Crofts wrote:
> > > On Mon, 24 Aug 2026 12:55:47 +0300
> > > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > > > On Sun, Aug 23, 2026 at 10:25:02PM +0000, Rishab Madhugiri wrote:
> > > > > Replace deprecated use of BUG() in default switch cases of
> > > > > iio_get_time_ns() and current_timestamp_clock_show() with
> > > > > WARN_ONCE() and return correct fallback or error codes.
> > > >
> > > > Why?!
> > >
> > > Because BUG() and BUG_ON() shouldn't be used anymore, no? Linus himself
> > > said that he hates the macros.
> >
> > Why? Please, study the case. As for the above change, there are two questions
> > (at least):
> > - Why BUG() is deprecated? Where is it stated?
>
> https://docs.kernel.org/process/deprecated.html?hl=en-GB#bug-and-bug-on
Thanks for sharing! So, this is a missing point in the commit message.
> > - What will WARN*() gain us here? (Note some specific kernel command line
> > parameter that may convert WARN to BUG)
>
> As Jonathan mentioned earlier, the original BUG() was there to prevent the
> compiler from complaining that all possible values weren't handled. So BUG()
> or WARN*() here is a placeholder. Just removing the BUG() call should be
> valid since it's impossible to hit(?)
Yeah, I was participated in several cases where the compiler made something
strange when BUG() was absent (basically no reachable point which BUG()
represents). Do we have no issues (anymore?) with the compiler with WARN*()?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] iio: core: Avoid BUG() on invalid clock types
2026-08-24 15:25 ` Andy Shevchenko
@ 2026-08-25 23:48 ` Rishab M
0 siblings, 0 replies; 8+ messages in thread
From: Rishab M @ 2026-08-25 23:48 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Joshua Crofts, jic23, dlechner, nuno.sa, andy, linux-iio,
linux-kernel
Hi Jonathan, Andy, and Joshua,
Thank you for the feedback and for sharing the documentation reference.
I will incorporate the reference to the documentation in the v2 commit
message and update the default cases to use WARN_ON_ONCE(1) as
Jonathan suggested.
I will send the v2 patch shortly.
Best regards,
Rishab
On Mon, Aug 24, 2026 at 8:25 AM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Mon, Aug 24, 2026 at 05:06:24PM +0200, Joshua Crofts wrote:
> > On Mon, 24 Aug 2026 at 16:48, Andy Shevchenko
> > <andriy.shevchenko@intel.com> wrote:
> > > On Mon, Aug 24, 2026 at 12:05:03PM +0200, Joshua Crofts wrote:
> > > > On Mon, 24 Aug 2026 12:55:47 +0300
> > > > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > > > > On Sun, Aug 23, 2026 at 10:25:02PM +0000, Rishab Madhugiri wrote:
> > > > > > Replace deprecated use of BUG() in default switch cases of
> > > > > > iio_get_time_ns() and current_timestamp_clock_show() with
> > > > > > WARN_ONCE() and return correct fallback or error codes.
> > > > >
> > > > > Why?!
> > > >
> > > > Because BUG() and BUG_ON() shouldn't be used anymore, no? Linus himself
> > > > said that he hates the macros.
> > >
> > > Why? Please, study the case. As for the above change, there are two questions
> > > (at least):
> > > - Why BUG() is deprecated? Where is it stated?
> >
> > https://docs.kernel.org/process/deprecated.html?hl=en-GB#bug-and-bug-on
>
> Thanks for sharing! So, this is a missing point in the commit message.
>
> > > - What will WARN*() gain us here? (Note some specific kernel command line
> > > parameter that may convert WARN to BUG)
> >
> > As Jonathan mentioned earlier, the original BUG() was there to prevent the
> > compiler from complaining that all possible values weren't handled. So BUG()
> > or WARN*() here is a placeholder. Just removing the BUG() call should be
> > valid since it's impossible to hit(?)
>
> Yeah, I was participated in several cases where the compiler made something
> strange when BUG() was absent (basically no reachable point which BUG()
> represents). Do we have no issues (anymore?) with the compiler with WARN*()?
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-08-25 23:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-23 22:25 [PATCH] iio: core: Avoid BUG() on invalid clock types Rishab Madhugiri
2026-08-23 22:48 ` Jonathan Cameron
2026-08-24 9:55 ` Andy Shevchenko
2026-08-24 10:05 ` Joshua Crofts
2026-08-24 14:48 ` Andy Shevchenko
2026-08-24 15:06 ` Joshua Crofts
2026-08-24 15:25 ` Andy Shevchenko
2026-08-25 23:48 ` Rishab M
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox