linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: uvc: also use try_format in set_format
@ 2022-10-26 18:22 Michael Grzeschik
  2022-11-09 10:38 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Grzeschik @ 2022-10-26 18:22 UTC (permalink / raw)
  To: linux-usb; +Cc: linux-media, gregkh, balbi, laurent.pinchart, kernel

Since e219a712bc06 (usb: gadget: uvc: add v4l2 try_format api call) the
try_format function is available. With this function includes checks for
valid configurations programmed in the configfs. We use this function to
ensure to return valid values on the set_format callback.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

---
 drivers/usb/gadget/function/uvc_v4l2.c | 72 ++++++++------------------
 1 file changed, 21 insertions(+), 51 deletions(-)

diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index d5bb3038626267..a12475d289167a 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -275,16 +275,6 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
  * V4L2 ioctls
  */
 
-struct uvc_format {
-	u8 bpp;
-	u32 fcc;
-};
-
-static struct uvc_format uvc_formats[] = {
-	{ 16, V4L2_PIX_FMT_YUYV  },
-	{ 0,  V4L2_PIX_FMT_MJPEG },
-};
-
 static int
 uvc_v4l2_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
 {
@@ -318,47 +308,6 @@ uvc_v4l2_get_format(struct file *file, void *fh, struct v4l2_format *fmt)
 	return 0;
 }
 
-static int
-uvc_v4l2_set_format(struct file *file, void *fh, struct v4l2_format *fmt)
-{
-	struct video_device *vdev = video_devdata(file);
-	struct uvc_device *uvc = video_get_drvdata(vdev);
-	struct uvc_video *video = &uvc->video;
-	struct uvc_format *format;
-	unsigned int imagesize;
-	unsigned int bpl;
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(uvc_formats); ++i) {
-		format = &uvc_formats[i];
-		if (format->fcc == fmt->fmt.pix.pixelformat)
-			break;
-	}
-
-	if (i == ARRAY_SIZE(uvc_formats)) {
-		uvcg_info(&uvc->func, "Unsupported format 0x%08x.\n",
-			  fmt->fmt.pix.pixelformat);
-		return -EINVAL;
-	}
-
-	bpl = format->bpp * fmt->fmt.pix.width / 8;
-	imagesize = bpl ? bpl * fmt->fmt.pix.height : fmt->fmt.pix.sizeimage;
-
-	video->fcc = format->fcc;
-	video->bpp = format->bpp;
-	video->width = fmt->fmt.pix.width;
-	video->height = fmt->fmt.pix.height;
-	video->imagesize = imagesize;
-
-	fmt->fmt.pix.field = V4L2_FIELD_NONE;
-	fmt->fmt.pix.bytesperline = bpl;
-	fmt->fmt.pix.sizeimage = imagesize;
-	fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
-	fmt->fmt.pix.priv = 0;
-
-	return 0;
-}
-
 static int
 uvc_v4l2_try_format(struct file *file, void *fh, struct v4l2_format *fmt)
 {
@@ -399,6 +348,27 @@ uvc_v4l2_try_format(struct file *file, void *fh, struct v4l2_format *fmt)
 	return 0;
 }
 
+static int
+uvc_v4l2_set_format(struct file *file, void *fh, struct v4l2_format *fmt)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct uvc_device *uvc = video_get_drvdata(vdev);
+	struct uvc_video *video = &uvc->video;
+	int ret;
+
+	ret = uvc_v4l2_try_format(file, fh, fmt);
+	if (ret)
+		return ret;
+
+	video->fcc = fmt->fmt.pix.pixelformat;
+	video->bpp = fmt->fmt.pix.bytesperline * 8 / video->width;
+	video->width = fmt->fmt.pix.width;
+	video->height = fmt->fmt.pix.height;
+	video->imagesize = fmt->fmt.pix.sizeimage;
+
+	return ret;
+}
+
 static int
 uvc_v4l2_enum_frameintervals(struct file *file, void *fh,
 		struct v4l2_frmivalenum *fival)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: gadget: uvc: also use try_format in set_format
  2022-10-26 18:22 [PATCH] usb: gadget: uvc: also use try_format in set_format Michael Grzeschik
@ 2022-11-09 10:38 ` Greg KH
  2022-11-09 14:06   ` Michael Grzeschik
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2022-11-09 10:38 UTC (permalink / raw)
  To: Michael Grzeschik; +Cc: linux-usb, linux-media, balbi, laurent.pinchart, kernel

On Wed, Oct 26, 2022 at 08:22:40PM +0200, Michael Grzeschik wrote:
> Since e219a712bc06 (usb: gadget: uvc: add v4l2 try_format api call) the
> try_format function is available. With this function includes checks for
> valid configurations programmed in the configfs. We use this function to
> ensure to return valid values on the set_format callback.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> 
> ---
>  drivers/usb/gadget/function/uvc_v4l2.c | 72 ++++++++------------------
>  1 file changed, 21 insertions(+), 51 deletions(-)

Again, is this a fix?  And should it go to stable kernels?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: gadget: uvc: also use try_format in set_format
  2022-11-09 10:38 ` Greg KH
@ 2022-11-09 14:06   ` Michael Grzeschik
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Grzeschik @ 2022-11-09 14:06 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb, linux-media, balbi, laurent.pinchart, kernel

[-- Attachment #1: Type: text/plain, Size: 1178 bytes --]

On Wed, Nov 09, 2022 at 11:38:22AM +0100, Greg KH wrote:
>On Wed, Oct 26, 2022 at 08:22:40PM +0200, Michael Grzeschik wrote:
>> Since e219a712bc06 (usb: gadget: uvc: add v4l2 try_format api call) the
>> try_format function is available. With this function includes checks for
>> valid configurations programmed in the configfs. We use this function to
>> ensure to return valid values on the set_format callback.
>>
>> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
>>
>> ---
>>  drivers/usb/gadget/function/uvc_v4l2.c | 72 ++++++++------------------
>>  1 file changed, 21 insertions(+), 51 deletions(-)
>
>Again, is this a fix?  And should it go to stable kernels?

You can add:

Fixes: e219a712bc06 ("usb: gadget: uvc: add v4l2 try_format api call")

Since uvc_v4l2_try_format was introduced with that patch.

Thanks,
Michael

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-09 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-26 18:22 [PATCH] usb: gadget: uvc: also use try_format in set_format Michael Grzeschik
2022-11-09 10:38 ` Greg KH
2022-11-09 14:06   ` Michael Grzeschik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).