]> www.infradead.org Git - users/dwmw2/linux.git/commit
crypto: scatterwalk - move to next sg entry just in time
authorEric Biggers <ebiggers@google.com>
Wed, 19 Feb 2025 18:23:23 +0000 (10:23 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sun, 2 Mar 2025 07:19:43 +0000 (15:19 +0800)
commit3bd4b2c603fce29f6d26da1579d5a013b70b9453
tree596ca02d94df1fb61d1d2c4813fa20a2dfb5afe8
parent2291399384c00bf61b117e848f3da6cf14c90f32
crypto: scatterwalk - move to next sg entry just in time

The scatterwalk_* functions are designed to advance to the next sg entry
only when there is more data from the request to process.  Compared to
the alternative of advancing after each step if !sg_is_last(sg), this
has the advantage that it doesn't cause problems if users accidentally
don't terminate their scatterlist with the end marker (which is an easy
mistake to make, and there are examples of this).

Currently, the advance to the next sg entry happens in
scatterwalk_done(), which is called after each "step" of the walk.  It
requires the caller to pass in a boolean 'more' that indicates whether
there is more data.  This works when the caller immediately knows
whether there is more data, though it adds some complexity.  However in
the case of scatterwalk_copychunks() it's not immediately known whether
there is more data, so the call to scatterwalk_done() has to happen
higher up the stack.  This is error-prone, and indeed the needed call to
scatterwalk_done() is not always made, e.g. scatterwalk_copychunks() is
sometimes called multiple times in a row.  This causes a zero-length
step to get added in some cases, which is unexpected and seems to work
only by accident.

This patch begins the switch to a less error-prone approach where the
advance to the next sg entry happens just in time instead.  For now,
that means just doing the advance in scatterwalk_clamp() if it's needed
there.  Initially this is redundant, but it's needed to keep the tree in
a working state as later patches change things to the final state.

Later patches will similarly move the dcache flushing logic out of
scatterwalk_done() and then remove scatterwalk_done() entirely.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
include/crypto/scatterwalk.h