linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: camss: vfe: simplify vfe_get_wm_sizes()
@ 2021-08-18 19:41 trix
  2021-08-31 19:11 ` Robert Foss
  0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2021-08-18 19:41 UTC (permalink / raw)
  To: robert.foss, todor.too, agross, bjorn.andersson, mchehab
  Cc: linux-media, linux-arm-msm, linux-kernel, Tom Rix

From: Tom Rix <trix@redhat.com>

Static analysis reports this representative problem
camss-vfe-4-1.c:333: The result of the left shift is undefined because
  the left operand is negative
  reg |= (height - 1) << 4;
~~~~~~~~~ ^

The is a false positive.  height is set in vfe_get_wm_sizes() which
has a switch statement without a default.

Reviewing the switch, the cases contain redundant assignments.
So simplify to assignments.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 .../media/platform/qcom/camss/camss-vfe-4-1.c | 20 ++++++-------------
 .../media/platform/qcom/camss/camss-vfe-4-7.c | 10 +++-------
 .../media/platform/qcom/camss/camss-vfe-4-8.c |  9 +++------
 3 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
index 7b7c9a0aaab282..42047b11ba529e 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
@@ -290,22 +290,14 @@ static void vfe_wm_frame_based(struct vfe_device *vfe, u8 wm, u8 enable)
 static void vfe_get_wm_sizes(struct v4l2_pix_format_mplane *pix, u8 plane,
 			     u16 *width, u16 *height, u16 *bytesperline)
 {
-	switch (pix->pixelformat) {
-	case V4L2_PIX_FMT_NV12:
-	case V4L2_PIX_FMT_NV21:
-		*width = pix->width;
-		*height = pix->height;
-		*bytesperline = pix->plane_fmt[0].bytesperline;
+	*width = pix->width;
+	*height = pix->height;
+	*bytesperline = pix->plane_fmt[0].bytesperline;
+
+	if (pix->pixelformat == V4L2_PIX_FMT_NV12 ||
+	    pix->pixelformat == V4L2_PIX_FMT_NV21)
 		if (plane == 1)
 			*height /= 2;
-		break;
-	case V4L2_PIX_FMT_NV16:
-	case V4L2_PIX_FMT_NV61:
-		*width = pix->width;
-		*height = pix->height;
-		*bytesperline = pix->plane_fmt[0].bytesperline;
-		break;
-	}
 }
 
 static void vfe_wm_line_based(struct vfe_device *vfe, u32 wm,
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-7.c b/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
index 2836b12ec98915..ab2d57bdf5e71c 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
@@ -370,30 +370,26 @@ static int vfe_word_per_line_by_bytes(u32 bytes_per_line)
 static void vfe_get_wm_sizes(struct v4l2_pix_format_mplane *pix, u8 plane,
 			     u16 *width, u16 *height, u16 *bytesperline)
 {
+	*width = pix->width;
+	*height = pix->height;
+
 	switch (pix->pixelformat) {
 	case V4L2_PIX_FMT_NV12:
 	case V4L2_PIX_FMT_NV21:
-		*width = pix->width;
-		*height = pix->height;
 		*bytesperline = pix->plane_fmt[0].bytesperline;
 		if (plane == 1)
 			*height /= 2;
 		break;
 	case V4L2_PIX_FMT_NV16:
 	case V4L2_PIX_FMT_NV61:
-		*width = pix->width;
-		*height = pix->height;
 		*bytesperline = pix->plane_fmt[0].bytesperline;
 		break;
 	case V4L2_PIX_FMT_YUYV:
 	case V4L2_PIX_FMT_YVYU:
 	case V4L2_PIX_FMT_VYUY:
 	case V4L2_PIX_FMT_UYVY:
-		*width = pix->width;
-		*height = pix->height;
 		*bytesperline = pix->plane_fmt[plane].bytesperline;
 		break;
-
 	}
 }
 
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-8.c b/drivers/media/platform/qcom/camss/camss-vfe-4-8.c
index 19519234f727c1..7e6b62c930ac8a 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-4-8.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-4-8.c
@@ -343,27 +343,24 @@ static int vfe_word_per_line_by_bytes(u32 bytes_per_line)
 static void vfe_get_wm_sizes(struct v4l2_pix_format_mplane *pix, u8 plane,
 			     u16 *width, u16 *height, u16 *bytesperline)
 {
+	*width = pix->width;
+	*height = pix->height;
+
 	switch (pix->pixelformat) {
 	case V4L2_PIX_FMT_NV12:
 	case V4L2_PIX_FMT_NV21:
-		*width = pix->width;
-		*height = pix->height;
 		*bytesperline = pix->plane_fmt[0].bytesperline;
 		if (plane == 1)
 			*height /= 2;
 		break;
 	case V4L2_PIX_FMT_NV16:
 	case V4L2_PIX_FMT_NV61:
-		*width = pix->width;
-		*height = pix->height;
 		*bytesperline = pix->plane_fmt[0].bytesperline;
 		break;
 	case V4L2_PIX_FMT_YUYV:
 	case V4L2_PIX_FMT_YVYU:
 	case V4L2_PIX_FMT_VYUY:
 	case V4L2_PIX_FMT_UYVY:
-		*width = pix->width;
-		*height = pix->height;
 		*bytesperline = pix->plane_fmt[plane].bytesperline;
 		break;
 	}
-- 
2.26.3


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

* Re: [PATCH] media: camss: vfe: simplify vfe_get_wm_sizes()
  2021-08-18 19:41 [PATCH] media: camss: vfe: simplify vfe_get_wm_sizes() trix
@ 2021-08-31 19:11 ` Robert Foss
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Foss @ 2021-08-31 19:11 UTC (permalink / raw)
  To: trix
  Cc: Todor Tomov, Andy Gross, Bjorn Andersson, Mauro Carvalho Chehab,
	linux-media, MSM, linux-kernel

Hey Tom,

Thanks for the patch!

On Wed, 18 Aug 2021 at 21:41, <trix@redhat.com> wrote:
>
> From: Tom Rix <trix@redhat.com>
>
> Static analysis reports this representative problem
> camss-vfe-4-1.c:333: The result of the left shift is undefined because
>   the left operand is negative
>   reg |= (height - 1) << 4;
> ~~~~~~~~~ ^
>
> The is a false positive.  height is set in vfe_get_wm_sizes() which
> has a switch statement without a default.
>
> Reviewing the switch, the cases contain redundant assignments.
> So simplify to assignments.
>
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  .../media/platform/qcom/camss/camss-vfe-4-1.c | 20 ++++++-------------
>  .../media/platform/qcom/camss/camss-vfe-4-7.c | 10 +++-------
>  .../media/platform/qcom/camss/camss-vfe-4-8.c |  9 +++------
>  3 files changed, 12 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
> index 7b7c9a0aaab282..42047b11ba529e 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
> +++ b/drivers/media/platform/qcom/camss/camss-vfe-4-1.c
> @@ -290,22 +290,14 @@ static void vfe_wm_frame_based(struct vfe_device *vfe, u8 wm, u8 enable)
>  static void vfe_get_wm_sizes(struct v4l2_pix_format_mplane *pix, u8 plane,
>                              u16 *width, u16 *height, u16 *bytesperline)
>  {
> -       switch (pix->pixelformat) {
> -       case V4L2_PIX_FMT_NV12:
> -       case V4L2_PIX_FMT_NV21:
> -               *width = pix->width;
> -               *height = pix->height;
> -               *bytesperline = pix->plane_fmt[0].bytesperline;
> +       *width = pix->width;
> +       *height = pix->height;
> +       *bytesperline = pix->plane_fmt[0].bytesperline;
> +
> +       if (pix->pixelformat == V4L2_PIX_FMT_NV12 ||
> +           pix->pixelformat == V4L2_PIX_FMT_NV21)
>                 if (plane == 1)
>                         *height /= 2;
> -               break;
> -       case V4L2_PIX_FMT_NV16:
> -       case V4L2_PIX_FMT_NV61:
> -               *width = pix->width;
> -               *height = pix->height;
> -               *bytesperline = pix->plane_fmt[0].bytesperline;
> -               break;
> -       }
>  }
>
>  static void vfe_wm_line_based(struct vfe_device *vfe, u32 wm,
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-7.c b/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
> index 2836b12ec98915..ab2d57bdf5e71c 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
> +++ b/drivers/media/platform/qcom/camss/camss-vfe-4-7.c
> @@ -370,30 +370,26 @@ static int vfe_word_per_line_by_bytes(u32 bytes_per_line)
>  static void vfe_get_wm_sizes(struct v4l2_pix_format_mplane *pix, u8 plane,
>                              u16 *width, u16 *height, u16 *bytesperline)
>  {
> +       *width = pix->width;
> +       *height = pix->height;
> +
>         switch (pix->pixelformat) {
>         case V4L2_PIX_FMT_NV12:
>         case V4L2_PIX_FMT_NV21:
> -               *width = pix->width;
> -               *height = pix->height;
>                 *bytesperline = pix->plane_fmt[0].bytesperline;
>                 if (plane == 1)
>                         *height /= 2;
>                 break;
>         case V4L2_PIX_FMT_NV16:
>         case V4L2_PIX_FMT_NV61:
> -               *width = pix->width;
> -               *height = pix->height;
>                 *bytesperline = pix->plane_fmt[0].bytesperline;
>                 break;
>         case V4L2_PIX_FMT_YUYV:
>         case V4L2_PIX_FMT_YVYU:
>         case V4L2_PIX_FMT_VYUY:
>         case V4L2_PIX_FMT_UYVY:
> -               *width = pix->width;
> -               *height = pix->height;
>                 *bytesperline = pix->plane_fmt[plane].bytesperline;
>                 break;
> -
>         }
>  }
>
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe-4-8.c b/drivers/media/platform/qcom/camss/camss-vfe-4-8.c
> index 19519234f727c1..7e6b62c930ac8a 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe-4-8.c
> +++ b/drivers/media/platform/qcom/camss/camss-vfe-4-8.c
> @@ -343,27 +343,24 @@ static int vfe_word_per_line_by_bytes(u32 bytes_per_line)
>  static void vfe_get_wm_sizes(struct v4l2_pix_format_mplane *pix, u8 plane,
>                              u16 *width, u16 *height, u16 *bytesperline)
>  {
> +       *width = pix->width;
> +       *height = pix->height;
> +
>         switch (pix->pixelformat) {
>         case V4L2_PIX_FMT_NV12:
>         case V4L2_PIX_FMT_NV21:
> -               *width = pix->width;
> -               *height = pix->height;
>                 *bytesperline = pix->plane_fmt[0].bytesperline;
>                 if (plane == 1)
>                         *height /= 2;
>                 break;
>         case V4L2_PIX_FMT_NV16:
>         case V4L2_PIX_FMT_NV61:
> -               *width = pix->width;
> -               *height = pix->height;
>                 *bytesperline = pix->plane_fmt[0].bytesperline;
>                 break;
>         case V4L2_PIX_FMT_YUYV:
>         case V4L2_PIX_FMT_YVYU:
>         case V4L2_PIX_FMT_VYUY:
>         case V4L2_PIX_FMT_UYVY:
> -               *width = pix->width;
> -               *height = pix->height;
>                 *bytesperline = pix->plane_fmt[plane].bytesperline;
>                 break;
>         }

Reviewed-by: Robert Foss <robert.foss@linaro.org>

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

end of thread, other threads:[~2021-08-31 19:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 19:41 [PATCH] media: camss: vfe: simplify vfe_get_wm_sizes() trix
2021-08-31 19:11 ` Robert Foss

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).