lkml.org 
[lkml]   [2019]   [Feb]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [PATCH 05/32] locking/lockdep: Prepare valid_state() to handle plain masks
    On Tue, Feb 12, 2019 at 9:14 AM Frederic Weisbecker <frederic@kernel.org> wrote:
    >
    > +
    > + while (vectors) {
    > + long fs = __ffs64(vectors) + 1;
    > +
    > + vectors >>= fs;

    This is wrong.

    If "vectors" only has the high hit set, you end up with "fs" having
    the value "64".

    And then "vectors >>= fs" is undefined and won't actually do anything
    at all on x86.

    In general, avoid "ffs()", and the stupid pattern of "__ffs(x)+1".

    Bit numbering starts at 0. "ffs()" is wrong. And you never *ever* just
    add one to a bit number in order to shift by one more bit, exactly
    because of overflow issues.

    So it may look inefficient, but the correct thing to do is

    long bit = __ffs64(vectors);
    vectors >>= fs;
    vectors >>= 1;

    because that actually works.

    Linus

    \
     
     \ /
      Last update: 2019-02-12 18:47    [W:4.420 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site