[PATCH 5/5] Staging: panel: Make statement more readable

Willy Tarreau w at 1wt.eu
Sat Jan 2 06:53:12 UTC 2016


Hi Ksenija,

several points, see below.

On Tue, Dec 29, 2015 at 09:11:03PM +0100, Ksenija Stanojevic wrote:
> Broke statement into 3 different lines to make it more readable.
> 
> Signeded-off-by: Ksenija Stanojevic <ksenija.stanojevic at gmail.com>
        ^^
Extra "ed". Don't waste your time typing it by hand, several git commands
(including git-commit and git-format-patch) will do it for you when you
pass "-s".

> diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
> index 70cb9f3..207d8d5 100644
> --- a/drivers/staging/panel/panel.c
> +++ b/drivers/staging/panel/panel.c
> @@ -2054,8 +2054,8 @@ static u8 input_name2mask(const char *name, __u64 *mask, __u64 *value,
>  	while (*name) {
>  		int in, out, bit, neg;
>  
> -		for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name);
> -		     in++)
> +		for (in = 0;
> +		    (in < sizeof(sigtab)) && (sigtab[in] != *name); in++)
>  			;
>  
>  		if (in >= sizeof(sigtab))

well, this one is still ugly in my opinion. I've just looked at the code
and it was crap originally :
  - sigtab[] is declared as static and without a trailing zero
  - the for loop uses extra parenthesis and basically only reimplements
    strchr()
  - the end condition is tested again after the for loop

=> I'd rather use strchr(), and clean up this part, approx like this, but
   do it as you want :

-       static char sigtab[10] = "EeSsPpAaBb";
+       const char sigtab[] = "EeSsPpAaBb";
...
 	while (*name) {
 		int in, out, bit, neg;
+		const char *idx;
 
-		for (in = 0; (in < sizeof(sigtab)) && (sigtab[in] != *name);
-		     in++)
-
-		if (in >= sizeof(sigtab))
-			return 0;
+		idx = strchr(sigtab, *name);
+		if (!idx)
+			return 0;
+
+		in = idx - sigtab;
 
I think it's more readable this way.

Regards,
Willy



More information about the devel mailing list