Re: Unify module.*

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

 



>I really did not like this part:
>#ifdef CONFIG_SPARC64
>                BUG_ON(((u64)location >> (u64)32) != (u64)0);
>#endif /* CONFIG_SPARC64 */
>
>I think it should be safe to do:
>
>		BUG_ON(((unsigned long)location >> (unsigned long)32) !=
>		       (unsigned long)0);

No, you can't safely shift a 32-bit value by 32 bits (the compiler
is allowed to turn this into a shift of 0 bits for instance, by
using a 5-bit mask for the shift distance).  However it should be
safe to do this, which is exactly the same in practice:

		BUG_ON((((unsigned long)location >> 31) >> 1) !=
		       (unsigned long)0);

>But I did not really see the point of the BUG_ON in the first place,
>and my limited digging did not turn up when it was added.

Not sure who uses it and why it was added, but it's equivalent to:

	BUG_ON((unsigned long)location > 0xffffffff);

which I personally prefer to the shift version -- I think it makes
the intent more obvious -- but this might still draw a warning about
being always-false on 32-bit.  Of course, if gcc gets any smarter,
so might the shift version.

Chris
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Kernel Development]     [DCCP]     [Linux ARM Development]     [Linux]     [Photo]     [Yosemite Help]     [Linux ARM Kernel]     [Linux SCSI]     [Linux x86_64]     [Linux Hams]

  Powered by Linux