On Thu, Jul 22, 2021 at 10:00:40AM -0300, Jason Gunthorpe wrote: > this is better: > > struct sg_append_table state; > > sg_append_init(&state, sgt, gfp_mask); > > while (..) > ret = sg_append_pages(&state, pages, n_pages, ..) > if (ret) > sg_append_abort(&state); // Frees the sgt and puts it to NULL > sg_append_complete(&state) > > Which allows sg_alloc_table_from_pages() to be written as > > struct sg_append_table state; > sg_append_init(&state, sgt, gfp_mask); > ret = sg_append_pages(&state,pages, n_pages, offset, size, UINT_MAX) > if (ret) { > sg_append_abort(&state); > return ret; > } > sg_append_complete(&state); > return 0; > > And then the API can manage all of this in some sane and > understandable way. That would be a lot easier to use for sure. Not sure how invasive the changes would be, though.