list: fix list_replace() for empty lists
Before, it would happily copy list_head next/prev (ie. pointer to the *from* list_head), leaving things in a confused state and causing much mayhem. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
parent
09fe35b450
commit
23dd9eaa94
|
@ -71,13 +71,19 @@ static inline void list_addtail(struct list_head *item, struct list_head *list)
|
|||
list->prev = item;
|
||||
}
|
||||
|
||||
static inline bool list_empty(struct list_head *list);
|
||||
|
||||
static inline void list_replace(struct list_head *from, struct list_head *to)
|
||||
{
|
||||
if (list_empty(from)) {
|
||||
list_inithead(to);
|
||||
} else {
|
||||
to->prev = from->prev;
|
||||
to->next = from->next;
|
||||
from->next->prev = to;
|
||||
from->prev->next = to;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void list_del(struct list_head *item)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue