diff options
author | Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp> | 2018-03-29 20:20:59 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-03-30 16:50:15 -0400 |
commit | f385178679b6561d2e717567d12e07c7f927ee59 (patch) | |
tree | 97578ab32a6848feb7f29972f58753febe01d0ce | |
parent | 1379ef828a18d8f81c526b25e4d5685caa2cfd65 (diff) |
lib/scatterlist: add sg_init_marker() helper
sg_init_marker initializes sg_magic in the sg table and calls
sg_mark_end() on the last entry of the table. This can be useful to
avoid memset in sg_init_table() when scatterlist is already zeroed out
For example: when scatterlist is embedded inside other struct and that
container struct is zeroed out
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | include/linux/scatterlist.h | 18 | ||||
-rw-r--r-- | lib/scatterlist.c | 9 |
2 files changed, 19 insertions, 8 deletions
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index 22b2131bcdcd..aa5d4eb725f5 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h | |||
@@ -248,6 +248,24 @@ static inline void *sg_virt(struct scatterlist *sg) | |||
248 | return page_address(sg_page(sg)) + sg->offset; | 248 | return page_address(sg_page(sg)) + sg->offset; |
249 | } | 249 | } |
250 | 250 | ||
251 | /** | ||
252 | * sg_init_marker - Initialize markers in sg table | ||
253 | * @sgl: The SG table | ||
254 | * @nents: Number of entries in table | ||
255 | * | ||
256 | **/ | ||
257 | static inline void sg_init_marker(struct scatterlist *sgl, | ||
258 | unsigned int nents) | ||
259 | { | ||
260 | #ifdef CONFIG_DEBUG_SG | ||
261 | unsigned int i; | ||
262 | |||
263 | for (i = 0; i < nents; i++) | ||
264 | sgl[i].sg_magic = SG_MAGIC; | ||
265 | #endif | ||
266 | sg_mark_end(&sgl[nents - 1]); | ||
267 | } | ||
268 | |||
251 | int sg_nents(struct scatterlist *sg); | 269 | int sg_nents(struct scatterlist *sg); |
252 | int sg_nents_for_len(struct scatterlist *sg, u64 len); | 270 | int sg_nents_for_len(struct scatterlist *sg, u64 len); |
253 | struct scatterlist *sg_next(struct scatterlist *); | 271 | struct scatterlist *sg_next(struct scatterlist *); |
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 53728d391d3a..06dad7a072fd 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c | |||
@@ -132,14 +132,7 @@ EXPORT_SYMBOL(sg_last); | |||
132 | void sg_init_table(struct scatterlist *sgl, unsigned int nents) | 132 | void sg_init_table(struct scatterlist *sgl, unsigned int nents) |
133 | { | 133 | { |
134 | memset(sgl, 0, sizeof(*sgl) * nents); | 134 | memset(sgl, 0, sizeof(*sgl) * nents); |
135 | #ifdef CONFIG_DEBUG_SG | 135 | sg_init_marker(sgl, nents); |
136 | { | ||
137 | unsigned int i; | ||
138 | for (i = 0; i < nents; i++) | ||
139 | sgl[i].sg_magic = SG_MAGIC; | ||
140 | } | ||
141 | #endif | ||
142 | sg_mark_end(&sgl[nents - 1]); | ||
143 | } | 136 | } |
144 | EXPORT_SYMBOL(sg_init_table); | 137 | EXPORT_SYMBOL(sg_init_table); |
145 | 138 | ||