[PATCH] kernel memory safety check in a block

Biancaa Ramesh posted 1 patch 12 hours ago
There is a newer version of this series
drivers/media/pci/cx18/cx18-queue.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
[PATCH] kernel memory safety check in a block
Posted by Biancaa Ramesh 12 hours ago
Signed-off-by: Biancaa Ramesh <biancaa2210329@ssn.edu.in>
---
 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;
 		}
 
-- 
2.43.0


-- 
::DISCLAIMER::

---------------------------------------------------------------------
The 
contents of this e-mail and any attachment(s) are confidential and
intended 
for the named recipient(s) only. Views or opinions, if any,
presented in 
this email are solely those of the author and may not
necessarily reflect 
the views or opinions of SSN Institutions (SSN) or its
affiliates. Any form 
of reproduction, dissemination, copying, disclosure,
modification, 
distribution and / or publication of this message without the
prior written 
consent of authorized representative of SSN is strictly
prohibited. If you 
have received this email in error please delete it and
notify the sender 
immediately.
---------------------------------------------------------------------
Header of this mail should have a valid DKIM signature for the domain 
ssn.edu.in <http://www.ssn.edu.in/>
Re: [PATCH] media: cx18: kernel memory safety check in a block
Posted by Markus Elfring 12 hours ago
…
> ---
>  drivers/media/pci/cx18/cx18-queue.c | 11 +++++++++--
…

Thanks for your try to improve the implementation of the function “cx18_stream_alloc”.
https://elixir.bootlin.com/linux/v6.18-rc2/source/drivers/media/pci/cx18/cx18-queue.c#L332-L408

I miss some information so far.

1. Helpful change description
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc2#n45

2. Subsystem specification
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc2#n646
   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/log/drivers/media/pci/cx18/cx18-queue.c

3. More appropriate recipient selection
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc2#n231


…
> -- 
> ::DISCLAIMER::
…
> The 
> contents of this e-mail and any attachment(s) are confidential and
…

Such hints are probably misplaced for communication by the means of public mailing lists.

See also once more:
https://subspace.kernel.org/etiquette.html#do-not-include-confidentiality-disclaimers

Regards,
Markus