Re: [PATCH] iio: buffer-dmaengine: fix sg entry iteration when building dma_vecs

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-iio
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
On Wed, Aug 19, 2026 at 01:41:04AM +0100, Jonathan Cameron wrote:
> On Tue, 18 Aug 2026 17:45:29 +0100
> Nuno Sá <[email protected]> wrote:

...

> >  		sgl = block->sg_table->sgl;
> > -		nents = sg_nents_for_len(sgl, block->bytes_used);
> > -		if (nents < 0)
> > -			return nents;
> > +		nents = sg_nents_for_dma(sgl, block->sg_table->nents, max_size);
> 
> So this fun function will generally give us the number of sgl entries, but not
> quite always. It will give us how many chunks of up to max_size fit into
> a particularly large entry.

It gives the number of SG entries needed for the case if each of them will
satisfy the limit. Whatever following code does, it may allocate a new SG
list based on the number returned by this function and resplit.

> > -		for (i = 0; i < nents; i++) {
> > +		for (i = 0; i < nents && len_total; i++) {
> So this needs to be more clever as we aren't just iterating entrees and filling
> them in, some of them could at least in theory be too big to fit
> in a single vec - hence you need to do a loop in here that sets
> multiple entries if that occurs.
> 
> If that can't happen for some other reason then I think you can 
> just use block->sgtable->nents instead of the more complex call above.

Perhaps sg_split() is what people are looking for in this case?

-- 
With Best Regards,
Andy Shevchenko
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.