public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Magnus Damm <magnus.damm@gmail.com>
To: linux-media@vger.kernel.org
Cc: hverkuil@xs4all.nl, Magnus Damm <magnus.damm@gmail.com>,
	m-karicheri2@ti.com, g.liakhovetski@gmx.de,
	mchehab@infradead.org
Subject: [PATCH] sh_mobile_ceu_camera: Add physical address alignment checks
Date: Wed, 09 Dec 2009 22:07:12 +0900	[thread overview]
Message-ID: <20091209130712.32292.81708.sendpatchset@rxone.opensource.se> (raw)

From: Magnus Damm <damm@opensource.se>

Make sure physical addresses are 32-bit aligned in the
SuperH Mobile CEU driver. The lowest two bits of the
address registers are fixed to zero so frame buffers
have to bit 32-bit aligned. The V4L2 mmap() case is
using dma_alloc_coherent() for this driver which will
return aligned addresses, but in the USERPTR case we
must make sure that the user space pointer is valid.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 drivers/media/video/sh_mobile_ceu_camera.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

--- 0001/drivers/media/video/sh_mobile_ceu_camera.c
+++ work/drivers/media/video/sh_mobile_ceu_camera.c	2009-12-09 17:16:47.000000000 +0900
@@ -278,9 +278,14 @@ static int sh_mobile_ceu_capture(struct 
 
 	phys_addr_top = videobuf_to_dma_contig(pcdev->active);
 	ceu_write(pcdev, CDAYR, phys_addr_top);
+	if (phys_addr_top & 3)
+		return -EINVAL;
+
 	if (pcdev->is_interlaced) {
 		phys_addr_bottom = phys_addr_top + icd->user_width;
 		ceu_write(pcdev, CDBYR, phys_addr_bottom);
+		if (phys_addr_bottom & 3)
+			return -EINVAL;
 	}
 
 	switch (icd->current_fmt->fourcc) {
@@ -288,13 +293,16 @@ static int sh_mobile_ceu_capture(struct 
 	case V4L2_PIX_FMT_NV21:
 	case V4L2_PIX_FMT_NV16:
 	case V4L2_PIX_FMT_NV61:
-		phys_addr_top += icd->user_width *
-			icd->user_height;
+		phys_addr_top += icd->user_width * icd->user_height;
 		ceu_write(pcdev, CDACR, phys_addr_top);
+		if (phys_addr_top & 3)
+			return -EINVAL;
+
 		if (pcdev->is_interlaced) {
-			phys_addr_bottom = phys_addr_top +
-				icd->user_width;
+			phys_addr_bottom = phys_addr_top + icd->user_width;
 			ceu_write(pcdev, CDBCR, phys_addr_bottom);
+			if (phys_addr_bottom & 3)
+				return -EINVAL;
 		}
 	}
 

             reply	other threads:[~2009-12-09 13:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-09 13:07 Magnus Damm [this message]
2009-12-10 12:45 ` [PATCH] sh_mobile_ceu_camera: Add physical address alignment checks Guennadi Liakhovetski

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=20091209130712.32292.81708.sendpatchset@rxone.opensource.se \
    --to=magnus.damm@gmail.com \
    --cc=g.liakhovetski@gmx.de \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=m-karicheri2@ti.com \
    --cc=mchehab@infradead.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