Make m_getm() always return the top of the newly allocated chain, as

opposed to returning the top of the old chain when there was one and
the top of the newly allocated chain if there was no old chain.

Actually, it should be noted that prior to this fix, although the
comment above m_getm() advertised that m_getm() would return the
top of the old chain (if an old chain was being passed in) it
actually [wrongly] was returning the tail mbuf in the old chain
instead.  This is a bug but since the one use of m_getm() in
the tree luckily did not depend on the behavior, it happened
to work out without notice.

Harti Brandt pointed out that the advertised behavior was actually
not the real behavior and so this change makes m_getm() ALWAYS
return the newly allocated chain (and fixes the comment).  This
is less confusing and is the best course of action as then the
caller is always able to have both a reference to the top of
the original chain (because it's passing it in in the call) and
a reference to the newly attached chain.  Although the API is
slightly modified, I don't think that any third-party code uses
m_getm() and if it does, it surely can't be working properly
because the old behavior was bogus.

API bug pointed out by: Harti Brandt <brandt@fokus.fraunhofer.de>
This commit is contained in:
Bosko Milekic 2003-02-14 16:50:13 +00:00
parent 6ed1480808
commit 9e7225808e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=110880
2 changed files with 2 additions and 5 deletions

View File

@ -1147,7 +1147,7 @@ m_get(int how, short type)
* Allocate a given length worth of mbufs and/or clusters (whatever fits
* best) and return a pointer to the top of the allocated chain. If an
* existing mbuf chain is provided, then we will append the new chain
* to the existing one and return the top of the provided (existing)
* to the existing one but still return the top of the newly allocated
* chain. NULL is returned on failure, in which case the [optional]
* provided chain is left untouched, and any memory already allocated
* is freed.
@ -1235,9 +1235,7 @@ m_getm(struct mbuf *m, int len, int how, short type)
if (mtail != NULL)
mtail->m_next = top;
else
mtail = top;
return mtail;
return top;
failed:
if (top != NULL)
m_freem(top);

View File

@ -196,7 +196,6 @@ mb_put_mem(struct mbchain *mbp, c_caddr_t source, int size, int type)
if (m == NULL)
return ENOBUFS;
}
m = m->m_next;
mleft = M_TRAILINGSPACE(m);
continue;
}