[PATCH] Fix calculus of bitmap_scnprintf_len() - Kernel

This is a discussion on [PATCH] Fix calculus of bitmap_scnprintf_len() - Kernel ; The function bitmap_scnprintf_len() is currently not used, but the returned value is 4 times larger than needed. This value is also only a good upper bound. Which should be mentioned in the comment. The correct number of chars needed for ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: [PATCH] Fix calculus of bitmap_scnprintf_len()

  1. [PATCH] Fix calculus of bitmap_scnprintf_len()

    The function bitmap_scnprintf_len() is currently not used, but the returned
    value is 4 times larger than needed. This value is also only a good upper
    bound. Which should be mentioned in the comment.

    The correct number of chars needed for the buffer, exluding any new line and
    terminating zero is:

    int bitmap_scnprintf_len(int len)
    {
    return /* complete hunks with commas */
    ((len / CHUNKSZ) * 9)
    /* partial hunk, 4 bits in one char */
    + (((len % CHUNKSZ) + 3) / 4)
    /* one less comma, if no partial hunk */
    - !(len % CHUNKSZ);
    }

    Signed-off-by: Bert Wesarg
    Cc: Mike Travis
    Cc: Paul Jackson

    ---
    lib/bitmap.c | 2 +-
    1 files changed, 1 insertions(+), 1 deletions(-)

    diff --git a/lib/bitmap.c b/lib/bitmap.c
    index a6939e1..47e6f0f 100644
    --- a/lib/bitmap.c
    +++ b/lib/bitmap.c
    @@ -325,7 +325,7 @@ int bitmap_scnprintf_len(unsigned int len)
    /* we need 9 chars per word for 32 bit words (8 hexdigits + sep/null) */
    int bitslen = ALIGN(len, CHUNKSZ);
    int wordlen = CHUNKSZ / 4;
    - int buflen = (bitslen / wordlen) * (wordlen + 1) * sizeof(char);
    + int buflen = (bitslen / CHUNKSZ) * (wordlen + 1);

    return buflen;
    }
    --
    1.5.4

    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  2. Re: [PATCH] Fix calculus of bitmap_scnprintf_len()

    Bert wrote:
    > The function bitmap_scnprintf_len() is currently not used


    How about we just remove that function?

    --
    I won't rest till it's the best ...
    Programmer, Linux Scalability
    Paul Jackson 1.940.382.4214
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  3. Re: [PATCH] Fix calculus of bitmap_scnprintf_len()

    On Sun, 27 Apr 2008, Paul Jackson wrote:

    > Bert wrote:
    >> The function bitmap_scnprintf_len() is currently not used

    >
    > How about we just remove that function?


    I am afraid no. See:

    include/linux/cpumask.h:292: return bitmap_scnprintf_len(len);

    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  4. Re: [PATCH] Fix calculus of bitmap_scnprintf_len()

    Bert wrote:
    > The function bitmap_scnprintf_len() is currently not used


    Paul Jackson wrote:
    > How about we just remove that function?


    WANG Cong wrote:
    > I am afraid no. See:
    >
    > include/linux/cpumask.h:292: return bitmap_scnprintf_len(len);


    Good point.


    Then how about we also remove from cpumask.h:

    #define cpumask_scnprintf_len(len) \
    __cpumask_scnprintf_len((len))
    static inline int __cpumask_scnprintf_len(int len)
    {
    return bitmap_scnprintf_len(len);
    }

    --
    I won't rest till it's the best ...
    Programmer, Linux Scalability
    Paul Jackson 1.940.382.4214
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  5. Re: [PATCH] Fix calculus of bitmap_scnprintf_len()

    Paul Jackson wrote:
    > Bert wrote:
    >> The function bitmap_scnprintf_len() is currently not used

    >
    > Paul Jackson wrote:
    >> How about we just remove that function?

    >
    > WANG Cong wrote:
    >> I am afraid no. See:
    >>
    >> include/linux/cpumask.h:292: return bitmap_scnprintf_len(len);

    >
    > Good point.
    >
    >
    > Then how about we also remove from cpumask.h:
    >
    > #define cpumask_scnprintf_len(len) \
    > __cpumask_scnprintf_len((len))
    > static inline int __cpumask_scnprintf_len(int len)
    > {
    > return bitmap_scnprintf_len(len);
    > }
    >


    That's fine with me. A later version of the patch did have
    the function removed but it didn't get picked up. The other
    changes there were to use function pointers instead of the
    flag variable to select list or mask output format, and the
    addition of mask variants for the cpu/{present,possible,
    online,system} map outputs.

    I'll dig that one back up and resubmit it.

    Thanks,
    Mike
    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  6. Re: [PATCH] Fix calculus of bitmap_scnprintf_len()

    On Mon, Apr 28, 2008 at 7:09 PM, Mike Travis wrote:
    > Paul Jackson wrote:
    > > Bert wrote:
    > >> The function bitmap_scnprintf_len() is currently not used

    > >
    > > Paul Jackson wrote:
    > >> How about we just remove that function?

    > >
    > > WANG Cong wrote:
    > >> I am afraid no. See:
    > >>
    > >> include/linux/cpumask.h:292: return bitmap_scnprintf_len(len);

    > >
    > > Good point.
    > >
    > >
    > > Then how about we also remove from cpumask.h:
    > >
    > > #define cpumask_scnprintf_len(len) \
    > > __cpumask_scnprintf_len((len))
    > > static inline int __cpumask_scnprintf_len(int len)
    > > {
    > > return bitmap_scnprintf_len(len);
    > > }
    > >

    >
    > That's fine with me. A later version of the patch did have
    > the function removed but it didn't get picked up. The other
    > changes there were to use function pointers instead of the
    > flag variable to select list or mask output format, and the
    > addition of mask variants for the cpu/{present,possible,
    > online,system} map outputs.

    I'm fine with this too. I did a hasty audit of cpumask_scnprintf()
    users, and no one can use these functions.

    But one last note to the cpumask_scnprintf_len() macro: this macro
    should really not have an argument, it should be forced to NR_CPUS.
    Else a user could have a too small buffer for the call to
    cpumask_scnprintf(), which always calls bitmap_scnprintf() with
    NR_CPUS nbits.

    >
    > I'll dig that one back up and resubmit it.

    Fine.

    Regards.
    Bert
    >
    > Thanks,
    > Mike
    >

    --
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

+ Reply to Thread