* [PATCH v2 1/5] staging: most: dim2: replace BUG_ON() in try_start_dim_transfer()
2026-03-30 18:22 [PATCH v2 0/5] staging: most: dim2: replace BUG_ON() with graceful error handling grondon
@ 2026-03-30 18:22 ` grondon
2026-03-30 18:22 ` [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag() grondon
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: grondon @ 2026-03-30 18:22 UTC (permalink / raw)
To: parthiban.veerasooran, christian.gromm, gregkh
Cc: linux-staging, linux-kernel, Gabriel Rondon
From: Gabriel Rondon <grondon@gmail.com>
Replace BUG_ON() calls with graceful error handling.
For the null/uninitialized channel checks, return -EINVAL instead of
crashing the kernel. For the zero bus_address check, release the
spinlock and return -EFAULT.
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 | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index 66617e89e..48315f8cd 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -165,8 +165,8 @@ 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 || !hdm_ch->is_initialized)
+ return -EINVAL;
spin_lock_irqsave(&dim_lock, flags);
if (list_empty(head)) {
@@ -187,7 +187,10 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
return -EAGAIN;
}
- BUG_ON(mbo->bus_address == 0);
+ if (mbo->bus_address == 0) {
+ spin_unlock_irqrestore(&dim_lock, flags);
+ return -EFAULT;
+ }
if (!dim_enqueue_buffer(&hdm_ch->ch, mbo->bus_address, buf_size)) {
list_del(head->next);
spin_unlock_irqrestore(&dim_lock, flags);
--
2.33.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
2026-03-30 18:22 [PATCH v2 0/5] staging: most: dim2: replace BUG_ON() with graceful error handling grondon
2026-03-30 18:22 ` [PATCH v2 1/5] staging: most: dim2: replace BUG_ON() in try_start_dim_transfer() grondon
@ 2026-03-30 18:22 ` grondon
2026-03-31 10:55 ` Dan Carpenter
2026-03-30 18:22 ` [PATCH v2 3/5] staging: most: dim2: replace BUG_ON() in configure_channel() grondon
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: grondon @ 2026-03-30 18:22 UTC (permalink / raw)
To: parthiban.veerasooran, christian.gromm, gregkh
Cc: linux-staging, linux-kernel, Gabriel Rondon
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
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
2026-03-30 18:22 ` [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag() grondon
@ 2026-03-31 10:55 ` Dan Carpenter
2026-03-31 16:44 ` grondon
0 siblings, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2026-03-31 10:55 UTC (permalink / raw)
To: grondon
Cc: parthiban.veerasooran, christian.gromm, gregkh, linux-staging,
linux-kernel
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
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
2026-03-31 10:55 ` Dan Carpenter
@ 2026-03-31 16:44 ` grondon
2026-03-31 19:40 ` Dan Carpenter
0 siblings, 1 reply; 10+ messages in thread
From: grondon @ 2026-03-31 16:44 UTC (permalink / raw)
To: error27
Cc: gregkh, christian.gromm, parthiban.veerasooran, linux-staging,
linux-kernel, Gabriel Rondon
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
2026-03-31 16:44 ` grondon
@ 2026-03-31 19:40 ` Dan Carpenter
2026-04-01 10:09 ` grondon
0 siblings, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2026-03-31 19:40 UTC (permalink / raw)
To: grondon
Cc: gregkh, christian.gromm, parthiban.veerasooran, linux-staging,
linux-kernel
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag()
2026-03-31 19:40 ` Dan Carpenter
@ 2026-04-01 10:09 ` grondon
0 siblings, 0 replies; 10+ messages in thread
From: grondon @ 2026-04-01 10:09 UTC (permalink / raw)
To: error27
Cc: gregkh, christian.gromm, parthiban.veerasooran, linux-staging,
linux-kernel, Gabriel Rondon
From: Gabriel Rondon <grondon@gmail.com>
On Tue, 31 Mar 2026 22:40:00 +0300, Dan Carpenter wrote:
> Check them all, right? Maybe the others are similar?
Checked. Patches 3/5 through 5/5 (configure_channel, enqueue,
poison_channel) only check ch_idx range, no hdm_ch NULL check — those
are fine.
Patch 1/5 (try_start_dim_transfer) does have the same unnecessary
!hdm_ch check. hdm_ch is a parameter there, but it's already
dereferenced on the line above (head = &hdm_ch->pending_list), so a
NULL check after that is dead code. Will send a fix for that one too.
Thanks,
Gabriel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/5] staging: most: dim2: replace BUG_ON() in configure_channel()
2026-03-30 18:22 [PATCH v2 0/5] staging: most: dim2: replace BUG_ON() with graceful error handling grondon
2026-03-30 18:22 ` [PATCH v2 1/5] staging: most: dim2: replace BUG_ON() in try_start_dim_transfer() grondon
2026-03-30 18:22 ` [PATCH v2 2/5] staging: most: dim2: replace BUG_ON() in service_done_flag() grondon
@ 2026-03-30 18:22 ` grondon
2026-03-30 18:22 ` [PATCH v2 4/5] staging: most: dim2: replace BUG_ON() in enqueue() grondon
2026-03-30 18:22 ` [PATCH v2 5/5] staging: most: dim2: replace BUG_ON() in poison_channel() grondon
4 siblings, 0 replies; 10+ messages in thread
From: grondon @ 2026-03-30 18:22 UTC (permalink / raw)
To: parthiban.veerasooran, christian.gromm, gregkh
Cc: linux-staging, linux-kernel, Gabriel Rondon
From: Gabriel Rondon <grondon@gmail.com>
Replace BUG_ON() range check on ch_idx with a return of -EINVAL.
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 | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index b820c3647..0b80f313a 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -457,7 +457,8 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx,
int const ch_addr = ch_idx * 2 + 2;
struct hdm_channel *const hdm_ch = dev->hch + ch_idx;
- BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
+ if (ch_idx < 0 || ch_idx >= DMA_CHANNELS)
+ return -EINVAL;
if (hdm_ch->is_initialized)
return -EPERM;
--
2.33.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 4/5] staging: most: dim2: replace BUG_ON() in enqueue()
2026-03-30 18:22 [PATCH v2 0/5] staging: most: dim2: replace BUG_ON() with graceful error handling grondon
` (2 preceding siblings ...)
2026-03-30 18:22 ` [PATCH v2 3/5] staging: most: dim2: replace BUG_ON() in configure_channel() grondon
@ 2026-03-30 18:22 ` grondon
2026-03-30 18:22 ` [PATCH v2 5/5] staging: most: dim2: replace BUG_ON() in poison_channel() grondon
4 siblings, 0 replies; 10+ messages in thread
From: grondon @ 2026-03-30 18:22 UTC (permalink / raw)
To: parthiban.veerasooran, christian.gromm, gregkh
Cc: linux-staging, linux-kernel, Gabriel Rondon
From: Gabriel Rondon <grondon@gmail.com>
Replace BUG_ON() range check on ch_idx with a return of -EINVAL.
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 | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index 0b80f313a..23230a32c 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -570,7 +570,8 @@ static int enqueue(struct most_interface *most_iface, int ch_idx,
struct hdm_channel *hdm_ch = dev->hch + ch_idx;
unsigned long flags;
- BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
+ if (ch_idx < 0 || ch_idx >= DMA_CHANNELS)
+ return -EINVAL;
if (!hdm_ch->is_initialized)
return -EPERM;
--
2.33.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 5/5] staging: most: dim2: replace BUG_ON() in poison_channel()
2026-03-30 18:22 [PATCH v2 0/5] staging: most: dim2: replace BUG_ON() with graceful error handling grondon
` (3 preceding siblings ...)
2026-03-30 18:22 ` [PATCH v2 4/5] staging: most: dim2: replace BUG_ON() in enqueue() grondon
@ 2026-03-30 18:22 ` grondon
4 siblings, 0 replies; 10+ messages in thread
From: grondon @ 2026-03-30 18:22 UTC (permalink / raw)
To: parthiban.veerasooran, christian.gromm, gregkh
Cc: linux-staging, linux-kernel, Gabriel Rondon
From: Gabriel Rondon <grondon@gmail.com>
Replace BUG_ON() range check on ch_idx with a return of -EINVAL.
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 | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index 23230a32c..7953d4626 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -647,7 +647,8 @@ static int poison_channel(struct most_interface *most_iface, int ch_idx)
u8 hal_ret;
int ret = 0;
- BUG_ON(ch_idx < 0 || ch_idx >= DMA_CHANNELS);
+ if (ch_idx < 0 || ch_idx >= DMA_CHANNELS)
+ return -EINVAL;
if (!hdm_ch->is_initialized)
return -EPERM;
--
2.33.0
^ permalink raw reply related [flat|nested] 10+ messages in thread