Skip to contentSkip to conversation

sh_mobile_ceu_camera: Add physical address alignment checks V2

PATCH New Magnus Damm 1 participant 1 message Dec 11, 2009 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sh_mobile_ceu_camera: Add physical address alignment checks V2

From: Magnus Damm <[email protected]>

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

---

Tested with a hacked up capture.c on a sh7722 Migo-R board.

V2 moves the checks to sh_mobile_ceu_videobuf_prepare()

 drivers/media/video/sh_mobile_ceu_camera.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/media/video/sh_mobile_ceu_camera.c +8 -1
@@ -339,7 +339,7 @@ static int sh_mobile_ceu_videobuf_prepar
 	}
 
 	vb->size = vb->width * vb->height * ((buf->fmt->depth + 7) >> 3);
-	if (0 != vb->baddr && vb->bsize < vb->size) {
+	if (0 != vb->baddr && vb->bsize < vb->size && !(vb->width & 3)) {
 		ret = -EINVAL;
 		goto out;
 	}
@@ -348,6 +348,13 @@ static int sh_mobile_ceu_videobuf_prepar
 		ret = videobuf_iolock(vq, vb, NULL);
 		if (ret)
 			goto fail;
+
+		/* the physical address must be 32-bit aligned (USERPTR) */
+		if (videobuf_to_dma_contig(vb) & 3) {
+			ret = -EINVAL;
+			goto fail;
+		}
+
 		vb->state = VIDEOBUF_PREPARED;
 	}