Re: [PATCH] iio: buffer-dmaengine: fix sg entry iteration when building dma_vecs
Jonathan Cameron <[email protected]>
| Newsgroups | org.kernel.vger.linux-iio |
|---|---|
| Message-ID | <20260823012318.77fcd990@jic23-huawei> |
On Wed, 19 Aug 2026 23:54:31 +0300 Andy Shevchenko <[email protected]> wrote: > 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. Yup. That's what would be needed if the condition can actually occur. Also, Nuno is (I think) suggesting the dma engine driver itself deals with that splitting when it is needed. So hopefully this is a place where we can apply the someone else's problem field ;) > > > > - 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? I'd forgotten that nugget of fun existed. There is a patch on list to drop the one driver I ever used it in - bringing the total users down to 4! :) I don't think it applies here though as we are talking splitting one entry of the list, not the whole list. That list splitting is for when you have a constraint on the total max DMA done in one request. Jonathan >