diff options
| author | Herbert Xu <herbert@gondor.apana.org.au> | 2016-07-12 01:18:00 -0400 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2016-07-18 05:35:50 -0400 |
| commit | ac02725812cb3a814cfe1fdc2a8a59db073e7e66 (patch) | |
| tree | 5480b15a94af14bd105e3981ece6a12898faeb14 | |
| parent | 2ee732d57496b8365819dfb958bc1ff04fcd4cac (diff) | |
crypto: scatterwalk - Inline start/map/done
This patch inlines the functions scatterwalk_start, scatterwalk_map
and scatterwalk_done as they're all tiny and mostly used by the block
cipher walker.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
| -rw-r--r-- | crypto/scatterwalk.c | 43 | ||||
| -rw-r--r-- | include/crypto/scatterwalk.h | 46 |
2 files changed, 40 insertions, 49 deletions
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c index ddffbb3ee712..52ce17a3dd63 100644 --- a/crypto/scatterwalk.c +++ b/crypto/scatterwalk.c | |||
| @@ -18,8 +18,6 @@ | |||
| 18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/mm.h> | 19 | #include <linux/mm.h> |
| 20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
| 21 | #include <linux/pagemap.h> | ||
| 22 | #include <linux/highmem.h> | ||
| 23 | #include <linux/scatterlist.h> | 21 | #include <linux/scatterlist.h> |
| 24 | 22 | ||
| 25 | static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out) | 23 | static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out) |
| @@ -30,47 +28,6 @@ static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out) | |||
| 30 | memcpy(dst, src, nbytes); | 28 | memcpy(dst, src, nbytes); |
| 31 | } | 29 | } |
| 32 | 30 | ||
| 33 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg) | ||
| 34 | { | ||
| 35 | walk->sg = sg; | ||
| 36 | walk->offset = sg->offset; | ||
| 37 | } | ||
| 38 | EXPORT_SYMBOL_GPL(scatterwalk_start); | ||
| 39 | |||
| 40 | void *scatterwalk_map(struct scatter_walk *walk) | ||
| 41 | { | ||
| 42 | return kmap_atomic(scatterwalk_page(walk)) + | ||
| 43 | offset_in_page(walk->offset); | ||
| 44 | } | ||
| 45 | EXPORT_SYMBOL_GPL(scatterwalk_map); | ||
| 46 | |||
| 47 | static void scatterwalk_pagedone(struct scatter_walk *walk, int out, | ||
| 48 | unsigned int more) | ||
| 49 | { | ||
| 50 | if (out) { | ||
| 51 | struct page *page; | ||
| 52 | |||
| 53 | page = sg_page(walk->sg) + ((walk->offset - 1) >> PAGE_SHIFT); | ||
| 54 | /* Test ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE first as | ||
| 55 | * PageSlab cannot be optimised away per se due to | ||
| 56 | * use of volatile pointer. | ||
| 57 | */ | ||
| 58 | if (ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE && !PageSlab(page)) | ||
| 59 | flush_dcache_page(page); | ||
| 60 | } | ||
| 61 | |||
| 62 | if (more && walk->offset >= walk->sg->offset + walk->sg->length) | ||
| 63 | scatterwalk_start(walk, sg_next(walk->sg)); | ||
| 64 | } | ||
| 65 | |||
| 66 | void scatterwalk_done(struct scatter_walk *walk, int out, int more) | ||
| 67 | { | ||
| 68 | if (!more || walk->offset >= walk->sg->offset + walk->sg->length || | ||
| 69 | !(walk->offset & (PAGE_SIZE - 1))) | ||
| 70 | scatterwalk_pagedone(walk, out, more); | ||
| 71 | } | ||
| 72 | EXPORT_SYMBOL_GPL(scatterwalk_done); | ||
| 73 | |||
| 74 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, | 31 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, |
| 75 | size_t nbytes, int out) | 32 | size_t nbytes, int out) |
| 76 | { | 33 | { |
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h index 7e1a33645eb5..880e6be9e95e 100644 --- a/include/crypto/scatterwalk.h +++ b/include/crypto/scatterwalk.h | |||
| @@ -16,14 +16,10 @@ | |||
| 16 | #ifndef _CRYPTO_SCATTERWALK_H | 16 | #ifndef _CRYPTO_SCATTERWALK_H |
| 17 | #define _CRYPTO_SCATTERWALK_H | 17 | #define _CRYPTO_SCATTERWALK_H |
| 18 | 18 | ||
| 19 | #include <asm/kmap_types.h> | ||
| 20 | #include <crypto/algapi.h> | 19 | #include <crypto/algapi.h> |
| 21 | #include <linux/hardirq.h> | ||
| 22 | #include <linux/highmem.h> | 20 | #include <linux/highmem.h> |
| 23 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
| 24 | #include <linux/mm.h> | ||
| 25 | #include <linux/scatterlist.h> | 22 | #include <linux/scatterlist.h> |
| 26 | #include <linux/sched.h> | ||
| 27 | 23 | ||
| 28 | static inline void scatterwalk_crypto_chain(struct scatterlist *head, | 24 | static inline void scatterwalk_crypto_chain(struct scatterlist *head, |
| 29 | struct scatterlist *sg, | 25 | struct scatterlist *sg, |
| @@ -83,11 +79,49 @@ static inline void scatterwalk_unmap(void *vaddr) | |||
| 83 | kunmap_atomic(vaddr); | 79 | kunmap_atomic(vaddr); |
| 84 | } | 80 | } |
| 85 | 81 | ||
| 86 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); | 82 | static inline void scatterwalk_start(struct scatter_walk *walk, |
| 83 | struct scatterlist *sg) | ||
| 84 | { | ||
| 85 | walk->sg = sg; | ||
| 86 | walk->offset = sg->offset; | ||
| 87 | } | ||
| 88 | |||
| 89 | static inline void *scatterwalk_map(struct scatter_walk *walk) | ||
| 90 | { | ||
| 91 | return kmap_atomic(scatterwalk_page(walk)) + | ||
| 92 | offset_in_page(walk->offset); | ||
| 93 | } | ||
| 94 | |||
| 95 | static inline void scatterwalk_pagedone(struct scatter_walk *walk, int out, | ||
| 96 | unsigned int more) | ||
| 97 | { | ||
| 98 | if (out) { | ||
| 99 | struct page *page; | ||
| 100 | |||
| 101 | page = sg_page(walk->sg) + ((walk->offset - 1) >> PAGE_SHIFT); | ||
| 102 | /* Test ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE first as | ||
| 103 | * PageSlab cannot be optimised away per se due to | ||
| 104 | * use of volatile pointer. | ||
| 105 | */ | ||
| 106 | if (ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE && !PageSlab(page)) | ||
| 107 | flush_dcache_page(page); | ||
| 108 | } | ||
| 109 | |||
| 110 | if (more && walk->offset >= walk->sg->offset + walk->sg->length) | ||
| 111 | scatterwalk_start(walk, sg_next(walk->sg)); | ||
| 112 | } | ||
| 113 | |||
| 114 | static inline void scatterwalk_done(struct scatter_walk *walk, int out, | ||
| 115 | int more) | ||
| 116 | { | ||
| 117 | if (!more || walk->offset >= walk->sg->offset + walk->sg->length || | ||
| 118 | !(walk->offset & (PAGE_SIZE - 1))) | ||
| 119 | scatterwalk_pagedone(walk, out, more); | ||
| 120 | } | ||
| 121 | |||
| 87 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, | 122 | void scatterwalk_copychunks(void *buf, struct scatter_walk *walk, |
| 88 | size_t nbytes, int out); | 123 | size_t nbytes, int out); |
| 89 | void *scatterwalk_map(struct scatter_walk *walk); | 124 | void *scatterwalk_map(struct scatter_walk *walk); |
| 90 | void scatterwalk_done(struct scatter_walk *walk, int out, int more); | ||
| 91 | 125 | ||
| 92 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, | 126 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, |
| 93 | unsigned int start, unsigned int nbytes, int out); | 127 | unsigned int start, unsigned int nbytes, int out); |
