Re: [PATCH] staging: most: dim2: replace BUG_ON() with error handling

From: Greg KH

Date: Sun Mar 08 2026 - 14:45:25 EST


On Wed, Mar 04, 2026 at 06:01:48PM -0800, Mark Adamenko wrote:
> Replace BUG_ON() calls with error handling to avoid unnecessary kernel
> crashes.
>
> Signed-off-by: Mark Adamenko <marusik.adamenko@xxxxxxxxx>
> ---
> drivers/staging/most/dim2/dim2.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
> index 8d649d920433..cec9d19e1cde 100644
> --- a/drivers/staging/most/dim2/dim2.c
> +++ b/drivers/staging/most/dim2/dim2.c
> @@ -168,8 +168,10 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
> unsigned long flags;
> struct dim_ch_state st;
>
> - BUG_ON(!hdm_ch);
> - BUG_ON(!hdm_ch->is_initialized);
> + if (!hdm_ch)
> + return -EINVAL;

Can this ever happen? If not, why is this even checked? (hint, I do
not think it ever can)

> + if (!hdm_ch->is_initialized)
> + return -EINVAL;

Same here, are you sure this can happen? And can the caller handle an
error? At first glance, I do not think it can. So be careful with
this.

You can't just blindly replace BUG_ON() with tests, please verify if
they are needed, and if so, how to handle the error correctly.

thanks,

greg k-h