mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Fourier <fourier.thomas@gmail.com>
Cc: Thomas Fourier <fourier.thomas@gmail.com>,
	Andy Walls <awalls@md.metrocast.net>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil@xs4all.nl>,
	Ian Armstrong <ian@iarmst.demon.co.uk>,
	Chris Kennedy <c@groovy.org>,
	John P Harvey <john.p.harvey@btinternet.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] media: pci/ivtv: Add missing check after DMA map
Date: Wed,  9 Jul 2025 14:08:33 +0200	[thread overview]
Message-ID: <20250709120834.49667-2-fourier.thomas@gmail.com> (raw)

The DMA map functions can fail and should be tested for errors.
If the mapping fails, free buffers and return an error.

Fixes: 1a0adaf37c30 ("V4L/DVB (5345): ivtv driver for Conexant cx23416/cx23415 MPEG encoder/decoder")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
 drivers/media/pci/ivtv/ivtv-queue.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/media/pci/ivtv/ivtv-queue.c b/drivers/media/pci/ivtv/ivtv-queue.c
index f9b192ab7e7c..c8a5f6d37bd4 100644
--- a/drivers/media/pci/ivtv/ivtv-queue.c
+++ b/drivers/media/pci/ivtv/ivtv-queue.c
@@ -221,6 +221,16 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
 		s->sg_handle = dma_map_single(&itv->pdev->dev, s->sg_dma,
 					      sizeof(struct ivtv_sg_element),
 					      DMA_TO_DEVICE);
+		if (dma_mapping_error(&itv->pdev->dev, s->sg_handle)) {
+			IVTV_ERR("Could not dma map sg_dma for %s stream\n", s->name);
+			kfree(s->sg_pending);
+			s->sg_pending = NULL;
+			kfree(s->sg_processing);
+			s->sg_processing = NULL;
+			kfree(s->sg_dma);
+			s->sg_dma = NULL;
+			return -ENOMEM;
+		}
 		ivtv_stream_sync_for_cpu(s);
 	}
 
@@ -240,6 +250,12 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
 		if (ivtv_might_use_dma(s)) {
 			buf->dma_handle = dma_map_single(&s->itv->pdev->dev,
 				buf->buf, s->buf_size + 256, s->dma);
+			if (dma_mapping_error(&s->itv->pdev->dev,
+					      buf->dma_handle)) {
+				kfree(buf->buf);
+				kfree(buf);
+				break;
+			}
 			ivtv_buf_sync_for_cpu(s, buf);
 		}
 		ivtv_enqueue(s, buf, &s->q_free);
-- 
2.43.0


                 reply	other threads:[~2025-07-09 12:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250709120834.49667-2-fourier.thomas@gmail.com \
    --to=fourier.thomas@gmail.com \
    --cc=awalls@md.metrocast.net \
    --cc=c@groovy.org \
    --cc=hverkuil@xs4all.nl \
    --cc=ian@iarmst.demon.co.uk \
    --cc=john.p.harvey@btinternet.com \
    --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®