Re: [PATCH v9 2/8] iov_iter: Add a function to extract a page list from an iterator

From: David Howells
Date: Tue Jan 24 2023 - 16:11:28 EST


John Hubbard <jhubbard@xxxxxxxxxx> wrote:

> > + for (;;) {
> > + if (i->nr_segs == 0)
> > + return 0;
> > + maxsize = min(maxsize, i->bvec->bv_len - skip);
> > + if (maxsize)
> > + break;
> > + i->iov_offset = 0;
> > + i->nr_segs--;
> > + i->kvec++;
> > + skip = 0;
> > + }
> > +
> > + skip += i->bvec->bv_offset;
> > + page = i->bvec->bv_page + skip / PAGE_SIZE;
> > + offset = skip % PAGE_SIZE;
> > + *offset0 = offset;
> > +
> > + maxpages = want_pages_array(pages, maxsize, offset, maxpages);
> > + if (!maxpages)
> > + return -ENOMEM;
>
> Is it OK that the iov_iter position has been advanced, and left that way,
> in the case of an early -ENOMEM return here?

I think it should be okay. The for-loop at the top just skips over empty
segments, so it doesn't really advance things. There is an error there,
though: it should be i->bvec++, not i->kvec++ in the loop.

David