Re: [PATCH] iio: core: Avoid BUG() on invalid clock types

From: Jonathan Cameron

Date: Sun Aug 23 2026 - 18:48:39 EST


On Sun, 23 Aug 2026 22:25:02 +0000
Rishab Madhugiri <rishab.madhugiri@xxxxxxxxx> 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@xxxxxxxxx>
> ---
> 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]);