media: tvp5150: fix width alignment during set_selection()
authorMarco Felsch <m.felsch@pengutronix.de>
Thu, 28 Jun 2018 16:20:33 +0000 (12:20 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Nov 2018 08:25:57 +0000 (09:25 +0100)
[ Upstream commit bd24db04101f45a9c1d874fe21b0c7eab7bcadec ]

The driver ignored the width alignment which exists due to the UYVY
colorspace format. Fix the width alignment and make use of the the
provided v4l2 helper function to set the width, height and all
alignments in one.

Fixes: 963ddc63e20d ("[media] media: tvp5150: Add cropping support")
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/i2c/tvp5150.c

index 5d9c2b03d83aafd1385d9420b5d62ec1ac0831a8..e83f8111a5fb622ad2ed7654914579a5dfaa21b6 100644 (file)
@@ -897,9 +897,6 @@ static int tvp5150_set_selection(struct v4l2_subdev *sd,
 
        /* tvp5150 has some special limits */
        rect.left = clamp(rect.left, 0, TVP5150_MAX_CROP_LEFT);
-       rect.width = clamp_t(unsigned int, rect.width,
-                            TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left,
-                            TVP5150_H_MAX - rect.left);
        rect.top = clamp(rect.top, 0, TVP5150_MAX_CROP_TOP);
 
        /* Calculate height based on current standard */
@@ -913,9 +910,16 @@ static int tvp5150_set_selection(struct v4l2_subdev *sd,
        else
                hmax = TVP5150_V_MAX_OTHERS;
 
-       rect.height = clamp_t(unsigned int, rect.height,
+       /*
+        * alignments:
+        *  - width = 2 due to UYVY colorspace
+        *  - height, image = no special alignment
+        */
+       v4l_bound_align_image(&rect.width,
+                             TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left,
+                             TVP5150_H_MAX - rect.left, 1, &rect.height,
                              hmax - TVP5150_MAX_CROP_TOP - rect.top,
-                             hmax - rect.top);
+                             hmax - rect.top, 0, 0);
 
        tvp5150_write(sd, TVP5150_VERT_BLANKING_START, rect.top);
        tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP,