linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Christophe JAILLET
	<christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>,
	mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	dennis.dalessandro-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit.
Date: Fri, 26 Aug 2016 15:34:48 -0400	[thread overview]
Message-ID: <e86e76dc-811b-7002-a35d-1e515c833d46@redhat.com> (raw)
In-Reply-To: <20160826192957.GG594-2ukJVAZIZ/Y@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 1726 bytes --]

On 8/26/2016 3:29 PM, Leon Romanovsky wrote:
> On Fri, Aug 26, 2016 at 02:01:55PM -0400, Doug Ledford wrote:
>> 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.
> 
> There is BITS_PER_LONG define for that. There is actual use of it in mlx5 for
> the similar code pieces.

BITS_PER_LONG only works if your bitfield is a single long.  It doesn't
work for other bitfields.  What I posted above will work for anything.


-- 
Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
    GPG Key ID: 0E572FDD


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 884 bytes --]

  parent reply	other threads:[~2016-08-26 19:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-26  4:49 [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit Christophe JAILLET
     [not found] ` <1472186949-9025-1-git-send-email-christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
2016-08-26 13:35   ` Doug Ledford
2016-08-26 18:01     ` Doug Ledford
2016-08-26 19:29       ` Leon Romanovsky
     [not found]         ` <20160826192957.GG594-2ukJVAZIZ/Y@public.gmane.org>
2016-08-26 19:34           ` Doug Ledford [this message]
2016-08-28  6:06             ` Leon Romanovsky
     [not found]               ` <20160828060640.GI594-2ukJVAZIZ/Y@public.gmane.org>
2016-09-02 14:39                 ` Doug Ledford
2016-09-04  9:04                   ` Leon Romanovsky
2016-08-27  5:25     ` Christophe JAILLET
     [not found]       ` <d3eea048-5c7e-a5e9-900b-fabf0f6e38c8-39ZsbGIQGT5GWvitb5QawA@public.gmane.org>
2016-09-02 17:11         ` Doug Ledford

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=e86e76dc-811b-7002-a35d-1e515c833d46@redhat.com \
    --to=dledford-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=christophe.jaillet-39ZsbGIQGT5GWvitb5QawA@public.gmane.org \
    --cc=dennis.dalessandro-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.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 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).