mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Olle Lukowski <olle@lukowski.dev>
To: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>,
	 Christian Gromm <christian.gromm@microchip.com>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	 Olle Lukowski <olle@lukowski.dev>
Subject: [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error
Date: Tue, 21 Oct 2025 15:16:27 +0300	[thread overview]
Message-ID: <20251021-staging-most-warn-v1-1-4cdd3745bbdc@lukowski.dev> (raw)
In-Reply-To: <20251021-staging-most-warn-v1-0-4cdd3745bbdc@lukowski.dev>

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


  reply	other threads:[~2025-10-21 12:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-10-21 12:24   ` [PATCH 1/3] staging: most: i2c: replace BUG_ON() with WARN_ON_ONCE() and return error 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251021-staging-most-warn-v1-1-4cdd3745bbdc@lukowski.dev \
    --to=olle@lukowski.dev \
    --cc=christian.gromm@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=parthiban.veerasooran@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®