Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1470920

Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit.

From Doug Ledford <dledford@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit.
Date 2016-08-26 20:10 +0200
Message-ID <satJM-22D-19@gated-at.bofh.it> (permalink)
References <sahpf-2mA-7@gated-at.bofh.it> <sapwu-7EL-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 8/26/2016 9:35 AM, Doug Ledford wrote:
> On 8/26/2016 12:49 AM, Christophe JAILLET wrote:
>> The 2nd parameter of 'find_first_bit' is the number of bits to search.
>> In this case, we are passing 'sizeof(unsigned long)' which is likely to
>> be 4 or 8.
> 
> If the size can be 4 or 8, then using 64 universally is not correct.
> Why not use sizeof() * 8 (or << 3)?

Better yet, why not put this patch in the kernel first:

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d96a6118d26a..a8838c87668e 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -52,6 +52,8 @@

 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) +
__must_be_array(arr))

+#define bitsizeof(x)   (sizeof((x)) << 3)
+
 #define u64_to_user_ptr(x) (           \
 {                                      \
        typecheck(u64, x);              \

then start going around replacing all these hard coded numbers with the
use of bitsizeof().  It can be applied not just to the find_first*bit()
routines, but to a bunch of other routines too.  Just look at
include/linux/bitmap.h and any that have nbits as an argument are
candidates.


-- 
Doug Ledford <dledford@redhat.com>
    GPG Key ID: 0E572FDD

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-08-26 07:00 +0200
  Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-08-26 15:40 +0200
    Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-08-26 20:10 +0200
      Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-08-26 21:40 +0200
        Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Leon Romanovsky <leon@kernel.org> - 2016-08-28 08:10 +0200
          Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-09-02 16:40 +0200
            Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Leon Romanovsky <leon@kernel.org> - 2016-09-04 11:10 +0200
      Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Leon Romanovsky <leon@kernel.org> - 2016-08-26 21:40 +0200
    Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2016-08-27 07:30 +0200
      Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. Doug Ledford <dledford@redhat.com> - 2016-09-02 19:20 +0200

csiph-web