lkml.org 
[lkml]   [2007]   [Oct]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    Subjectsg_next() for struct scatterlist is confusing

    according to the inline comments in include/linux/scatterlist.h:

    "* If bit 0 is set, then the page_link contains a pointer to the next sg
    * table list. Otherwise the next entry is at sg + 1."

    but if that's the case, then the implementation of sg_next() seems a
    bit weird:

    =================================
    /**
    * sg_next - return the next scatterlist entry in a list
    * @sg: The current sg entry
    *
    * Description:
    * Usually the next entry will be @sg@ + 1, but if this sg element is part
    * of a chained scatterlist, it could jump to the start of a new
    * scatterlist array.
    *
    **/
    static inline struct scatterlist *sg_next(struct scatterlist *sg)
    {
    #ifdef CONFIG_DEBUG_SG
    BUG_ON(sg->sg_magic != SG_MAGIC);
    #endif
    if (sg_is_last(sg))
    return NULL;

    sg++;
    if (unlikely(sg_is_chain(sg)))
    sg = sg_chain_ptr(sg);

    return sg;
    }
    ================================

    note how the comment says that the next entry will "usually" be
    sg+1, "but" not if it's actually a pointer.

    however, as i read the code above, sg is *always* incremented before
    that testing. is that correct? am i just misreading something? or
    could the comment have been a bit clearer?

    rday


    --
    ========================================================================
    Robert P. J. Day
    Linux Consulting, Training and Annoying Kernel Pedantry
    Waterloo, Ontario, CANADA

    http://crashcourse.ca
    ========================================================================
    -
    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/

    \
     
     \ /
      Last update: 2007-10-27 13:45    [W:0.022 / U:61.552 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site