Re: [PATCH] SCSI: Use is_power_of_2() macro for simplicity.

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

 



On Tue, Nov 06, 2007 at 11:09:51AM -0500, Robert P. J. Day wrote:
> > >  		bits &= ~esp->scsi_id_mask;
> > > -		if (!bits || (bits & (bits - 1)))
> > > +		if (!is_power_of_2(bits))
> > >  			goto do_reset;
> >
> > Non-equivalent transform.  Definitely a bug.
> 
> ok, that one i'm curious about.  how is that not an equivalent
> transform?  am i missing something painfully obvious?

Apologies, I got my boolean algebra wrong.  It is equivalent:

bool is_power_of_2(unsigned long n)
        return (n != 0 && ((n & (n - 1)) == 0));

substitute it in:

		if (!is_power_of_2(bits))

		if (!(bits != 0 && ((bits & (bits - 1)) == 0)))

push the ! inside brackets:

		if (bits == 0 || ((bits & (bits - 1)) != 0))

> > > -		if (!bits || (bits & (bits - 1)))

Clearly the same thing.  Still ... I don't like it because we're not
really looking for 'is this a power of two', we want to know 'is there
exactly one bit set'.  Which, after a bit of thinking, is the same
thing, but it's a bad name for this usage.  Perhaps we could add

#define exactly_one_bit_set is_power_of_2

to the header file.

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux