On Fri, Feb 27, 2026 at 03:03:23PM +0100, Laurent Vivier wrote: > Add a counterpart to IOV_PEEK_HEADER() that writes header data back > to an iov_tail after modification. If the header pointer matches the > original iov buffer location, it only advances the offset. Otherwise, > it copies the data using iov_from_buf(). > > Signed-off-by: Laurent Vivier Concept looks good to me. > --- > iov.c | 22 ++++++++++++++++++++++ > iov.h | 14 +++++++++++++- > 2 files changed, 35 insertions(+), 1 deletion(-) > > diff --git a/iov.c b/iov.c > index 8836305fb701..2cf23d284e4a 100644 > --- a/iov.c > +++ b/iov.c > @@ -296,6 +296,28 @@ void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_t align) > return v; > } > > +/** > + * iov_put_header_() - Write header back to an IOV tail > + * @tail: IOV tail to write header to > + * @v: Pointer to header data to write > + * @len: Length of header to write, in bytes > + * > + * Return: number of bytes written > + */ > +/* cppcheck-suppress unusedFunction */ > +size_t iov_put_header_(struct iov_tail *tail, const void *v, size_t len) > +{ > + size_t l = len; > + > + /* iov_peek_header_() already called iov_check_header() */ > + if ((char *)tail->iov[0].iov_base + tail->off != v) > + l = iov_from_buf(tail->iov, tail->cnt, tail->off, v, len); IIUC, there's a strong requirement that this only be called after a matching iov_peek_header_(), yes? If that's the case then (l != len) would mean something has already gone badly wrong - so should it be an ASSERT()? > + tail->off += l; > + > + return l; > +} > + > /** > * iov_remove_header_() - Remove a header from an IOV tail > * @tail: IOV tail to remove header from (modified) > diff --git a/iov.h b/iov.h > index a7b873d58134..08cf60639358 100644 > --- a/iov.h > +++ b/iov.h > @@ -86,6 +86,7 @@ bool iov_tail_prune(struct iov_tail *tail); > size_t iov_tail_size(struct iov_tail *tail); > bool iov_drop_header(struct iov_tail *tail, size_t len); > void *iov_peek_header_(struct iov_tail *tail, void *v, size_t len, size_t align); > +size_t iov_put_header_(struct iov_tail *tail, const void *v, size_t len); > void *iov_remove_header_(struct iov_tail *tail, void *v, size_t len, size_t align); > ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > struct iov_tail *tail); > @@ -110,6 +111,16 @@ void iov_tail_zero_end(struct iov_tail *tail, size_t size); > sizeof(var_), \ > __alignof__(var_)))) > > +/** > + * IOV_PUT_HEADER() - Write header back to an IOV tail > + * @tail_: IOV tail to write header to > + * @var_: Pointer to a variable containing the header data to write > + * > + * Return: number of bytes written > + */ > +#define IOV_PUT_HEADER(tail_, var_) \ > + (iov_put_header_((tail_), (var_), sizeof(*var_))) > + > /** > * IOV_REMOVE_HEADER() - Remove and return typed header from an IOV tail > * @tail_: IOV tail to remove header from (modified) > @@ -128,7 +139,8 @@ void iov_tail_zero_end(struct iov_tail *tail, size_t size); > ((__typeof__(var_) *)(iov_remove_header_((tail_), &(var_), \ > sizeof(var_), __alignof__(var_)))) > > -/** IOV_DROP_HEADER() - Remove a typed header from an IOV tail > +/** > + * IOV_DROP_HEADER() - Remove a typed header from an IOV tail > * @tail_: IOV tail to remove header from (modified) > * @type_: Data type of the header to remove > * > -- > 2.53.0 > -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson