Skip to content

Commit 723fbf5

Browse files
Anshuman Khandualaxboe
authored andcommitted
lib/scatterlist: Add SG_CHAIN and SG_END macros for LSB encodings
This replaces scatterlist->page_link LSB encodings with SG_CHAIN and SG_END definitions without any functional change. Signed-off-by: Anshuman Khandual <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 468f098 commit 723fbf5

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

include/linux/scatterlist.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ struct sg_table {
6565
*/
6666

6767
#define SG_MAGIC 0x87654321
68+
#define SG_CHAIN 0x01UL
69+
#define SG_END 0x02UL
6870

6971
/*
7072
* We overload the LSB of the page pointer to indicate whether it's
7173
* a valid sg entry, or whether it points to the start of a new scatterlist.
7274
* Those low bits are there for everyone! (thanks mason :-)
7375
*/
74-
#define sg_is_chain(sg) ((sg)->page_link & 0x01)
75-
#define sg_is_last(sg) ((sg)->page_link & 0x02)
76+
#define sg_is_chain(sg) ((sg)->page_link & SG_CHAIN)
77+
#define sg_is_last(sg) ((sg)->page_link & SG_END)
7678
#define sg_chain_ptr(sg) \
77-
((struct scatterlist *) ((sg)->page_link & ~0x03))
79+
((struct scatterlist *) ((sg)->page_link & ~(SG_CHAIN | SG_END)))
7880

7981
/**
8082
* sg_assign_page - Assign a given page to an SG entry
@@ -88,13 +90,13 @@ struct sg_table {
8890
**/
8991
static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
9092
{
91-
unsigned long page_link = sg->page_link & 0x3;
93+
unsigned long page_link = sg->page_link & (SG_CHAIN | SG_END);
9294

9395
/*
9496
* In order for the low bit stealing approach to work, pages
9597
* must be aligned at a 32-bit boundary as a minimum.
9698
*/
97-
BUG_ON((unsigned long) page & 0x03);
99+
BUG_ON((unsigned long) page & (SG_CHAIN | SG_END));
98100
#ifdef CONFIG_DEBUG_SG
99101
BUG_ON(sg->sg_magic != SG_MAGIC);
100102
BUG_ON(sg_is_chain(sg));
@@ -130,7 +132,7 @@ static inline struct page *sg_page(struct scatterlist *sg)
130132
BUG_ON(sg->sg_magic != SG_MAGIC);
131133
BUG_ON(sg_is_chain(sg));
132134
#endif
133-
return (struct page *)((sg)->page_link & ~0x3);
135+
return (struct page *)((sg)->page_link & ~(SG_CHAIN | SG_END));
134136
}
135137

136138
/**
@@ -178,7 +180,8 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,
178180
* Set lowest bit to indicate a link pointer, and make sure to clear
179181
* the termination bit if it happens to be set.
180182
*/
181-
prv[prv_nents - 1].page_link = ((unsigned long) sgl | 0x01) & ~0x02;
183+
prv[prv_nents - 1].page_link = ((unsigned long) sgl | SG_CHAIN)
184+
& ~SG_END;
182185
}
183186

184187
/**
@@ -198,8 +201,8 @@ static inline void sg_mark_end(struct scatterlist *sg)
198201
/*
199202
* Set termination bit, clear potential chain bit
200203
*/
201-
sg->page_link |= 0x02;
202-
sg->page_link &= ~0x01;
204+
sg->page_link |= SG_END;
205+
sg->page_link &= ~SG_CHAIN;
203206
}
204207

205208
/**
@@ -215,7 +218,7 @@ static inline void sg_unmark_end(struct scatterlist *sg)
215218
#ifdef CONFIG_DEBUG_SG
216219
BUG_ON(sg->sg_magic != SG_MAGIC);
217220
#endif
218-
sg->page_link &= ~0x02;
221+
sg->page_link &= ~SG_END;
219222
}
220223

221224
/**

0 commit comments

Comments
 (0)