All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, Dmitry Torokhov <dtor@vmware.com>
Subject: [08/16] linux/log2.h: Fix rounddown_pow_of_two(1)
Date: Fri, 16 Dec 2011 12:49:41 -0800	[thread overview]
Message-ID: <20111216205043.042482736@clark.kroah.org> (raw)
In-Reply-To: <20111216205049.GA28030@kroah.com>

2.6.32-longterm review patch.  If anyone has any objections, please let me know.

------------------

From: Linus Torvalds <torvalds@linux-foundation.org>

commit 13c07b0286d340275f2d97adf085cecda37ede37 upstream.

Exactly like roundup_pow_of_two(1), the rounddown version was buggy for
the case of a compile-time constant '1' argument.  Probably because it
originated from the same code, sharing history with the roundup version
from before the bugfix (for that one, see commit 1a06a52ee1b0: "Fix
roundup_pow_of_two(1)").

However, unlike the roundup version, the fix for rounddown is to just
remove the broken special case entirely.  It's simply not needed - the
generic code

    1UL << ilog2(n)

does the right thing for the constant '1' argment too.  The only reason
roundup needed that special case was because rounding up does so by
subtracting one from the argument (and then adding one to the result)
causing the obvious problems with "ilog2(0)".

But rounddown doesn't do any of that, since ilog2() naturally truncates
(ie "rounds down") to the right rounded down value.  And without the
ilog2(0) case, there's no reason for the special case that had the wrong
value.

tl;dr: rounddown_pow_of_two(1) should be 1, not 0.

Acked-by: Dmitry Torokhov <dtor@vmware.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 include/linux/log2.h |    1 -
 1 file changed, 1 deletion(-)

--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -185,7 +185,6 @@ unsigned long __rounddown_pow_of_two(uns
 #define rounddown_pow_of_two(n)			\
 (						\
 	__builtin_constant_p(n) ? (		\
-		(n == 1) ? 0 :			\
 		(1UL << ilog2(n))) :		\
 	__rounddown_pow_of_two(n)		\
  )



  parent reply	other threads:[~2011-12-16 20:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 20:50 [00/16] 2.6.32.51-longterm review Greg KH
2011-12-16 20:49 ` [01/16] ALSA: sis7019 - give slow codecs more time to reset Greg KH
2011-12-16 20:49 ` [02/16] ALSA: hda/realtek - Fix Oops in alc_mux_select() Greg KH
2011-12-16 20:49 ` [03/16] ARM: davinci: dm646x evm: wrong register used in setup_vpif_input_channel_mode Greg KH
2011-12-16 20:49 ` [04/16] oprofile: Free potentially owned tasks in case of errors Greg KH
2011-12-16 20:49 ` [05/16] oprofile: Fix locking dependency in sync_start() Greg KH
2011-12-16 20:49 ` [06/16] percpu: fix chunk range calculation Greg KH
2011-12-16 20:49 ` [07/16] xfrm: Fix key lengths for rfc3686(ctr(aes)) Greg KH
2011-12-16 20:49   ` Greg KH
2011-12-16 20:49 ` Greg KH [this message]
2011-12-16 20:49 ` [09/16] jbd/jbd2: validate sb->s_first in journal_get_superblock() Greg KH
2011-12-16 20:49 ` [10/16] Make TASKSTATS require root access Greg KH
2011-12-16 20:49 ` [11/16] hfs: fix hfs_find_init() sb->ext_tree NULL ptr oops Greg KH
2011-12-16 20:49 ` [12/16] export __get_user_pages_fast() function Greg KH
2011-12-16 20:49 ` [13/16] [PATCH 2/3] oprofile, x86: Fix nmi-unsafe callgraph support Greg KH
2011-12-18 16:04   ` Robert Richter
2011-12-22 20:37     ` Greg KH
2011-12-16 20:49 ` [14/16] [PATCH 3/3] oprofile, x86: Fix crash when unloading module (timer mode) Greg KH
2011-12-16 20:49 ` [15/16] ext4: avoid hangs in ext4_da_should_update_i_disksize() Greg KH
2011-12-16 20:49 ` [16/16] USB: cdc-acm: add IDs for Motorola H24 HSPA USB module Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111216205043.042482736@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=dtor@vmware.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.