[PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()

grondon@gmail.com posted 5 patches 1 day, 15 hours ago
[PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
Posted by grondon@gmail.com 1 day, 15 hours ago
From: Gabriel Rondon <grondon@gmail.com>

Replace BUG_ON() calls with an early return since the function returns
void.

BUG_ON() is deprecated as it crashes the entire kernel on assertion
failure (see Documentation/process/deprecated.rst).

Signed-off-by: Gabriel Rondon <grondon@gmail.com>
---
 drivers/staging/most/dim2/dim2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index 48315f8cd..b820c3647 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -271,8 +271,8 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
 	unsigned long flags;
 	u8 *data;
 
-	BUG_ON(!hdm_ch);
-	BUG_ON(!hdm_ch->is_initialized);
+	if (!hdm_ch || !hdm_ch->is_initialized)
+		return;
 
 	spin_lock_irqsave(&dim_lock, flags);
 
-- 
2.33.0
Re: [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
Posted by Dan Carpenter 22 hours ago
On Mon, Mar 30, 2026 at 07:22:52PM +0100, grondon@gmail.com wrote:
> From: Gabriel Rondon <grondon@gmail.com>
> 
> Replace BUG_ON() calls with an early return since the function returns
> void.
> 
> BUG_ON() is deprecated as it crashes the entire kernel on assertion
> failure (see Documentation/process/deprecated.rst).
> 
> Signed-off-by: Gabriel Rondon <grondon@gmail.com>
> ---
>  drivers/staging/most/dim2/dim2.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
> index 48315f8cd..b820c3647 100644
> --- a/drivers/staging/most/dim2/dim2.c
> +++ b/drivers/staging/most/dim2/dim2.c
> @@ -271,8 +271,8 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
>  	unsigned long flags;
>  	u8 *data;
>  
> -	BUG_ON(!hdm_ch);
> -	BUG_ON(!hdm_ch->is_initialized);
> +	if (!hdm_ch || !hdm_ch->is_initialized)

hdm_ch can't be NULL.  It's a pointer to the middle of a struct plus
an offset.

regards,
dan carpenter

> +		return;
>  
>  	spin_lock_irqsave(&dim_lock, flags);
>  
> -- 
> 2.33.0
>
Re: [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
Posted by grondon@gmail.com 17 hours ago
From: Gabriel Rondon <grondon@gmail.com>

On Tue, 31 Mar 2026 13:55:43 +0300, Dan Carpenter wrote:
> hdm_ch can't be NULL.  It's a pointer to the middle of a struct plus
> an offset.

You're right, the NULL check is unnecessary here. Will send a fix
removing the !hdm_ch check and keeping only !hdm_ch->is_initialized.

Thanks,
Gabriel
Re: [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
Posted by Dan Carpenter 14 hours ago
On Tue, Mar 31, 2026 at 05:44:29PM +0100, grondon@gmail.com wrote:
> From: Gabriel Rondon <grondon@gmail.com>
> 
> On Tue, 31 Mar 2026 13:55:43 +0300, Dan Carpenter wrote:
> > hdm_ch can't be NULL.  It's a pointer to the middle of a struct plus
> > an offset.
> 
> You're right, the NULL check is unnecessary here. Will send a fix
> removing the !hdm_ch check and keeping only !hdm_ch->is_initialized.

Check them all, right?  Maybe the others are similar?

regards,
dan carpenter