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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
        ^^
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

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux