mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@crashcourse.ca>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: sg_next() for struct scatterlist is confusing
Date: Sat, 27 Oct 2007 07:39:40 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0710270734210.24293@localhost.localdomain> (raw)


  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
========================================================================

             reply	other threads:[~2007-10-27 11:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-27 11:39 Robert P. J. Day [this message]
2007-10-27 16:31 ` Haavard Skinnemoen
2007-10-27 16:35   ` Robert P. J. Day

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=Pine.LNX.4.64.0710270734210.24293@localhost.localdomain \
    --to=rpjday@crashcourse.ca \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®