Subject: Re: m_defrag() addition
To: Bill Studenmund <wrstuden@netbsd.org>
From: Jason Thorpe <thorpej@shagadelic.org>
List: tech-kern
Date: 03/02/2005 08:50:07
On Mar 1, 2005, at 7:12 PM, Bill Studenmund wrote:

> I think it'd be better to just return the chain. While you're right 
> that
> chances are we will just drop the packet, I think there are times we 
> may
> want to do something different with it. Yes, that would be using this
> routine for something other than fixing up DMA segments... If we always
> free the chain on error, it'd be very hard to support doing something 
> with
> the chain.

Rather than "return the chain", you do want it to return NULL, but 
simply not modify the chain.  If you do:

	m = m_defrag(m, ...);

...and it returns the old chain on failure, or a new chain on success, 
you have no way of knowing if it failed.  I suppose you could always 
do:

	m_new = m_defrag(m, ...);
	if (m == m_new) {
		/* m_defrag() failed */
	}

...but that would not handle the case of m_defrag() being able to 
compact the chain into trailing-space in m.

So, I think the way it needs to be done is:

	error = m_defrag(&m, ...);
	if (error != 0) {
		/* m_defrag() failed, m still points to old chain. */
	} else {
		/* m_defrag() succeeded, m now points to new chain, old chain freed. 
*/
	}

Sound reasonable?

-- thorpej