Re: [PATCH 4/8] usb: gadget/uvc: also handle v4l2 ioctl ENUM_FMT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Michael,

Thank you for the patch.

On Wednesday 28 May 2014 09:38:05 Michael Grzeschik wrote:
> This patch adds ENUM_FMT as possible ioctl to the uvc v4l2 device.
> That makes userspace applications with a generic IOCTL calling
> convention make also use of it.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@xxxxxxxxxxxxxx>
> ---
>  drivers/usb/gadget/uvc_v4l2.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c
> index 3223b90..abe0e79 100644
> --- a/drivers/usb/gadget/uvc_v4l2.c
> +++ b/drivers/usb/gadget/uvc_v4l2.c
> @@ -185,6 +185,30 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd,
> void *arg) break;
>  	}
> 
> +	case VIDIOC_ENUM_FMT:
> +	{
> +		struct v4l2_fmtdesc *f = arg;
> +
> +		switch (f->type) {
> +		case V4L2_BUF_TYPE_VIDEO_OUTPUT:
> +			switch (f->index) {
> +				case 0:
> +					strcpy(f->description, "YUV 4:2:2");
> +					f->pixelformat = V4L2_PIX_FMT_YUYV;
> +					break;
> +				case 1:
> +					strcpy(f->description, "MJPEG");
> +					f->pixelformat = V4L2_PIX_FMT_MJPEG;
> +					break;
> +				default:
> +					return -EINVAL;
> +			}
> +			default:
> +				break;

Is this default case included by mistake ?

> +		}
> +		break;
> +	}

That's too many cascaded switch/case statements for my taste. How about 
replacing the first one with a

                if (fmt->type != video->queue.queue.type)
                        return -EINVAL;

like for the other ioctls ? You will then reduce the indentation level by one.

Then, please move the implementation of the ioctl to a separate function, like 
done for G_FMT and S_FMT for instance. Finally, instead of hardcoding the 
formats list, extend the uvc_format structure with a description field and and 
fill the format description from the uvc_formats[] entry corresponding to the 
index (don't forget to validate index against ARRAY_SIZE(uvc_formats)).
 
> +
>  	/* Get & Set format */
>  	case VIDIOC_G_FMT:
>  	{

-- 
Regards,

Laurent Pinchart

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux