[lkml]   [2002]   [Oct]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: Container_of considered harmful - was Re: usb storage sddr09
    On Sun, Oct 20, 2002 at 08:24:36PM +0200, Andries Brouwer wrote:
    > The oops is a dereference of fffffff0 in base/bus.c:driver_attach().
    > I have seen several such oopses lately, various places in the kernel.
    > The cause here is a NULL pointer that is turned into fffffff0 by
    > container_of() and then fed to get_device(). And get_device() tests
    > that it gets a non-NULL pointer, but that does not protect against
    > fffffff0.

    Just as an anecdote - I built a variant of container_of to protect against
    cases where NULL can creep in:

    #define test_container_of(ptr, type, member) ({ \
    const typeof( ((type *)0)->member ) *__p = (ptr); \
    __p ? container_of(__p, type, member) : NULL;})

    It calls the real container_of only if 'ptr' is not NULL.


    | Kevin O'Connor "BTW, IMHO we need a FAQ for |
    | 'IMHO', 'FAQ', 'BTW', etc. !" |
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 13:30    [W:0.024 / U:7.408 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site