From 93ee7d61dc311cfa382cf3461fc7647e0ff62bff Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 30 Apr 2025 09:29:21 +0200 Subject: [PATCH] media: omap3isp: rework isp_video_try/set_format isp_video_set_format now calls isp_video_try_format first, ensuring consistent behavior and removing duplicate code in both functions. This fixes an v4l2-compliance error: fail: v4l2-test-formats.cpp(519): !pix.sizeimage test VIDIOC_S_FMT: FAIL Signed-off-by: Hans Verkuil Acked-by: Sakari Ailus --- drivers/media/platform/ti/omap3isp/ispvideo.c | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/drivers/media/platform/ti/omap3isp/ispvideo.c b/drivers/media/platform/ti/omap3isp/ispvideo.c index c52312b395985..adea39b6d9302 100644 --- a/drivers/media/platform/ti/omap3isp/ispvideo.c +++ b/drivers/media/platform/ti/omap3isp/ispvideo.c @@ -700,11 +700,15 @@ isp_video_get_format(struct file *file, void *fh, struct v4l2_format *format) } static int -isp_video_set_format(struct file *file, void *fh, struct v4l2_format *format) +isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format) { - struct isp_video_fh *vfh = file_to_isp_video_fh(file); struct isp_video *video = video_drvdata(file); - struct v4l2_mbus_framefmt fmt; + struct v4l2_subdev_format fmt = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + struct v4l2_subdev *subdev; + u32 pad; + int ret; if (format->type != video->type) return -EINVAL; @@ -744,32 +748,11 @@ isp_video_set_format(struct file *file, void *fh, struct v4l2_format *format) break; } - /* Fill the bytesperline and sizeimage fields by converting to media bus - * format and back to pixel format. - */ - isp_video_pix_to_mbus(&format->fmt.pix, &fmt); - isp_video_mbus_to_pix(video, &fmt, &format->fmt.pix); - - mutex_lock(&video->mutex); - vfh->format = *format; - mutex_unlock(&video->mutex); - - return 0; -} - -static int -isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format) -{ - struct isp_video *video = video_drvdata(file); - struct v4l2_subdev_format fmt = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - }; - struct v4l2_subdev *subdev; - u32 pad; - int ret; - - if (format->type != video->type) - return -EINVAL; + if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { + isp_video_pix_to_mbus(&format->fmt.pix, &fmt.format); + isp_video_mbus_to_pix(video, &fmt.format, &format->fmt.pix); + return 0; + } subdev = isp_video_remote_subdev(video, &pad); if (subdev == NULL) @@ -786,6 +769,24 @@ isp_video_try_format(struct file *file, void *fh, struct v4l2_format *format) return 0; } +static int +isp_video_set_format(struct file *file, void *fh, struct v4l2_format *format) +{ + struct isp_video_fh *vfh = file_to_isp_video_fh(file); + struct isp_video *video = video_drvdata(file); + int ret; + + ret = isp_video_try_format(file, fh, format); + if (ret) + return ret; + + mutex_lock(&video->mutex); + vfh->format = *format; + mutex_unlock(&video->mutex); + + return 0; +} + static int isp_video_get_selection(struct file *file, void *fh, struct v4l2_selection *sel) { -- 2.47.3