public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix roundup_pow_of_two(1)
@ 2007-05-17 21:56 Rolf Eike Beer
  2007-06-04 11:49 ` Adrian Bunk
  0 siblings, 1 reply; 5+ messages in thread
From: Rolf Eike Beer @ 2007-05-17 21:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Andrew Morton, stable

Fix roundup_pow_of_two(1)

1 is a power of two, therefore roundup_pow_of_two(1) should return 1. It does
in case the argument is a variable but in case it's a constant it behaves
wrong and returns 0. Probably nobody ever did it so this was never noticed.

Signed-off-by: Rolf Eike Beer <eike-kernel@sf-tec.de>

---
commit 01ceeffac83011f0b5021013cc4abd1c4f291df5
tree 7da59df51617d7cebd55e4361019181645a17e10
parent ab35916f807eb4f2019a208e96cb0bddbb91dfc3
author Rolf Eike Beer <eike-kernel@sf-tec.de> Thu, 17 May 2007 23:43:54 +0200
committer Rolf Eike Beer <eike-kernel@sf-tec.de> Thu, 17 May 2007 23:43:54 +0200

 include/linux/log2.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/linux/log2.h b/include/linux/log2.h
index 57e641e..1b8a2c1 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -159,7 +159,7 @@ unsigned long __roundup_pow_of_two(unsigned long n)
 #define roundup_pow_of_two(n)			\
 (						\
 	__builtin_constant_p(n) ? (		\
-		(n == 1) ? 0 :			\
+		(n == 1) ? 1 :			\
 		(1UL << (ilog2((n) - 1) + 1))	\
 				   ) :		\
 	__roundup_pow_of_two(n)			\

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

* Re: [PATCH] Fix roundup_pow_of_two(1)
  2007-05-17 21:56 [PATCH] Fix roundup_pow_of_two(1) Rolf Eike Beer
@ 2007-06-04 11:49 ` Adrian Bunk
  2007-06-04 12:13   ` Rolf Eike Beer
  2007-06-04 12:33   ` Jiri Kosina
  0 siblings, 2 replies; 5+ messages in thread
From: Adrian Bunk @ 2007-06-04 11:49 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: linux-kernel, Linus Torvalds, Andrew Morton, stable

On Thu, May 17, 2007 at 11:56:56PM +0200, Rolf Eike Beer wrote:
> Fix roundup_pow_of_two(1)
> 
> 1 is a power of two, therefore roundup_pow_of_two(1) should return 1. It does
> in case the argument is a variable but in case it's a constant it behaves
> wrong and returns 0. Probably nobody ever did it so this was never noticed.

I'm not getting the problem.
2^0 = 1

> Signed-off-by: Rolf Eike Beer <eike-kernel@sf-tec.de>
> 
> ---
> commit 01ceeffac83011f0b5021013cc4abd1c4f291df5
> tree 7da59df51617d7cebd55e4361019181645a17e10
> parent ab35916f807eb4f2019a208e96cb0bddbb91dfc3
> author Rolf Eike Beer <eike-kernel@sf-tec.de> Thu, 17 May 2007 23:43:54 +0200
> committer Rolf Eike Beer <eike-kernel@sf-tec.de> Thu, 17 May 2007 23:43:54 +0200
> 
>  include/linux/log2.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/log2.h b/include/linux/log2.h
> index 57e641e..1b8a2c1 100644
> --- a/include/linux/log2.h
> +++ b/include/linux/log2.h
> @@ -159,7 +159,7 @@ unsigned long __roundup_pow_of_two(unsigned long n)
>  #define roundup_pow_of_two(n)			\
>  (						\
>  	__builtin_constant_p(n) ? (		\
> -		(n == 1) ? 0 :			\
> +		(n == 1) ? 1 :			\
>  		(1UL << (ilog2((n) - 1) + 1))	\
>  				   ) :		\
>  	__roundup_pow_of_two(n)			\

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


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

* Re: [PATCH] Fix roundup_pow_of_two(1)
  2007-06-04 11:49 ` Adrian Bunk
@ 2007-06-04 12:13   ` Rolf Eike Beer
  2007-06-04 13:17     ` Adrian Bunk
  2007-06-04 12:33   ` Jiri Kosina
  1 sibling, 1 reply; 5+ messages in thread
From: Rolf Eike Beer @ 2007-06-04 12:13 UTC (permalink / raw)
  To: Adrian Bunk; +Cc: linux-kernel, Linus Torvalds, Andrew Morton, stable

[-- Attachment #1: Type: text/plain, Size: 450 bytes --]

Adrian Bunk wrote:
> On Thu, May 17, 2007 at 11:56:56PM +0200, Rolf Eike Beer wrote:
> > Fix roundup_pow_of_two(1)
> >
> > 1 is a power of two, therefore roundup_pow_of_two(1) should return 1. It
> > does in case the argument is a variable but in case it's a constant it
> > behaves wrong and returns 0. Probably nobody ever did it so this was
> > never noticed.
>
> I'm not getting the problem.
> 2^0 = 1

Yes. But it returned 0 (not 1 << 0).

Eike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH] Fix roundup_pow_of_two(1)
  2007-06-04 11:49 ` Adrian Bunk
  2007-06-04 12:13   ` Rolf Eike Beer
@ 2007-06-04 12:33   ` Jiri Kosina
  1 sibling, 0 replies; 5+ messages in thread
From: Jiri Kosina @ 2007-06-04 12:33 UTC (permalink / raw)
  To: Adrian Bunk
  Cc: Rolf Eike Beer, linux-kernel, Linus Torvalds, Andrew Morton,
	stable

On Mon, 4 Jun 2007, Adrian Bunk wrote:

> > 1 is a power of two, therefore roundup_pow_of_two(1) should return 1. It does
> > in case the argument is a variable but in case it's a constant it behaves
> > wrong and returns 0. Probably nobody ever did it so this was never noticed.
> I'm not getting the problem.
> 2^0 = 1

Adrian,

that's of course true, but unrelated to the patch in question :)

You simply want roundup_pow_of_two(1) to be 1, and not 0. That's what the 
patch does, and that's correct.

-- 
Jiri Kosina

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

* Re: [PATCH] Fix roundup_pow_of_two(1)
  2007-06-04 12:13   ` Rolf Eike Beer
@ 2007-06-04 13:17     ` Adrian Bunk
  0 siblings, 0 replies; 5+ messages in thread
From: Adrian Bunk @ 2007-06-04 13:17 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: linux-kernel, Linus Torvalds, Andrew Morton, stable

On Mon, Jun 04, 2007 at 02:13:11PM +0200, Rolf Eike Beer wrote:
> Adrian Bunk wrote:
> > On Thu, May 17, 2007 at 11:56:56PM +0200, Rolf Eike Beer wrote:
> > > Fix roundup_pow_of_two(1)
> > >
> > > 1 is a power of two, therefore roundup_pow_of_two(1) should return 1. It
> > > does in case the argument is a variable but in case it's a constant it
> > > behaves wrong and returns 0. Probably nobody ever did it so this was
> > > never noticed.
> >
> > I'm not getting the problem.
> > 2^0 = 1
> 
> Yes. But it returned 0 (not 1 << 0).

Sorry, I had a thinko and you are right.

> Eike

cu
Adrian

-- 

       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed


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

end of thread, other threads:[~2007-06-04 13:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-17 21:56 [PATCH] Fix roundup_pow_of_two(1) Rolf Eike Beer
2007-06-04 11:49 ` Adrian Bunk
2007-06-04 12:13   ` Rolf Eike Beer
2007-06-04 13:17     ` Adrian Bunk
2007-06-04 12:33   ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox