Subject: Re: [PATCH] ATM: misplaced parentheses?

From: Al Viro <[email-masked]>
Date: Mon, 16 Feb 2009 22:30:01 +0000

On Mon, Feb 16, 2009 at 05:02:36PM -0500, Chas Williams (CONTRACTOR) wrote:
> that doesnt seem to make sense either.  the original code
> is:
> 
>  		for (i = 128; i != 0; i >>= 1) {   /* write command out */
> ...
>  			tmp = (lanai->conf1 & ~CONFIG1_PROMDATA) |
> 			    (data & i) ? CONFIG1_PROMDATA : 0;
> 
> since i is always positive here, you wouldnt need the ?: if your suggested
> fix is the original intent.  it looks like setting CONFIG1_PROMDATA
> means '1' and not setting it means '0' when writing the value of data
> to the register.

What the hell does it have to do with i being positive?  || variant is,
of course, silly; it's very obvious what's going on here.  Garden-variety
bit-banging, IOW
  			tmp = (lanai->conf1 & ~CONFIG1_PROMDATA) |
 			    ((data & i) ? CONFIG1_PROMDATA : 0);
and while you technically only need parens around ?:, in this case it's
better to keep it fully parenthesised - more readable that way.

The lack of parens around ?: in the current tree is an obvious bug.