linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH-next] media: s2255drv: Remove unneeded if else blocks
@ 2018-01-24 21:40 Christopher Díaz Riveros
  2018-01-25  8:46 ` walter harms
  0 siblings, 1 reply; 2+ messages in thread
From: Christopher Díaz Riveros @ 2018-01-24 21:40 UTC (permalink / raw)
  To: mchehab, hans.verkuil, arvind.yadav.cs, dean, keescook, bhumirks,
	sakari.ailus
  Cc: linux-media, linux-kernel, kernel-janitors

Given the following definitions from s2255drv.c

 #define LINE_SZ_4CIFS_NTSC      640
 #define LINE_SZ_2CIFS_NTSC      640
 #define LINE_SZ_1CIFS_NTSC      320

and

 #define LINE_SZ_4CIFS_PAL       704
 #define LINE_SZ_2CIFS_PAL       704
 #define LINE_SZ_1CIFS_PAL       352

f->fmt.pix.width possible values can be reduced to
LINE_SZ_4CIFS_NTSC or LINE_SZ_1CIFS_NTSC.

This patch removes unneeded if else blocks in vidioc_try_fmt_vid_cap
function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Christopher Díaz Riveros <chrisadr@gentoo.org>
---
 drivers/media/usb/s2255/s2255drv.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 8c2a86d71e8a..a00a15f55d37 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -803,10 +803,6 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 		}
 		if (f->fmt.pix.width >= LINE_SZ_4CIFS_NTSC)
 			f->fmt.pix.width = LINE_SZ_4CIFS_NTSC;
-		else if (f->fmt.pix.width >= LINE_SZ_2CIFS_NTSC)
-			f->fmt.pix.width = LINE_SZ_2CIFS_NTSC;
-		else if (f->fmt.pix.width >= LINE_SZ_1CIFS_NTSC)
-			f->fmt.pix.width = LINE_SZ_1CIFS_NTSC;
 		else
 			f->fmt.pix.width = LINE_SZ_1CIFS_NTSC;
 	} else {
@@ -820,10 +816,6 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
 		}
 		if (f->fmt.pix.width >= LINE_SZ_4CIFS_PAL)
 			f->fmt.pix.width = LINE_SZ_4CIFS_PAL;
-		else if (f->fmt.pix.width >= LINE_SZ_2CIFS_PAL)
-			f->fmt.pix.width = LINE_SZ_2CIFS_PAL;
-		else if (f->fmt.pix.width >= LINE_SZ_1CIFS_PAL)
-			f->fmt.pix.width = LINE_SZ_1CIFS_PAL;
 		else
 			f->fmt.pix.width = LINE_SZ_1CIFS_PAL;
 	}
-- 
2.16.0

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

* Re: [PATCH-next] media: s2255drv: Remove unneeded if else blocks
  2018-01-24 21:40 [PATCH-next] media: s2255drv: Remove unneeded if else blocks Christopher Díaz Riveros
@ 2018-01-25  8:46 ` walter harms
  0 siblings, 0 replies; 2+ messages in thread
From: walter harms @ 2018-01-25  8:46 UTC (permalink / raw)
  To: Christopher Díaz Riveros
  Cc: mchehab, hans.verkuil, arvind.yadav.cs, dean, keescook, bhumirks,
	sakari.ailus, linux-media, linux-kernel, kernel-janitors



Am 24.01.2018 22:40, schrieb Christopher Díaz Riveros:
> Given the following definitions from s2255drv.c
> 
>  #define LINE_SZ_4CIFS_NTSC      640
>  #define LINE_SZ_2CIFS_NTSC      640
>  #define LINE_SZ_1CIFS_NTSC      320
> 
> and
> 
>  #define LINE_SZ_4CIFS_PAL       704
>  #define LINE_SZ_2CIFS_PAL       704
>  #define LINE_SZ_1CIFS_PAL       352
> 
> f->fmt.pix.width possible values can be reduced to
> LINE_SZ_4CIFS_NTSC or LINE_SZ_1CIFS_NTSC.
> 
> This patch removes unneeded if else blocks in vidioc_try_fmt_vid_cap
> function.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Christopher Díaz Riveros <chrisadr@gentoo.org>

mmmh, yes and no.
i guess the author tries to document the change from 4->2->1

The whole thing gets more obvoius when you use hex and look at the bits:
704 = 0x2C0 = 001011000000
640 = 0x280 = 001010000000
352 = 0x160 = 000101100000
320 = 0x140 = 000101000000

so they only flip one bit and shift the mask. perhaps you can use that
to simplify the code ?

re
 wh
> ---
>  drivers/media/usb/s2255/s2255drv.c | 8 --------
>  1 file changed, 8 deletions(-)
> 
> diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
> index 8c2a86d71e8a..a00a15f55d37 100644
> --- a/drivers/media/usb/s2255/s2255drv.c
> +++ b/drivers/media/usb/s2255/s2255drv.c
> @@ -803,10 +803,6 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
>  		}
>  		if (f->fmt.pix.width >= LINE_SZ_4CIFS_NTSC)
>  			f->fmt.pix.width = LINE_SZ_4CIFS_NTSC;
> -		else if (f->fmt.pix.width >= LINE_SZ_2CIFS_NTSC)
> -			f->fmt.pix.width = LINE_SZ_2CIFS_NTSC;
> -		else if (f->fmt.pix.width >= LINE_SZ_1CIFS_NTSC)
> -			f->fmt.pix.width = LINE_SZ_1CIFS_NTSC;
>  		else
>  			f->fmt.pix.width = LINE_SZ_1CIFS_NTSC;
>  	} else {
> @@ -820,10 +816,6 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
>  		}
>  		if (f->fmt.pix.width >= LINE_SZ_4CIFS_PAL)
>  			f->fmt.pix.width = LINE_SZ_4CIFS_PAL;
> -		else if (f->fmt.pix.width >= LINE_SZ_2CIFS_PAL)
> -			f->fmt.pix.width = LINE_SZ_2CIFS_PAL;
> -		else if (f->fmt.pix.width >= LINE_SZ_1CIFS_PAL)
> -			f->fmt.pix.width = LINE_SZ_1CIFS_PAL;
>  		else
>  			f->fmt.pix.width = LINE_SZ_1CIFS_PAL;
>  	}

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

end of thread, other threads:[~2018-01-25  8:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-24 21:40 [PATCH-next] media: s2255drv: Remove unneeded if else blocks Christopher Díaz Riveros
2018-01-25  8:46 ` walter harms

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