From: Eric Biggers <ebiggers@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: Re: [v2 PATCH 2/3] crypto: scatterwalk - Add memcpy_sglist
Date: Mon, 10 Mar 2025 21:36:51 -0700 [thread overview]
Message-ID: <20250311043651.GA1263@sol.localdomain> (raw)
In-Reply-To: <18a6df64615a10be64c3c902f8b1f36e472548d7.1741318360.git.herbert@gondor.apana.org.au>
On Fri, Mar 07, 2025 at 11:36:19AM +0800, Herbert Xu wrote:
> Add memcpy_sglist which copies one SG list to another.
>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> ---
> crypto/scatterwalk.c | 27 +++++++++++++++++++++++++++
> include/crypto/scatterwalk.h | 3 +++
> 2 files changed, 30 insertions(+)
>
> diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
> index 20a28c6d94da..8225801488d5 100644
> --- a/crypto/scatterwalk.c
> +++ b/crypto/scatterwalk.c
> @@ -86,6 +86,33 @@ void memcpy_to_sglist(struct scatterlist *sg, unsigned int start,
> }
> EXPORT_SYMBOL_GPL(memcpy_to_sglist);
>
> +void memcpy_sglist(struct scatterlist *dst, struct scatterlist *src,
> + unsigned int nbytes)
> +{
> + struct scatter_walk swalk;
> + struct scatter_walk dwalk;
> +
> + if (unlikely(nbytes == 0)) /* in case sg == NULL */
> + return;
> +
> + scatterwalk_start(&swalk, src);
> + scatterwalk_start(&dwalk, dst);
> +
> + do {
> + unsigned int slen, dlen;
> + unsigned int len;
> +
> + slen = scatterwalk_next(&swalk, nbytes);
> + dlen = scatterwalk_next(&dwalk, nbytes);
> + len = min(slen, dlen);
> + memcpy(dwalk.addr, swalk.addr, len);
> + scatterwalk_done_dst(&dwalk, len);
> + scatterwalk_done_src(&swalk, len);
> + nbytes -= len;
> + } while (nbytes);
> +}
> +EXPORT_SYMBOL_GPL(memcpy_sglist);
Actually this new function is useless as-is, since it invokes undefined behavior
when the source and destination coincide (which can happen even when src ==
dst), and all the potential callers need to handle that case. I'm working on a
fixed version.
- Eric
next prev parent reply other threads:[~2025-03-11 4:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 3:36 [v2 PATCH 0/3] crypto: scatterwalk - scatterwalk_next and memcpy_sglist Herbert Xu
2025-03-07 3:36 ` [v2 PATCH 1/3] crypto: scatterwalk - Change scatterwalk_next calling convention Herbert Xu
2025-03-07 21:43 ` Eric Biggers
2025-03-08 10:46 ` Herbert Xu
2025-03-07 3:36 ` [v2 PATCH 2/3] crypto: scatterwalk - Add memcpy_sglist Herbert Xu
2025-03-07 21:37 ` Eric Biggers
2025-03-08 10:52 ` Herbert Xu
2025-03-10 17:06 ` Eric Biggers
2025-03-11 4:36 ` Eric Biggers [this message]
2025-04-26 6:16 ` Herbert Xu
2025-03-07 3:36 ` [v2 PATCH 3/3] crypto: skcipher - Eliminate duplicate virt.addr field Herbert Xu
2025-03-07 21:48 ` Eric Biggers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250311043651.GA1263@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox