All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] use "is_power_of_2()" macro for simplicity.
@ 2007-11-07  8:03 Robert P. J. Day
  2007-11-07 12:48 ` Matthew Wilcox
  2007-11-08  6:55 ` Robert P. J. Day
  0 siblings, 2 replies; 3+ messages in thread
From: Robert P. J. Day @ 2007-11-07  8:03 UTC (permalink / raw)
  To: kernel-janitors


Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>

---

  this source file already includes log2.h for other power-of-2
operations, so might as well finish off the job.


diff --git a/kernel/kfifo.c b/kernel/kfifo.c
index bc41ad0..04a1748 100644
--- a/kernel/kfifo.c
+++ b/kernel/kfifo.c
@@ -74,7 +74,7 @@ struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask, spinlock_t *lock)
 	 * round up to the next power of 2, since our 'let the indices
 	 * wrap' tachnique works only in this case.
 	 */
-	if (size & (size - 1)) {
+	if (!is_power_of_2(size)) {
 		BUG_ON(size > 0x80000000);
 		size = roundup_pow_of_two(size);
 	}
-- 
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
====================================

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] use "is_power_of_2()" macro for simplicity.
  2007-11-07  8:03 [PATCH] use "is_power_of_2()" macro for simplicity Robert P. J. Day
@ 2007-11-07 12:48 ` Matthew Wilcox
  2007-11-08  6:55 ` Robert P. J. Day
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2007-11-07 12:48 UTC (permalink / raw)
  To: kernel-janitors

On Wed, Nov 07, 2007 at 03:03:39AM -0500, Robert P. J. Day wrote:
>  	 */
> -	if (size & (size - 1)) {
> +	if (!is_power_of_2(size)) {
>  		BUG_ON(size > 0x80000000);
>  		size = roundup_pow_of_two(size);
>  	}

Why not just delete the if?

	BUG_ON(size > 0x80000000);
	size = roundup_pow_of_two(size);

It's not a fast-path, and we'll consume a little less .text

-- 
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."

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] use "is_power_of_2()" macro for simplicity.
  2007-11-07  8:03 [PATCH] use "is_power_of_2()" macro for simplicity Robert P. J. Day
  2007-11-07 12:48 ` Matthew Wilcox
@ 2007-11-08  6:55 ` Robert P. J. Day
  1 sibling, 0 replies; 3+ messages in thread
From: Robert P. J. Day @ 2007-11-08  6:55 UTC (permalink / raw)
  To: kernel-janitors

On Wed, 7 Nov 2007, Matthew Wilcox wrote:

> On Wed, Nov 07, 2007 at 03:03:39AM -0500, Robert P. J. Day wrote:
> >  	 */
> > -	if (size & (size - 1)) {
> > +	if (!is_power_of_2(size)) {
> >  		BUG_ON(size > 0x80000000);
> >  		size = roundup_pow_of_two(size);
> >  	}
>
> Why not just delete the if?
>
> 	BUG_ON(size > 0x80000000);
> 	size = roundup_pow_of_two(size);
>
> It's not a fast-path, and we'll consume a little less .text

sure, that's doable.  i'm only reluctant to make simplifications like
that since sometimes it's visually useful to have a test there, to
perhaps make it clear that something should *normally* be a power of
two, but you want to handle the case when, occasionally, it isn't.

by taking out the test, someone reading the code might get the
impression that that value will *always* be rounded up (that is,
actually changed).  like i said, it's more a visual thing than
anything else but, if no one cares, i'll take out the test.  as you
noticed, it's entirely equivalent.

rday
-- 
====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
====================================

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-11-08  6:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-07  8:03 [PATCH] use "is_power_of_2()" macro for simplicity Robert P. J. Day
2007-11-07 12:48 ` Matthew Wilcox
2007-11-08  6:55 ` Robert P. J. Day

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.