Skip to content

Commit f385178

Browse files
pbholeborkmann
authored andcommitted
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 <[email protected]> Signed-off-by: Prashant Bhole <[email protected]> Acked-by: John Fastabend <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 1379ef8 commit f385178

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

include/linux/scatterlist.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ static inline void *sg_virt(struct scatterlist *sg)
248248
return page_address(sg_page(sg)) + sg->offset;
249249
}
250250

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+
251269
int sg_nents(struct scatterlist *sg);
252270
int sg_nents_for_len(struct scatterlist *sg, u64 len);
253271
struct scatterlist *sg_next(struct scatterlist *);

lib/scatterlist.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,7 @@ EXPORT_SYMBOL(sg_last);
132132
void sg_init_table(struct scatterlist *sgl, unsigned int nents)
133133
{
134134
memset(sgl, 0, sizeof(*sgl) * nents);
135-
#ifdef CONFIG_DEBUG_SG
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]);
135+
sg_init_marker(sgl, nents);
143136
}
144137
EXPORT_SYMBOL(sg_init_table);
145138

0 commit comments

Comments
 (0)