linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Olle Lukowski <olle@lukowski.dev>
Cc: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>,
	Christian Gromm <christian.gromm@microchip.com>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] staging: most: dim2: replace BUG_ON() with proper checks and error returns
Date: Tue, 21 Oct 2025 18:02:20 +0200	[thread overview]
Message-ID: <2025102108-smartness-rework-238c@gregkh> (raw)
In-Reply-To: <20251021-staging-most-warn-v2-2-cd51e1e717f6@lukowski.dev>

On Tue, Oct 21, 2025 at 04:09:29PM +0300, Olle Lukowski wrote:
> Replace BUG_ON() calls with proper checks 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..d0832704b 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 (!hdm_ch)
> +		return -EINVAL;
> +	if (!hdm_ch->is_initialized)
> +		return -EINVAL;

Can these things ever actually happen?  In looking at the code, I don't
see how that could be, do you?

Let's not check for things that are impossible to ever hit.

Same with the other changes in this series, please verify that these are
actually possible to happen.  If not, then just remove the check.

>  	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 (mbo->bus_address == 0) {
> +		spin_unlock_irqrestore(&dim_lock, flags);
> +		return -EFAULT;

You need to do more than just that here :(

Please be very careful on error paths to properly clean up everything.

thanks,

greg k-h

  reply	other threads:[~2025-10-21 16:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21 13:09 [PATCH v2 0/3] staging: most: replace BUG_ON() with proper error handling Olle Lukowski
2025-10-21 13:09 ` [PATCH v2 1/3] staging: most: i2c: replace BUG_ON() with proper checks and error returns Olle Lukowski
2025-10-21 13:09 ` [PATCH v2 2/3] staging: most: dim2: " Olle Lukowski
2025-10-21 16:02   ` Greg Kroah-Hartman [this message]
2025-10-21 13:09 ` [PATCH v2 3/3] staging: most: video: replace BUG_ON() with proper check Olle Lukowski
2025-10-21 16:02   ` Greg Kroah-Hartman

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=2025102108-smartness-rework-238c@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=christian.gromm@microchip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=olle@lukowski.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;
as well as URLs for NNTP newsgroup(s).