aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorJens Axboe <jens.axboe@oracle.com>2007-10-22 14:01:06 -0400
committerJens Axboe <jens.axboe@oracle.com>2007-10-22 15:20:03 -0400
commitd6ec084200c37683278c821338f74ddf21ab80f5 (patch)
tree931a112061e3a861768384b8b6ea20fdd35bd41b /include/linux
parent18dabf473e15850c0dbc8ff13ac1e2806d542c15 (diff)
Add CONFIG_DEBUG_SG sg validation
Add a Kconfig entry which will toggle some sanity checks on the sg entry and tables. Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/scatterlist.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index c6136e8a7f58..42daf5e15265 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -23,6 +23,8 @@
23 * 23 *
24 */ 24 */
25 25
26#define SG_MAGIC 0x87654321
27
26/** 28/**
27 * sg_set_page - Set sg entry to point at given page 29 * sg_set_page - Set sg entry to point at given page
28 * @sg: SG entry 30 * @sg: SG entry
@@ -39,6 +41,9 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page)
39{ 41{
40 unsigned long page_link = sg->page_link & 0x3; 42 unsigned long page_link = sg->page_link & 0x3;
41 43
44#ifdef CONFIG_DEBUG_SG
45 BUG_ON(sg->sg_magic != SG_MAGIC);
46#endif
42 sg->page_link = page_link | (unsigned long) page; 47 sg->page_link = page_link | (unsigned long) page;
43} 48}
44 49
@@ -81,6 +86,9 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
81 **/ 86 **/
82static inline struct scatterlist *sg_next(struct scatterlist *sg) 87static inline struct scatterlist *sg_next(struct scatterlist *sg)
83{ 88{
89#ifdef CONFIG_DEBUG_SG
90 BUG_ON(sg->sg_magic != SG_MAGIC);
91#endif
84 if (sg_is_last(sg)) 92 if (sg_is_last(sg))
85 return NULL; 93 return NULL;
86 94
@@ -124,6 +132,10 @@ static inline struct scatterlist *sg_last(struct scatterlist *sgl,
124 ret = sg; 132 ret = sg;
125 133
126#endif 134#endif
135#ifdef CONFIG_DEBUG_SG
136 BUG_ON(sgl[0].sg_magic != SG_MAGIC);
137 BUG_ON(!sg_is_last(ret));
138#endif
127 return ret; 139 return ret;
128} 140}
129 141
@@ -180,6 +192,9 @@ static inline void sg_init_one(struct scatterlist *sg, const void *buf,
180 unsigned int buflen) 192 unsigned int buflen)
181{ 193{
182 memset(sg, 0, sizeof(*sg)); 194 memset(sg, 0, sizeof(*sg));
195#ifdef CONFIG_DEBUG_SG
196 sg->sg_magic = SG_MAGIC;
197#endif
183 sg_mark_end(sg, 1); 198 sg_mark_end(sg, 1);
184 sg_set_buf(sg, buf, buflen); 199 sg_set_buf(sg, buf, buflen);
185} 200}
@@ -198,6 +213,13 @@ static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
198{ 213{
199 memset(sgl, 0, sizeof(*sgl) * nents); 214 memset(sgl, 0, sizeof(*sgl) * nents);
200 sg_mark_end(sgl, nents); 215 sg_mark_end(sgl, nents);
216#ifdef CONFIG_DEBUG_SG
217 {
218 int i;
219 for (i = 0; i < nents; i++)
220 sgl[i].sg_magic = SG_MAGIC;
221 }
222#endif
201} 223}
202 224
203/** 225/**