From: William Breathitt Gray <vilhelm.gray@gmail.com>
To: Syed Nayyar Waris <syednwaris@gmail.com>
Cc: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
arnd@arndb.de, linux-arch@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] bitmap: Modify bitmap_set_value() to check bitmap length
Date: Fri, 20 Nov 2020 12:59:09 -0500 [thread overview]
Message-ID: <X7gD7Q/63qoUuGpi@shinobu> (raw)
In-Reply-To: <b2011fb2e0438bdfd0b663b9f0456d0aef20f04b.1605893642.git.syednwaris@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3980 bytes --]
On Fri, Nov 20, 2020 at 11:14:16PM +0530, Syed Nayyar Waris wrote:
> Add explicit check to see if the value being written into the bitmap
> does not fall outside the bitmap.
> The situation that it is falling outside would never be possible in the
> code because the boundaries are required to be correct before the function
> is called. The responsibility is on the caller for ensuring the boundaries
> are correct.
> This is just to suppress the GCC -Wtype-limits warnings.
Hi Syed,
This commit message sounds a bit strange without the context of our
earlier discussion thread. Would you be able to reword the commit
message to explain the motivation for using __builtin_unreachable()?
Thanks,
William Breathitt Gray
>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com>
> Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com>
> ---
> include/linux/bitmap.h | 35 +++++++++++++++++++++--------------
> 1 file changed, 21 insertions(+), 14 deletions(-)
>
> diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
> index 386d08777342..efb6199ea1e7 100644
> --- a/include/linux/bitmap.h
> +++ b/include/linux/bitmap.h
> @@ -78,8 +78,9 @@
> * bitmap_get_value(map, start, nbits) Get bit value of size
> * 'nbits' from map at start
> * bitmap_set_value8(map, value, start) Set 8bit value to map at start
> - * bitmap_set_value(map, value, start, nbits) Set bit value of size 'nbits'
> - * of map at start
> + * bitmap_set_value(map, nbits, value, value_width, start)
> + * Set bit value of size value_width
> + * to map at start
> *
> * Note, bitmap_zero() and bitmap_fill() operate over the region of
> * unsigned longs, that is, bits behind bitmap till the unsigned long
> @@ -610,30 +611,36 @@ static inline void bitmap_set_value8(unsigned long *map, unsigned long value,
> }
>
> /**
> - * bitmap_set_value - set n-bit value within a memory region
> + * bitmap_set_value - set value within a memory region
> * @map: address to the bitmap memory region
> - * @value: value of nbits
> - * @start: bit offset of the n-bit value
> - * @nbits: size of value in bits (must be between 1 and BITS_PER_LONG inclusive).
> + * @nbits: size of map in bits
> + * @value: value of clump
> + * @value_width: size of value in bits (must be between 1 and BITS_PER_LONG inclusive)
> + * @start: bit offset of the value
> */
> -static inline void bitmap_set_value(unsigned long *map,
> - unsigned long value,
> - unsigned long start, unsigned long nbits)
> +static inline void bitmap_set_value(unsigned long *map, unsigned long nbits,
> + unsigned long value, unsigned long value_width,
> + unsigned long start)
> {
> - const size_t index = BIT_WORD(start);
> + const unsigned long index = BIT_WORD(start);
> + const unsigned long length = BIT_WORD(nbits);
> const unsigned long offset = start % BITS_PER_LONG;
> const unsigned long ceiling = round_up(start + 1, BITS_PER_LONG);
> const unsigned long space = ceiling - start;
>
> - value &= GENMASK(nbits - 1, 0);
> + value &= GENMASK(value_width - 1, 0);
>
> - if (space >= nbits) {
> - map[index] &= ~(GENMASK(nbits - 1, 0) << offset);
> + if (space >= value_width) {
> + map[index] &= ~(GENMASK(value_width - 1, 0) << offset);
> map[index] |= value << offset;
> } else {
> map[index + 0] &= ~BITMAP_FIRST_WORD_MASK(start);
> map[index + 0] |= value << offset;
> - map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits);
> +
> + if (index + 1 >= length)
> + __builtin_unreachable();
> +
> + map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + value_width);
> map[index + 1] |= value >> space;
> }
> }
> --
> 2.29.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-11-20 17:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 17:42 [PATCH 0/4] Modify bitmap_set_value() to suppress compiler warning Syed Nayyar Waris
2020-11-20 17:44 ` [PATCH 1/4] bitmap: Modify bitmap_set_value() to check bitmap length Syed Nayyar Waris
2020-11-20 17:59 ` William Breathitt Gray [this message]
2020-11-20 18:02 ` Syed Nayyar Waris
2020-11-20 18:43 ` [RESEND PATCH " Syed Nayyar Waris
2020-11-20 17:45 ` [PATCH 2/4] lib/test_bitmap.c: Modify for_each_set_clump test Syed Nayyar Waris
2020-11-20 18:44 ` [RESEND PATCH " Syed Nayyar Waris
2020-11-20 17:46 ` [PATCH 3/4] gpio: xilinx: Modify bitmap_set_value() calls Syed Nayyar Waris
2020-11-20 18:45 ` [RESEND PATCH " Syed Nayyar Waris
2020-12-01 15:33 ` Bartosz Golaszewski
2020-12-12 9:39 ` Syed Nayyar Waris
2020-11-20 17:48 ` [PATCH 4/4] gpio: xilinx: Add extra check to see if sum of widths exceed 64 Syed Nayyar Waris
2020-11-20 18:46 ` [RESEND PATCH 4/4] gpio: xilinx: Add extra check " Syed Nayyar Waris
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=X7gD7Q/63qoUuGpi@shinobu \
--to=vilhelm.gray@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syednwaris@gmail.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).