mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@iki.fi>
To: Biancaa Ramesh <biancaa2210329@ssn.edu.in>
Cc: linux-kernel@vger.kernel.org, awalls@md.metrocast.net,
	mchehab@kernel.org, linux-media@vger.kernel.org
Subject: Re: [PATCH] kernel memory safety check in a block
Date: Wed, 22 Oct 2025 13:20:52 +0300	[thread overview]
Message-ID: <aPiwBG0Iusmy3jeZ@valkosipuli.retiisi.eu> (raw)
In-Reply-To: <20251021201704.178535-1-biancaa2210329@ssn.edu.in>

Hi Biancaa,

On Wed, Oct 22, 2025 at 01:47:04AM +0530, Biancaa Ramesh wrote:
> Signed-off-by: Biancaa Ramesh <biancaa2210329@ssn.edu.in>
> [PATCH] media: cx18: fix potential double free in cx18_stream_alloc
> 
> The function cx18_stream_alloc() may free buf->buf and buf multiple times
> if dma_mapping_error() occurs. This patch:
> 
> - Adds checks before kfree() to avoid double free
> - Sets pointers to NULL after free to make accidental double free less likely
> - Improves overall memory safety and robustness in error paths
> ---
>  drivers/media/pci/cx18/cx18-queue.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/pci/cx18/cx18-queue.c b/drivers/media/pci/cx18/cx18-queue.c
> index eeb5513b1d52..025ba4e6e4be 100644
> --- a/drivers/media/pci/cx18/cx18-queue.c
> +++ b/drivers/media/pci/cx18/cx18-queue.c
> @@ -383,9 +383,16 @@ int cx18_stream_alloc(struct cx18_stream *s)
>  						 buf->buf, s->buf_size,
>  						 s->dma);
>  		if (dma_mapping_error(&s->cx->pci_dev->dev, buf->dma_handle)) {
> -			kfree(buf->buf);
> +			if (buf) {
> +        		if (buf->buf){
> +            	kfree(buf->buf);
> +				buf->buf =NULL;
> +				}
> +        		kfree(buf);
> +				buf=NULL;
> +    		}
>  			kfree(mdl);
> -			kfree(buf);
> +			//makes accidental double free less possible
>  			break;
>  		}
>  

Please read Documentation/process/submitting-patches.rst before submitting
further patches.

-- 
Kind regards,

Sakari Ailus

  reply	other threads:[~2025-10-22 10:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21 20:17 Biancaa Ramesh
2025-10-22 10:20 ` Sakari Ailus [this message]
2025-10-30  8:37 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2025-10-21 19:54 Biancaa Ramesh
2025-10-21 17:57 Biancaa Ramesh

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=aPiwBG0Iusmy3jeZ@valkosipuli.retiisi.eu \
    --to=sakari.ailus@iki.fi \
    --cc=awalls@md.metrocast.net \
    --cc=biancaa2210329@ssn.edu.in \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /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®