From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=sqnxJomq; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id DB4645A004E for ; Mon, 08 Dec 2025 03:17:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1765160260; bh=pRDMQid6jiqkS0D3IDdri3K4UDKLzMhlmDSPKDymJBs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sqnxJomqT1XK7igDs+NKpyNK5u8cRmFU/Vq4vnbZP40anZwOrszM3HTywsILyI7hC nh5Vx06079Fh9KVjjOeCU2/cekmm7YLB9jx+q3XwCQO9qCgUysEyY12IQDdxwQmx4v nikmHdlXgV9tHuLs/6nJBx0vwq3rMpmJ9GbeEMROwH30TRdTDLPjFhqC+mS3JRRG1m gDhdxU/zzGQ1tCLKYhNFHgO/Gx+aeyr/uT0LKpot6yVFsqDUTH+DLSdoOfnNYsxwbh s3Ko+jnCCR5F4WkoAeev29aSTbEFWUQxmt9HTj+ZTx/M0qOa8ohxALTiRYatI3zPqr 2xZjMNYhwPzzw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dPlxc3lf2z4wM8; Mon, 08 Dec 2025 13:17:40 +1100 (AEDT) Date: Mon, 8 Dec 2025 13:17:35 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2] iov: Fix coding style of basic (non-IOV_TAIL) parts Message-ID: References: <20251208001855.390887-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="RqnI/GWtnXedUgGD" Content-Disposition: inline In-Reply-To: <20251208001855.390887-1-sbrivio@redhat.com> Message-ID-Hash: 2QZZH7YANWFZOBTWVFJMV63GMG7QDBD2 X-Message-ID-Hash: 2QZZH7YANWFZOBTWVFJMV63GMG7QDBD2 X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --RqnI/GWtnXedUgGD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 08, 2025 at 01:18:55AM +0100, Stefano Brivio wrote: > I happened to touch these functions for a change that turned out to be > unnecessary, but coding style and documentation could still benefit > from some rephrasing and fixes. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > v2: Make description of @offset consistent between iov_from_buf() and > iov_to_buf() >=20 > iov.c | 68 +++++++++++++++++++++++++---------------------------------- > 1 file changed, 29 insertions(+), 39 deletions(-) >=20 > diff --git a/iov.c b/iov.c > index 8c74a59..ad726da 100644 > --- a/iov.c > +++ b/iov.c > @@ -20,24 +20,21 @@ > * Contributions after 2012-01-13 are licensed under the terms of the > * GNU GPL, version 2 or (at your option) any later version. > */ > + > #include > =20 > #include "util.h" > #include "iov.h" > =20 > - > /** > - * iov_skip_bytes() - Skip leading bytes of an IO vector > - * @iov: IO vector > + * iov_skip_bytes() - Find index and offset in iovec array given byte of= fset > + * @iov: iovec array > * @n: Number of entries in @iov > - * @skip: Number of leading bytes of @iov to skip > - * @offset: Offset of first unskipped byte in its @iov entry > + * @skip: Byte offset: leading bytes of @iov to skip > + * @offset: Offset within matching @iov entry, set on return, can be NULL > * > - * Return: index I of individual struct iovec which contains the byte at= @skip > - * bytes into the vector (as though all its buffers were contigu= ous). > - * If @offset is non-NULL, update it to the offset of that byte = within > - * @iov[I] (guaranteed to be less than @iov[I].iov_len) If the w= hole > - * vector has <=3D @skip bytes, return @n. > + * Return: index of iovec array containing the @skip byte counted as if = buffers > + * were contiguous. If iovec has less than @skip bytes, return @n. > */ > size_t iov_skip_bytes(const struct iovec *iov, size_t n, > size_t skip, size_t *offset) > @@ -57,17 +54,14 @@ size_t iov_skip_bytes(const struct iovec *iov, size_t= n, > } > =20 > /** > - * iov_from_buf() - Copy data from a buffer to an I/O vector (struct iov= ec) > - * efficiently. > - * > - * @iov: Pointer to the array of struct iovec describing the > - * scatter/gather I/O vector. > - * @iov_cnt: Number of elements in the iov array. > - * @offset: Byte offset in the iov array where copying should start. > - * @buf: Pointer to the source buffer containing the data to copy. > - * @bytes: Total number of bytes to copy from buf to iov. > + * iov_from_buf() - Copy from flat buffer to iovec array > + * @iov: Destination iovec array > + * @iov_cnt: Number of elements in the iovec array > + * @offset: Destination offset in @iov counted as if buffers were contig= uous > + * @buf: Source buffer > + * @bytes: Bytes to copy > * > - * Return: the number of bytes successfully copied. > + * Return: number of bytes copied > */ > size_t iov_from_buf(const struct iovec *iov, size_t iov_cnt, > size_t offset, const void *buf, size_t bytes) > @@ -78,12 +72,12 @@ size_t iov_from_buf(const struct iovec *iov, size_t i= ov_cnt, > if (__builtin_constant_p(bytes) && iov_cnt && > offset <=3D iov[0].iov_len && bytes <=3D iov[0].iov_len - offset) { > memcpy((char *)iov[0].iov_base + offset, buf, bytes); > + > return bytes; > } > =20 > i =3D iov_skip_bytes(iov, iov_cnt, offset, &offset); > =20 > - /* copying data */ > for (copied =3D 0; copied < bytes && i < iov_cnt; i++) { > size_t len =3D MIN(iov[i].iov_len - offset, bytes - copied); > =20 > @@ -97,17 +91,14 @@ size_t iov_from_buf(const struct iovec *iov, size_t i= ov_cnt, > } > =20 > /** > - * iov_to_buf() - Copy data from a scatter/gather I/O vector (struct iov= ec) to > - * a buffer efficiently. > - * > - * @iov: Pointer to the array of struct iovec describing the scatt= er/gather > - * I/O vector. > - * @iov_cnt: Number of elements in the iov array. > - * @offset: Offset within the first element of iov from where copying= should start. > - * @buf: Pointer to the destination buffer where data will be copi= ed. > - * @bytes: Total number of bytes to copy from iov to buf. > + * iov_to_buf() - Copy from iovec to flat buffer > + * @iov: Source iovec array > + * @iov_cnt: Number of elements in iovec array > + * @offset: Source offset in @iov counted as if buffers were contiguous > + * @buf: Destination buffer > + * @bytes: Bytes to copy > * > - * Return: the number of bytes successfully copied. > + * Return: number of bytes copied > */ > size_t iov_to_buf(const struct iovec *iov, size_t iov_cnt, > size_t offset, void *buf, size_t bytes) > @@ -118,15 +109,17 @@ size_t iov_to_buf(const struct iovec *iov, size_t i= ov_cnt, > if (__builtin_constant_p(bytes) && iov_cnt && > offset <=3D iov[0].iov_len && bytes <=3D iov[0].iov_len - offset) { > memcpy(buf, (char *)iov[0].iov_base + offset, bytes); > + > return bytes; > } > =20 > i =3D iov_skip_bytes(iov, iov_cnt, offset, &offset); > =20 > - /* copying data */ > for (copied =3D 0; copied < bytes && i < iov_cnt; i++) { > size_t len =3D MIN(iov[i].iov_len - offset, bytes - copied); > + > ASSERT(iov[i].iov_base); > + > memcpy((char *)buf + copied, (char *)iov[i].iov_base + offset, > len); > copied +=3D len; > @@ -137,14 +130,11 @@ size_t iov_to_buf(const struct iovec *iov, size_t i= ov_cnt, > } > =20 > /** > - * iov_size() - Calculate the total size of a scatter/gather I/O vector > - * (struct iovec). > + * iov_size() - Calculate total data size of iovec > + * @iov: Source iovec array > + * @iov_cnt: Number of elements in iovec array > * > - * @iov: Pointer to the array of struct iovec describing the > - * scatter/gather I/O vector. > - * @iov_cnt: Number of elements in the iov array. > - * > - * Return: the total size in bytes. > + * Return: total size in bytes > */ > size_t iov_size(const struct iovec *iov, size_t iov_cnt) > { > --=20 > 2.43.0 >=20 --=20 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 --RqnI/GWtnXedUgGD Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmk2NT4ACgkQzQJF27ox 2GciRw//bVac9q0ExZVgyypffn8i9zwpOC5rEAERfFbh3EJQGFkqociTXQVn7xVt PHFoclX1T438xL6HEyUcC4vSiUX9Sgm6lMoNudLL8wZK2rez6044hBKGyKKqgoaS uCHJyB4MZgahNZOKkCMlblnX4cH1taqN1WiDTNWpAPPjDS+bN1dXZPTTdqlzxDmb HWNfuwemHimpKl3T2PzTdAr8dXM3glbhJ8/Wsws80VdvzTSy4YLGHGlh2xU+X3G0 f48zTq5MeOjx6Tv4+IJFWac1Y0JIKAh75Zh7D/Ye5bLNINf85mH6q65rheJTL6gV g5KrX6invs9cepkgBvFOy0UJlUuQ2911Ekdz8Aayqo1Hbb8zLisFNS+hFg5AdKIF z7EfED/Yct1MZcbp4ti3zITkt5k3iHsboBFC3j4J1DZSt1X4V3EZIHhBkdrY75FD Ghj099YBxwXhg8yXUkQO1L8CZc+xcaTYUUKix5h3KEapl06PAYtHTaOp2O+ZBd/t z754UiLcqdt4/HRE0uza6yNgY+V0fApJJ8zW1b9ovuvgQ9igjX4fLcN4zh9XbUxF ywcMLX48vj/FdvlLOwQkOiuVHNxO8RuEtxw5kNarqnM64ZL5qHZ6uoOl8k2TLS+f Tk0tR15SISUv/ZdOwW3Ndd55Kut5dH6At9utdm6s5S0Fm1mqY2s= =2G5s -----END PGP SIGNATURE----- --RqnI/GWtnXedUgGD--