diff options
author | Joel Fernandes <joelf@ti.com> | 2013-08-17 21:42:22 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-08-21 21:27:58 +1000 |
commit | ca1683bdd49ab4d378e4fa295c09ac35001ab79b (patch) | |
tree | 7165c8964e6143e49fefce61f8f93465ca723d12 /crypto | |
parent | d8a8fc6438d25265e0c271137c1d0f1290f3b109 (diff) | |
download | linux-crypto-ca1683bdd49ab4d378e4fa295c09ac35001ab79b.tar.gz linux-crypto-ca1683bdd49ab4d378e4fa295c09ac35001ab79b.zip |
crypto: scatterwalk - Add support for calculating number of SG elements
Crypto layer only passes nbytes to encrypt but in omap-aes driver we need to
know number of SG elements to pass to dmaengine slave API. We add function for
the same to scatterwalk library.
Signed-off-by: Joel Fernandes <joelf@ti.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r-- | crypto/scatterwalk.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c index 7281b8a9..79ca2278 100644 --- a/crypto/scatterwalk.c +++ b/crypto/scatterwalk.c @@ -124,3 +124,25 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, scatterwalk_done(&walk, out, 0); } EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy); + +int scatterwalk_bytes_sglen(struct scatterlist *sg, int num_bytes) +{ + int offset = 0, n = 0; + + /* num_bytes is too small */ + if (num_bytes < sg->length) + return -1; + + do { + offset += sg->length; + n++; + sg = scatterwalk_sg_next(sg); + + /* num_bytes is too large */ + if (unlikely(!sg && (num_bytes < offset))) + return -1; + } while (sg && (num_bytes > offset)); + + return n; +} +EXPORT_SYMBOL_GPL(scatterwalk_bytes_sglen); |