From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Andrew Morton <akpm@linux-foundation.org>,
Yury Norov <ynorov@caviumnetworks.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/7] linux/bitmap.h: handle constant zero-size bitmaps correctly
Date: Sat, 18 Aug 2018 15:16:18 +0200 [thread overview]
Message-ID: <20180818131623.8755-3-linux@rasmusvillemoes.dk> (raw)
In-Reply-To: <20180818131623.8755-1-linux@rasmusvillemoes.dk>
The static inlines in bitmap.h do not handle a compile-time constant
nbits==0 correctly (they dereference the passed src or dst pointers,
despite only 0 words being valid to access). I had the 0-day buildbot
chew on a patch [1] that would cause build failures for such cases
without complaining, suggesting that we don't have any such users
currently, at least for the 70 .config/arch combinations that was
built. Should any turn up, make sure they use the out-of-line versions,
which do handle nbits==0 correctly.
This is of course not the most efficient, but it's much less churn than
teaching all the static inlines an "if (zero_const_nbits())", and since
we don't have any current instances, this doesn't affect existing code
at all.
[1] lkml.kernel.org/r/20180815085539.27485-1-linux@rasmusvillemoes.dk
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/bitmap.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 1ee46f492267..b91a6b5d3e78 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -196,8 +196,13 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf,
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
+/*
+ * The static inlines below do not handle constant nbits==0 correctly,
+ * so make such users (should any ever turn up) call the out-of-line
+ * versions.
+ */
#define small_const_nbits(nbits) \
- (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
+ (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0)
static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
{
--
2.16.4
next prev parent reply other threads:[~2018-08-18 13:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-18 13:16 [PATCH 0/7] assorted minor bitmap patches Rasmus Villemoes
2018-08-18 13:16 ` [PATCH 1/7] lib/bitmap.c: remove wrong documentation Rasmus Villemoes
2018-08-18 13:16 ` Rasmus Villemoes [this message]
2018-08-18 13:16 ` [PATCH 3/7] linux/bitmap.h: remove redundant uses of small_const_nbits() Rasmus Villemoes
2018-08-18 13:16 ` [PATCH 4/7] linux/bitmap.h: fix type of nbits in bitmap_shift_right() Rasmus Villemoes
2018-08-18 13:16 ` [PATCH 5/7] linux/bitmap.h: relax comment on compile-time constant nbits Rasmus Villemoes
2018-09-04 11:08 ` Yury Norov
2018-09-04 11:30 ` Andy Shevchenko
2018-09-04 11:45 ` Rasmus Villemoes
2018-08-18 13:16 ` [PATCH 6/7] lib/bitmap.c: fix remaining space computation in bitmap_print_to_pagebuf Rasmus Villemoes
2018-08-19 12:37 ` Andy Shevchenko
2018-08-20 7:36 ` Rasmus Villemoes
2018-08-18 13:16 ` [PATCH 7/7] lib/bitmap.c: simplify bitmap_print_to_pagebuf Rasmus Villemoes
2018-08-19 12:39 ` [PATCH 0/7] assorted minor bitmap patches Andy Shevchenko
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=20180818131623.8755-3-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ynorov@caviumnetworks.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).