All of lore.kernel.org
 help / color / mirror / Atom feed
From: walter harms <wharms@bfs.de>
To: "Christopher Díaz Riveros" <chrisadr@gentoo.org>
Cc: mchehab@kernel.org, hans.verkuil@cisco.com,
	arvind.yadav.cs@gmail.com, dean@sensoray.com,
	keescook@chromium.org, bhumirks@gmail.com,
	sakari.ailus@linux.intel.com, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH-next] media: s2255drv: Remove unneeded if else blocks
Date: Thu, 25 Jan 2018 08:46:05 +0000	[thread overview]
Message-ID: <5A69994D.5070802@bfs.de> (raw)
In-Reply-To: <20180124214043.16429-1-chrisadr@gentoo.org>



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;
>  	}

WARNING: multiple messages have this Message-ID (diff)
From: walter harms <wharms@bfs.de>
To: "Christopher Díaz Riveros" <chrisadr@gentoo.org>
Cc: mchehab@kernel.org, hans.verkuil@cisco.com,
	arvind.yadav.cs@gmail.com, dean@sensoray.com,
	keescook@chromium.org, bhumirks@gmail.com,
	sakari.ailus@linux.intel.com, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH-next] media: s2255drv: Remove unneeded if else blocks
Date: Thu, 25 Jan 2018 09:46:05 +0100	[thread overview]
Message-ID: <5A69994D.5070802@bfs.de> (raw)
In-Reply-To: <20180124214043.16429-1-chrisadr@gentoo.org>



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;
>  	}

  reply	other threads:[~2018-01-25  8:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 21:40 [PATCH-next] media: s2255drv: Remove unneeded if else blocks Christopher Díaz Riveros
2018-01-24 21:40 ` Christopher Díaz Riveros
2018-01-25  8:46 ` walter harms [this message]
2018-01-25  8:46   ` walter harms

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5A69994D.5070802@bfs.de \
    --to=wharms@bfs.de \
    --cc=arvind.yadav.cs@gmail.com \
    --cc=bhumirks@gmail.com \
    --cc=chrisadr@gentoo.org \
    --cc=dean@sensoray.com \
    --cc=hans.verkuil@cisco.com \
    --cc=keescook@chromium.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.