linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] staging: most: replace BUG_ON() with WARN_ON_ONCE()
@ 2025-10-21 12:16 Olle Lukowski
  2025-10-21 12:16 ` [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error Olle Lukowski
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Olle Lukowski @ 2025-10-21 12:16 UTC (permalink / raw)
  To: Parthiban Veerasooran, Christian Gromm, Greg Kroah-Hartman
  Cc: linux-staging, linux-kernel, Olle Lukowski

This small series replaces BUG_ON() calls in three staging MOST drivers
with WARN_ON_ONCE() and appropriate error handling.

The affected drivers are:

  - drivers/staging/most/i2c/i2c.c
  - drivers/staging/most/dim2/dim2.c
  - drivers/staging/most/video/video.c

All changes are mechanical and do not alter runtime behavior, except that
the kernel will now log a warning instead of panicking if a driver
invariant is violated.

Tested with checkpatch.pl and compile-tested (make M=drivers/staging/most).

Signed-off-by: Olle Lukowski <olle@lukowski.dev>
---
Olle Lukowski (3):
      staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error
      staging: most: dim2: replace BUG_ON() with WARN_ON_ONCE() and proper error returns
      staging: most: video: replace BUG_ON() with WARN_ON_ONCE()

 drivers/staging/most/dim2/dim2.c   | 27 +++++++++++++++++++--------
 drivers/staging/most/i2c/i2c.c     |  9 ++++++---
 drivers/staging/most/video/video.c |  2 +-
 3 files changed, 26 insertions(+), 12 deletions(-)
---
base-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
change-id: 20251021-staging-most-warn-51deb2e454aa

Best regards,
-- 
Olle Lukowski <olle@lukowski.dev>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error
  2025-10-21 12:16 [PATCH 0/3] staging: most: replace BUG_ON() with WARN_ON_ONCE() Olle Lukowski
@ 2025-10-21 12:16 ` Olle Lukowski
  2025-10-21 12:24   ` Greg Kroah-Hartman
  2025-10-21 12:16 ` [PATCH 2/3] staging: most: dim2: replace BUG_ON() with WARN_ON_ONCE() and proper error returns Olle Lukowski
  2025-10-21 12:16 ` [PATCH 3/3] staging: most: video: replace BUG_ON() with WARN_ON_ONCE() Olle Lukowski
  2 siblings, 1 reply; 5+ messages in thread
From: Olle Lukowski @ 2025-10-21 12:16 UTC (permalink / raw)
  To: Parthiban Veerasooran, Christian Gromm, Greg Kroah-Hartman
  Cc: linux-staging, linux-kernel, Olle Lukowski

Replace BUG_ON() checks for invalid channel indices with WARN_ON_ONCE()
and return -EINVAL to avoid crashing the kernel unnecessarily.

Signed-off-by: Olle Lukowski <olle@lukowski.dev>
---
 drivers/staging/most/i2c/i2c.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/most/i2c/i2c.c b/drivers/staging/most/i2c/i2c.c
index 184b2dd11..b9267c3fc 100644
--- a/drivers/staging/most/i2c/i2c.c
+++ b/drivers/staging/most/i2c/i2c.c
@@ -71,7 +71,8 @@ static int configure_channel(struct most_interface *most_iface,
 	struct hdm_i2c *dev = to_hdm(most_iface);
 	unsigned int delay, pr;
 
-	BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS);
+	if (WARN_ON_ONCE(ch_idx < 0 || ch_idx >= NUM_CHANNELS))
+		return -EINVAL;
 
 	if (channel_config->data_type != MOST_CH_CONTROL) {
 		pr_err("bad data type for channel %d\n", ch_idx);
@@ -125,7 +126,8 @@ static int enqueue(struct most_interface *most_iface,
 	struct hdm_i2c *dev = to_hdm(most_iface);
 	int ret;
 
-	BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS);
+	if (WARN_ON_ONCE(ch_idx < 0 || ch_idx >= NUM_CHANNELS))
+		return -EINVAL;
 
 	if (ch_idx == CH_RX) {
 		/* RX */
@@ -170,7 +172,8 @@ static int poison_channel(struct most_interface *most_iface,
 	struct hdm_i2c *dev = to_hdm(most_iface);
 	struct mbo *mbo;
 
-	BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS);
+	if (WARN_ON_ONCE(ch_idx < 0 || ch_idx >= NUM_CHANNELS))
+		return -EINVAL;
 
 	if (ch_idx == CH_RX) {
 		if (!polling_rate)

-- 
2.51.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] staging: most: dim2: replace BUG_ON() with WARN_ON_ONCE() and proper error returns
  2025-10-21 12:16 [PATCH 0/3] staging: most: replace BUG_ON() with WARN_ON_ONCE() Olle Lukowski
  2025-10-21 12:16 ` [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error Olle Lukowski
@ 2025-10-21 12:16 ` Olle Lukowski
  2025-10-21 12:16 ` [PATCH 3/3] staging: most: video: replace BUG_ON() with WARN_ON_ONCE() Olle Lukowski
  2 siblings, 0 replies; 5+ messages in thread
From: Olle Lukowski @ 2025-10-21 12:16 UTC (permalink / raw)
  To: Parthiban Veerasooran, Christian Gromm, Greg Kroah-Hartman
  Cc: linux-staging, linux-kernel, Olle Lukowski

Replace BUG_ON() calls with WARN_ON_ONCE() to prevent unnecessary kernel
panics. Return appropriate error codes (-EINVAL or -EFAULT) instead of
crashing the system.

Signed-off-by: Olle Lukowski <olle@lukowski.dev>
---
 drivers/staging/most/dim2/dim2.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c
index dad2abe6c..a9dc3765b 100644
--- a/drivers/staging/most/dim2/dim2.c
+++ b/drivers/staging/most/dim2/dim2.c
@@ -166,8 +166,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 (WARN_ON_ONCE(!hdm_ch))
+		return -EINVAL;
+	if (WARN_ON_ONCE(!hdm_ch->is_initialized))
+		return -EINVAL;
 
 	spin_lock_irqsave(&dim_lock, flags);
 	if (list_empty(head)) {
@@ -188,7 +190,11 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
 		return -EAGAIN;
 	}
 
-	BUG_ON(mbo->bus_address == 0);
+	if (WARN_ON_ONCE(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);
@@ -269,8 +275,10 @@ 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 (WARN_ON_ONCE(!hdm_ch))
+		return;
+	if (WARN_ON_ONCE(!hdm_ch->is_initialized))
+		return;
 
 	spin_lock_irqsave(&dim_lock, flags);
 
@@ -455,7 +463,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 (WARN_ON_ONCE(ch_idx < 0 || ch_idx >= DMA_CHANNELS))
+		return -EINVAL;
 
 	if (hdm_ch->is_initialized)
 		return -EPERM;
@@ -567,7 +576,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 (WARN_ON_ONCE(ch_idx < 0 || ch_idx >= DMA_CHANNELS))
+		return -EINVAL;
 
 	if (!hdm_ch->is_initialized)
 		return -EPERM;
@@ -643,7 +653,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 (WARN_ON_ONCE(ch_idx < 0 || ch_idx >= DMA_CHANNELS))
+		return -EINVAL;
 
 	if (!hdm_ch->is_initialized)
 		return -EPERM;

-- 
2.51.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] staging: most: video: replace BUG_ON() with WARN_ON_ONCE()
  2025-10-21 12:16 [PATCH 0/3] staging: most: replace BUG_ON() with WARN_ON_ONCE() Olle Lukowski
  2025-10-21 12:16 ` [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error Olle Lukowski
  2025-10-21 12:16 ` [PATCH 2/3] staging: most: dim2: replace BUG_ON() with WARN_ON_ONCE() and proper error returns Olle Lukowski
@ 2025-10-21 12:16 ` Olle Lukowski
  2 siblings, 0 replies; 5+ messages in thread
From: Olle Lukowski @ 2025-10-21 12:16 UTC (permalink / raw)
  To: Parthiban Veerasooran, Christian Gromm, Greg Kroah-Hartman
  Cc: linux-staging, linux-kernel, Olle Lukowski

Replace a BUG_ON() call with WARN_ON_ONCE() to prevent an unnecessary
kernel panic.

Signed-off-by: Olle Lukowski <olle@lukowski.dev>
---
 drivers/staging/most/video/video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c
index 32f71d9a9..3a622bd59 100644
--- a/drivers/staging/most/video/video.c
+++ b/drivers/staging/most/video/video.c
@@ -575,7 +575,7 @@ static void __exit comp_exit(void)
 
 	most_deregister_configfs_subsys(&comp);
 	most_deregister_component(&comp);
-	BUG_ON(!list_empty(&video_devices));
+	WARN_ON_ONCE(!list_empty(&video_devices));
 }
 
 module_init(comp_init);

-- 
2.51.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error
  2025-10-21 12:16 ` [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error Olle Lukowski
@ 2025-10-21 12:24   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2025-10-21 12:24 UTC (permalink / raw)
  To: Olle Lukowski
  Cc: Parthiban Veerasooran, Christian Gromm, linux-staging,
	linux-kernel

On Tue, Oct 21, 2025 at 03:16:27PM +0300, Olle Lukowski wrote:
> Replace BUG_ON() checks for invalid channel indices with WARN_ON_ONCE()
> and return -EINVAL to avoid crashing the kernel unnecessarily.
> 
> Signed-off-by: Olle Lukowski <olle@lukowski.dev>
> ---
>  drivers/staging/most/i2c/i2c.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/most/i2c/i2c.c b/drivers/staging/most/i2c/i2c.c
> index 184b2dd11..b9267c3fc 100644
> --- a/drivers/staging/most/i2c/i2c.c
> +++ b/drivers/staging/most/i2c/i2c.c
> @@ -71,7 +71,8 @@ static int configure_channel(struct most_interface *most_iface,
>  	struct hdm_i2c *dev = to_hdm(most_iface);
>  	unsigned int delay, pr;
>  
> -	BUG_ON(ch_idx < 0 || ch_idx >= NUM_CHANNELS);
> +	if (WARN_ON_ONCE(ch_idx < 0 || ch_idx >= NUM_CHANNELS))
> +		return -EINVAL;

If this is something that can actually ever happen, this change really
doesn't do anything well.  Many systems (i.e. the HUGE majority of Linux
instances in the world, billions) are running with panic-on-warn set, so
that means this will still reboot the box.

So please, just properly handle the issue and return an error and do not
panic the system.

Same for the other patches in this series.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-21 12:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21 12:16 [PATCH 0/3] staging: most: replace BUG_ON() with WARN_ON_ONCE() Olle Lukowski
2025-10-21 12:16 ` [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error Olle Lukowski
2025-10-21 12:24   ` Greg Kroah-Hartman
2025-10-21 12:16 ` [PATCH 2/3] staging: most: dim2: replace BUG_ON() with WARN_ON_ONCE() and proper error returns Olle Lukowski
2025-10-21 12:16 ` [PATCH 3/3] staging: most: video: replace BUG_ON() with WARN_ON_ONCE() Olle Lukowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).