staging: most: replace BUG_ON() with WARN_ON_ONCE()
Subsystems (2)
cover staging: most: replace BUG_ON() with WARN_ON_ONCE()
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).
---
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,
Signature · 1 line
Olle Lukowski <[email protected]>
PATCH 1/3 staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error
Replace BUG_ON() checks for invalid channel indices with WARN_ON_ONCE() and return -EINVAL to avoid crashing the kernel unnecessarily.
--- drivers/staging/most/i2c/i2c.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/staging/most/i2c/i2c.c +6 -3
@@ -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)
Signature · 1 line
2.51.1
Greg Kroah-Hartman
maintainerRe: [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error
Quoted 13 lines · Olle Lukowski
Replace
BUG_ON()checks for invalid channel indices withWARN_ON_ONCE()and return-EINVALto avoid crashing the kernel unnecessarily.Signed-off-by Olle Lukowski <[email protected]>--- drivers/staging/most/i2c/i2c.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/staging/most/i2c/i2c.c +0
-0
drivers/staging/most/i2c/i2c.c static int configure_channel(struct most_interface *most_iface, · line 75
Quoted 6 lines
drivers/staging/most/i2c/i2c.c +2
-1@@ -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
PATCH 2/3 staging: most: dim2: replace BUG_ON() with WARN_ON_ONCE() and proper error returns
In reply to Olle LukowskiReplace BUG_ON() calls with WARN_ON_ONCE() to prevent unnecessary kernel panics. Return appropriate error codes (-EINVAL or -EFAULT) instead of crashing the system.
--- drivers/staging/most/dim2/dim2.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/staging/most/dim2/dim2.c +19 -8
@@ -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 ;
Signature · 1 line
2.51.1
PATCH 3/3 staging: most: video: replace BUG_ON() with WARN_ON_ONCE()
In reply to Olle LukowskiReplace a BUG_ON() call with WARN_ON_ONCE() to prevent an unnecessary kernel panic.
--- drivers/staging/most/video/video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/most/video/video.c +1 -1
@@ -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);
Signature · 1 line
2.51.1