LKML Archive on
 help / color / Atom feed
From: "Gustavo A. R. Silva" <>
To: William Breathitt Gray <>,
	Andrew Morton <>,
	Stephen Rothwell <>
	"Gustavo A. R. Silva" <>
Subject: [PATCH] linux/bitmap.h: fix potential sign-extension overflow
Date: Tue, 15 Oct 2019 13:46:57 -0500
Message-ID: <20191015184657.GA26541@embeddedor> (raw)

In expression 0xff << offset, left shifting by more than 31 bits has
undefined behavior. Notice that the shift amount, *offset*, can be as
much as 63.

Fix this by adding suffix ULL to integer 0xFF.

Addresses-Coverity: 1487071 ("Bad bit shift operation")
Fixes: d33f5cbaadd8 ("bitops: introduce the for_each_set_clump8 macro")
Signed-off-by: Gustavo A. R. Silva <>
 include/linux/bitmap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 942871bfe47e..96f91db25b06 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -520,7 +520,7 @@ static inline void bitmap_set_value8(unsigned long *map, unsigned long value,
 	const size_t index = BIT_WORD(start);
 	const unsigned long offset = start % BITS_PER_LONG;
-	map[index] &= ~(0xFF << offset);
+	map[index] &= ~(0xFFULL << offset);
 	map[index] |= value << offset;

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-15 18:46 Gustavo A. R. Silva [this message]
2019-10-15 19:44 ` Joe Perches

Reply instructions:

You may reply publically 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:

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

  git send-email \
    --in-reply-to=20191015184657.GA26541@embeddedor \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on

Archives are clonable:
	git clone --mirror lkml/git/0.git
	git clone --mirror lkml/git/1.git
	git clone --mirror lkml/git/2.git
	git clone --mirror lkml/git/3.git
	git clone --mirror lkml/git/4.git
	git clone --mirror lkml/git/5.git
	git clone --mirror lkml/git/6.git
	git clone --mirror lkml/git/7.git
	git clone --mirror lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ \
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone