summaryrefslogtreecommitdiff
path: root/crypto
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2025-02-19 10:23:24 -0800
committerHerbert Xu <herbert@gondor.apana.org.au>2025-03-02 15:19:43 +0800
commite21d01a2a3f56ee422cd155bf06c5e572523fcc1 (patch)
treeda488347e5634620fb212a40bfbb1fdb8e551f5b /crypto
parent3bd4b2c603fce29f6d26da1579d5a013b70b9453 (diff)
crypto: scatterwalk - add new functions for skipping data
Add scatterwalk_skip() to skip the given number of bytes in a scatter_walk. Previously support for skipping was provided through scatterwalk_copychunks(..., 2) followed by scatterwalk_done(), which was confusing and less efficient. Also add scatterwalk_start_at_pos() which starts a scatter_walk at the given position, equivalent to scatterwalk_start() + scatterwalk_skip(). This addresses another common need in a more streamlined way. Later patches will convert various users to use these functions. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/scatterwalk.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
index 16f6ba896fb6..af436ad02e3f 100644
--- a/crypto/scatterwalk.c
+++ b/crypto/scatterwalk.c
@@ -15,6 +15,21 @@
#include <linux/module.h>
#include <linux/scatterlist.h>
+void scatterwalk_skip(struct scatter_walk *walk, unsigned int nbytes)
+{
+ struct scatterlist *sg = walk->sg;
+
+ nbytes += walk->offset - sg->offset;
+
+ while (nbytes > sg->length) {
+ nbytes -= sg->length;
+ sg = sg_next(sg);
+ }
+ walk->sg = sg;
+ walk->offset = sg->offset + nbytes;
+}
+EXPORT_SYMBOL_GPL(scatterwalk_skip);
+
static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out)
{
void *src = out ? buf : sgdata;