Why do we need list_for_each_safe() in for deleting nodes in kernel linked list?

后端 未结 2 1914
臣服心动
臣服心动 2021-02-13 03:43

I\'m learning how to use the kernel linked-list API from list.h.

I learned that I need to use list_for_each_safe() when deleting nodes off with list_d

2条回答
  •  清歌不尽
    2021-02-13 04:11

    pos = start;
    del(pos);
    pos = pos->next;
    

    as opposed to

    pos = start;
    n = pos->next;
    del(pos);
    pos = n;
    

    if del() is free() and memset(), pos->next is undefined

提交回复
热议问题