diff mbox series

[v2,09/15] media: vimc: cap: Allocate and verify mplanar buffers

Message ID 20190327151743.18528-10-andrealmeid@collabora.com (mailing list archive)
State New, archived
Headers show
Series media: vimc: Add support for multiplanar formats | expand

Commit Message

André Almeida March 27, 2019, 3:17 p.m. UTC
If the driver is in multiplanar mode, fill the vb2 structures
with the planes sizes and verify it the sizes allocated to the
planes are enough.

Signed-off-by: André Almeida <andrealmeid@collabora.com>
---
Change in v2:
- Use IS_MULTIPLANAR macro

 drivers/media/platform/vimc/vimc-capture.c | 42 ++++++++++++++++++----
 1 file changed, 36 insertions(+), 6 deletions(-)

Comments

Helen Mae Koike Fornazier April 12, 2019, 10:49 p.m. UTC | #1
On 3/27/19 12:17 PM, André Almeida wrote:
> If the driver is in multiplanar mode, fill the vb2 structures
> with the planes sizes and verify it the sizes allocated to the
> planes are enough.
> 
> Signed-off-by: André Almeida <andrealmeid@collabora.com>

Acked-by: Helen Koike <helen.koike@collabora.com>

> ---
> Change in v2:
> - Use IS_MULTIPLANAR macro
> 
>  drivers/media/platform/vimc/vimc-capture.c | 42 ++++++++++++++++++----
>  1 file changed, 36 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c
> index c344d04ed8ea..57bc2b64b093 100644
> --- a/drivers/media/platform/vimc/vimc-capture.c
> +++ b/drivers/media/platform/vimc/vimc-capture.c
> @@ -505,12 +505,28 @@ static int vimc_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
>  				struct device *alloc_devs[])
>  {
>  	struct vimc_cap_device *vcap = vb2_get_drv_priv(vq);
> +	const struct v4l2_plane_pix_format *plane_fmt =
> +		vcap->format.fmt.pix_mp.plane_fmt;
> +	unsigned int i;
> +
> +	if (IS_MULTIPLANAR(vcap)) {
> +		for (i = 0; i < *nplanes; i++)
> +			if (sizes[i] < plane_fmt[i].sizeimage)
> +				return -EINVAL;
> +	} else if (*nplanes && sizes[0] < vcap->format.fmt.pix.sizeimage)
> +		return -EINVAL;

I thought checkpatch should complain about the unbalanced braces here
but it didn't.

Helen

>  
>  	if (*nplanes)
> -		return sizes[0] < vcap->format.fmt.pix.sizeimage ? -EINVAL : 0;
> -	/* We don't support multiplanes for now */
> -	*nplanes = 1;
> -	sizes[0] = vcap->format.fmt.pix.sizeimage;
> +		return 0;
> +
> +	if (IS_MULTIPLANAR(vcap)) {
> +		*nplanes = vcap->format.fmt.pix_mp.num_planes;
> +		for (i = 0; i < *nplanes; i++)
> +			sizes[i] = plane_fmt[i].sizeimage;
> +	} else {
> +		*nplanes = 1;
> +		sizes[0] = vcap->format.fmt.pix.sizeimage;
> +	}
>  
>  	return 0;
>  }
> @@ -518,9 +534,23 @@ static int vimc_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
>  static int vimc_cap_buffer_prepare(struct vb2_buffer *vb)
>  {
>  	struct vimc_cap_device *vcap = vb2_get_drv_priv(vb->vb2_queue);
> -	unsigned long size = vcap->format.fmt.pix.sizeimage;
> +	unsigned long size;
> +	unsigned int i;
>  
> -	if (vb2_plane_size(vb, 0) < size) {
> +	if (IS_MULTIPLANAR(vcap)) {
> +		for (i = 0; i < vb->num_planes; i++) {
> +			size = vcap->format.fmt.pix_mp.plane_fmt[i].sizeimage;
> +			if (vb2_plane_size(vb, i) < size) {
> +				dev_err(vcap->dev,
> +					"%s: buffer too small (%lu < %lu)\n",
> +					vcap->vdev.name, vb2_plane_size(vb, i),
> +					size);
> +
> +				return -EINVAL;
> +			}
> +		}
> +	} else if (vb2_plane_size(vb, 0) < vcap->format.fmt.pix.sizeimage) {
> +		size = vcap->format.fmt.pix.sizeimage;
>  		dev_err(vcap->dev, "%s: buffer too small (%lu < %lu)\n",
>  			vcap->vdev.name, vb2_plane_size(vb, 0), size);
>  		return -EINVAL;
>
diff mbox series

Patch

diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c
index c344d04ed8ea..57bc2b64b093 100644
--- a/drivers/media/platform/vimc/vimc-capture.c
+++ b/drivers/media/platform/vimc/vimc-capture.c
@@ -505,12 +505,28 @@  static int vimc_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
 				struct device *alloc_devs[])
 {
 	struct vimc_cap_device *vcap = vb2_get_drv_priv(vq);
+	const struct v4l2_plane_pix_format *plane_fmt =
+		vcap->format.fmt.pix_mp.plane_fmt;
+	unsigned int i;
+
+	if (IS_MULTIPLANAR(vcap)) {
+		for (i = 0; i < *nplanes; i++)
+			if (sizes[i] < plane_fmt[i].sizeimage)
+				return -EINVAL;
+	} else if (*nplanes && sizes[0] < vcap->format.fmt.pix.sizeimage)
+		return -EINVAL;
 
 	if (*nplanes)
-		return sizes[0] < vcap->format.fmt.pix.sizeimage ? -EINVAL : 0;
-	/* We don't support multiplanes for now */
-	*nplanes = 1;
-	sizes[0] = vcap->format.fmt.pix.sizeimage;
+		return 0;
+
+	if (IS_MULTIPLANAR(vcap)) {
+		*nplanes = vcap->format.fmt.pix_mp.num_planes;
+		for (i = 0; i < *nplanes; i++)
+			sizes[i] = plane_fmt[i].sizeimage;
+	} else {
+		*nplanes = 1;
+		sizes[0] = vcap->format.fmt.pix.sizeimage;
+	}
 
 	return 0;
 }
@@ -518,9 +534,23 @@  static int vimc_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
 static int vimc_cap_buffer_prepare(struct vb2_buffer *vb)
 {
 	struct vimc_cap_device *vcap = vb2_get_drv_priv(vb->vb2_queue);
-	unsigned long size = vcap->format.fmt.pix.sizeimage;
+	unsigned long size;
+	unsigned int i;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (IS_MULTIPLANAR(vcap)) {
+		for (i = 0; i < vb->num_planes; i++) {
+			size = vcap->format.fmt.pix_mp.plane_fmt[i].sizeimage;
+			if (vb2_plane_size(vb, i) < size) {
+				dev_err(vcap->dev,
+					"%s: buffer too small (%lu < %lu)\n",
+					vcap->vdev.name, vb2_plane_size(vb, i),
+					size);
+
+				return -EINVAL;
+			}
+		}
+	} else if (vb2_plane_size(vb, 0) < vcap->format.fmt.pix.sizeimage) {
+		size = vcap->format.fmt.pix.sizeimage;
 		dev_err(vcap->dev, "%s: buffer too small (%lu < %lu)\n",
 			vcap->vdev.name, vb2_plane_size(vb, 0), size);
 		return -EINVAL;