diff options
author | Luis R. Rodriguez <lrodriguez@atheros.com> | 2008-08-06 18:21:26 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-08-07 09:49:42 -0400 |
commit | 7d283aee50351ec19eaf654a8690d77c4e1dff50 (patch) | |
tree | 8b0079f19db09ecd264cc2e8c428033fe725015f | |
parent | e6fce5b916cd7f7f79b2b3e53ba74bbfc1d7cf8b (diff) |
list.h: Add list_splice_tail() and list_splice_tail_init()
If you are using linked lists for queues list_splice() will not do what
you would expect even if you use the elements passed reversed. We need
to handle these differently. We add list_splice_tail() and
list_splice_tail_init().
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/dma/ioat_dma.c | 2 | ||||
-rw-r--r-- | drivers/usb/host/ehci-q.c | 2 | ||||
-rw-r--r-- | include/linux/list.h | 47 |
3 files changed, 40 insertions, 11 deletions
diff --git a/drivers/dma/ioat_dma.c b/drivers/dma/ioat_dma.c index a52156e56886..bc8c6e3470ca 100644 --- a/drivers/dma/ioat_dma.c +++ b/drivers/dma/ioat_dma.c | |||
@@ -551,7 +551,7 @@ static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx) | |||
551 | /* write address into NextDescriptor field of last desc in chain */ | 551 | /* write address into NextDescriptor field of last desc in chain */ |
552 | to_ioat_desc(ioat_chan->used_desc.prev)->hw->next = | 552 | to_ioat_desc(ioat_chan->used_desc.prev)->hw->next = |
553 | first->async_tx.phys; | 553 | first->async_tx.phys; |
554 | __list_splice(&new_chain, ioat_chan->used_desc.prev); | 554 | list_splice_tail(&new_chain, &ioat_chan->used_desc); |
555 | 555 | ||
556 | ioat_chan->dmacount += desc_count; | 556 | ioat_chan->dmacount += desc_count; |
557 | ioat_chan->pending += desc_count; | 557 | ioat_chan->pending += desc_count; |
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index 2622b6596d7c..3712b925b315 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c | |||
@@ -932,7 +932,7 @@ static struct ehci_qh *qh_append_tds ( | |||
932 | 932 | ||
933 | list_del (&qtd->qtd_list); | 933 | list_del (&qtd->qtd_list); |
934 | list_add (&dummy->qtd_list, qtd_list); | 934 | list_add (&dummy->qtd_list, qtd_list); |
935 | __list_splice (qtd_list, qh->qtd_list.prev); | 935 | list_splice_tail(qtd_list, &qh->qtd_list); |
936 | 936 | ||
937 | ehci_qtd_init(ehci, qtd, qtd->qtd_dma); | 937 | ehci_qtd_init(ehci, qtd, qtd->qtd_dma); |
938 | qh->dummy = qtd; | 938 | qh->dummy = qtd; |
diff --git a/include/linux/list.h b/include/linux/list.h index 453916bc0412..a886f27a1181 100644 --- a/include/linux/list.h +++ b/include/linux/list.h | |||
@@ -215,21 +215,21 @@ static inline int list_is_singular(const struct list_head *head) | |||
215 | } | 215 | } |
216 | 216 | ||
217 | static inline void __list_splice(const struct list_head *list, | 217 | static inline void __list_splice(const struct list_head *list, |
218 | struct list_head *head) | 218 | struct list_head *prev, |
219 | struct list_head *next) | ||
219 | { | 220 | { |
220 | struct list_head *first = list->next; | 221 | struct list_head *first = list->next; |
221 | struct list_head *last = list->prev; | 222 | struct list_head *last = list->prev; |
222 | struct list_head *at = head->next; | ||
223 | 223 | ||
224 | first->prev = head; | 224 | first->prev = prev; |
225 | head->next = first; | 225 | prev->next = first; |
226 | 226 | ||
227 | last->next = at; | 227 | last->next = next; |
228 | at->prev = last; | 228 | next->prev = last; |
229 | } | 229 | } |
230 | 230 | ||
231 | /** | 231 | /** |
232 | * list_splice - join two lists | 232 | * list_splice - join two lists, this is designed for stacks |
233 | * @list: the new list to add. | 233 | * @list: the new list to add. |
234 | * @head: the place to add it in the first list. | 234 | * @head: the place to add it in the first list. |
235 | */ | 235 | */ |
@@ -237,7 +237,19 @@ static inline void list_splice(const struct list_head *list, | |||
237 | struct list_head *head) | 237 | struct list_head *head) |
238 | { | 238 | { |
239 | if (!list_empty(list)) | 239 | if (!list_empty(list)) |
240 | __list_splice(list, head); | 240 | __list_splice(list, head, head->next); |
241 | } | ||
242 | |||
243 | /** | ||
244 | * list_splice_tail - join two lists, each list being a queue | ||
245 | * @list: the new list to add. | ||
246 | * @head: the place to add it in the first list. | ||
247 | */ | ||
248 | static inline void list_splice_tail(struct list_head *list, | ||
249 | struct list_head *head) | ||
250 | { | ||
251 | if (!list_empty(list)) | ||
252 | __list_splice(list, head->prev, head); | ||
241 | } | 253 | } |
242 | 254 | ||
243 | /** | 255 | /** |
@@ -251,7 +263,24 @@ static inline void list_splice_init(struct list_head *list, | |||
251 | struct list_head *head) | 263 | struct list_head *head) |
252 | { | 264 | { |
253 | if (!list_empty(list)) { | 265 | if (!list_empty(list)) { |
254 | __list_splice(list, head); | 266 | __list_splice(list, head, head->next); |
267 | INIT_LIST_HEAD(list); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * list_splice_tail_init - join two lists, each list being a queue, and | ||
273 | * reinitialise the emptied list. | ||
274 | * @list: the new list to add. | ||
275 | * @head: the place to add it in the first list. | ||
276 | * | ||
277 | * The list at @list is reinitialised | ||
278 | */ | ||
279 | static inline void list_splice_tail_init(struct list_head *list, | ||
280 | struct list_head *head) | ||
281 | { | ||
282 | if (!list_empty(list)) { | ||
283 | __list_splice(list, head->prev, head); | ||
255 | INIT_LIST_HEAD(list); | 284 | INIT_LIST_HEAD(list); |
256 | } | 285 | } |
257 | } | 286 | } |