]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/scatterlist: add sg_init_marker() helper
authorPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Fri, 30 Mar 2018 00:20:59 +0000 (09:20 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 30 Mar 2018 20:50:15 +0000 (22:50 +0200)
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>
include/linux/scatterlist.h
lib/scatterlist.c

index 22b2131bcdcd23339ef068b22cb8cbf8e6a55ea5..aa5d4eb725f5af918382e799f4b2101709024f35 100644 (file)
@@ -248,6 +248,24 @@ static inline void *sg_virt(struct scatterlist *sg)
        return page_address(sg_page(sg)) + sg->offset;
 }
 
+/**
+ * sg_init_marker - Initialize markers in sg table
+ * @sgl:          The SG table
+ * @nents:        Number of entries in table
+ *
+ **/
+static inline void sg_init_marker(struct scatterlist *sgl,
+                                 unsigned int nents)
+{
+#ifdef CONFIG_DEBUG_SG
+       unsigned int i;
+
+       for (i = 0; i < nents; i++)
+               sgl[i].sg_magic = SG_MAGIC;
+#endif
+       sg_mark_end(&sgl[nents - 1]);
+}
+
 int sg_nents(struct scatterlist *sg);
 int sg_nents_for_len(struct scatterlist *sg, u64 len);
 struct scatterlist *sg_next(struct scatterlist *);
index 53728d391d3a70f15d0f42499d92cd87b670b962..06dad7a072fd66385032f541f3c9f77b6d440235 100644 (file)
@@ -132,14 +132,7 @@ EXPORT_SYMBOL(sg_last);
 void sg_init_table(struct scatterlist *sgl, unsigned int nents)
 {
        memset(sgl, 0, sizeof(*sgl) * nents);
-#ifdef CONFIG_DEBUG_SG
-       {
-               unsigned int i;
-               for (i = 0; i < nents; i++)
-                       sgl[i].sg_magic = SG_MAGIC;
-       }
-#endif
-       sg_mark_end(&sgl[nents - 1]);
+       sg_init_marker(sgl, nents);
 }
 EXPORT_SYMBOL(sg_init_table);