media: imx: imx7-media-csi: Get rid of superfluous call to imx7_csi_mbus_fm t_to_pix_fmt

Fabio Estevam festevam at gmail.com
Thu Jul 20 11:47:46 PDT 2023


On Thu, Jul 20, 2023 at 12:12 PM Tim Harvey <tharvey at gateworks.com> wrote:

> clamp_roundup is static in v4l2-common.c so it would have to be
> something like the following:
>
>         pixfmt->width = round_up(clamp(pixfmt->width, (unsigned int)1,
> (unsigned int)0xffff), walign);
>         pixfmt->height = round_up(clamp(pixfmt->height, (unsigned
> int)1, (unsigned int)0xffff), walign);
>
> the above works. I'm not sure how to keep the compiler from
> complaining about types other than typecasting the min/max values as
> above.

Does it work if we do like this?

--- a/drivers/media/platform/nxp/imx7-media-csi.c
+++ b/drivers/media/platform/nxp/imx7-media-csi.c
@@ -1108,6 +1108,17 @@ static int imx7_csi_video_g_fmt_vid_cap(struct
file *file, void *fh,
        return 0;
 }

+/* borrowed from drivers/media/v4l2-core/v4l2-common.c */
+static unsigned int clamp_roundup(unsigned int x, unsigned int min,
+                                 unsigned int max, unsigned int alignment)
+{
+       x = clamp(x, min, max);
+       if (alignment)
+               x = round_up(x, alignment);
+
+       return x;
+}
+
 static const struct imx7_csi_pixfmt *
 __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
                         struct v4l2_rect *compose)
@@ -1137,8 +1148,8 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
         * TODO: Implement configurable stride support.
         */
        walign = 8 * 8 / cc->bpp;
-       v4l_bound_align_image(&pixfmt->width, 1, 0xffff, walign,
-                             &pixfmt->height, 1, 0xffff, 1, 0);
+       pixfmt->width = clamp_roundup(pixfmt->width, 1, 0xffff, walign);
+       pixfmt->height = clamp_roundup(pixfmt->height, 1, 0xffff, walign);

        pixfmt->bytesperline = pixfmt->width * cc->bpp / 8;
        pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;



More information about the linux-arm-kernel mailing list