在linux里内核通用列表中list_for_each经常被使用。但这里有一点值得注意,最近在自己项目里就碰到了。

list_for_each的定义如下:

#define list_for_each(pos, head) \

for(pos = (head)->next; pos != (head); pos = pos->next)

list_del的定义如下:

void list_del(struct list_head *entry)

{

__list_del(entry->entry->prev, entry->next);

entry->next = LIST_POSITION1;

entry->prev = LIST_POSITION2;

}

从定义中可以看到如果在list_for_each遍历过程中使用list_del,会出问题。list_del后,pos的next,prev都已经变为NULL, pos = pos->next运行时就会异常访问。

当在遍历列表时,应该使用list_for_each_safe;定义如下

#define list_for_each_safe(pos, n, head) \

for(pos = (head)->next, n = pos->next; pos != (head);

pos = n, n = pos->next)

转载于:https://www.cnblogs.com/Mingxx/archive/2011/06/30/2095025.html

list_for_each引起的问题相关推荐

  1. list_for_each()与list_for_each_safe()

    #define list_for_each(pos, head) \ for (pos = (head)->next; prefetch(pos->next), pos != (head) ...

  2. list_for_each,list_for_each_entry和list_for_each_entry_safe

    比较 共同点 1.list_for_each和list_for_each_entry都是遍历链表的两个宏,本质上都是for循环. 2.他们做的事情本质上都一样,A.获取链表头,B.判断链表项是不是链表 ...

  3. 2014.4新版uboot启动流程分析

    原文 http://blog.csdn.net/skyflying2012/article/details/25804209 此处转载有稍作修改 最近开始接触uboot,现在需要将2014.4版本ub ...

  4. linux下poll和epoll内核源代码剖析

    作者:董昊 博客链接http://donghao.org/uii/ poll和epoll的使用应该不用再多说了.当fd很多时,使用epoll比poll效率更高. 我们通过内核源码分析来看看到底是为什么 ...

  5. Kernel数据结构移植(list和rbtree)

    主要移植了内核中的 list,rbtree.使得这2个数据结构在用户态程序中也能使用. 同时用 cpputest 对移植后的代码进行了测试.(测试代码其实也是使用这2个数据结构的方法) 内核代码的如下 ...

  6. linux内核链表使用例,linux内核链表的使用例子

    linux内核链表的使用例子 #include #include #include #include #include #include MODULE_LICENSE("GPL") ...

  7. mipi屏在内核可以显示logo但是u-boot无法显示的问题【转】

    本文转载自:http://blog.csdn.net/fulinus/article/details/45071721 平台:瑞芯的rk3288 u-boot版本:u-boot-2014.10 ker ...

  8. pollepoll实现分析(二)——epoll实现

    Epoll实现分析--作者:lvyilong316 通过上一章分析,poll运行效率的两个瓶颈已经找出,现在的问题是怎么改进.首先,如果要监听1000个fd,每次poll都要把1000个fd 拷入内核 ...

  9. linux内核seq_file接口

    seq相关头文件linux/seq_file.h,seq相关函数的实现在fs/seq_file.c.seq函数最早是在2001年就引入了,但以前内核中一直用得不多,而到了2.6内核后,许多/proc的 ...

最新文章

  1. windows用 tree命令查看目录文件夹结构
  2. pyqt5如何循环遍历控件名_利用Python的PyQt5编写GUI界面教学,QT5还是比较难的
  3. Windows8系统服务终极优化
  4. cannot import name '_imaging' from 'PIL'
  5. UR #3 核聚变反应强度( gcd )
  6. Kerberos协议
  7. 计算机专业颈椎有问题,出现这4个表现,你的颈椎病已经很严重了!上班族尤需警惕_39健康网...
  8. Intel Sandy Bridge/Ivy Bridge架构/微架构/流水线 (1) - 特性概述
  9. 安装cuda时 提示toolkit installation failed using unsupported compiler解决方法
  10. zabbix mysql 分离_编译安装zabbix3.0 并且与mysql分离
  11. String、StringBuffer、StringBuilder有什么区别
  12. [转]一个软件设计的全过程(基于UML)
  13. 纽微特反省:别人犯错不敢说,那是因为自己不干活
  14. 用matlab做bp神经网络预测,matlab人工神经网络预测
  15. c# list转为json_C#中List集合转换JSON
  16. Excel VBA与VSTO基础实战指南 VBA和VSTO权威教材
  17. 服务器频繁重启怎么解决
  18. Component name “XXX“ should always be multi-word vue/multi-word-component-names
  19. java date the type is ambiguous_java 调用方法引起歧义:The method XXX is ambiguous for the type XX...
  20. python代码库-吐血整理!绝不能错过的24个Python库

热门文章

  1. python恶搞表情包-用 Python 把你的朋友变成表情包
  2. python绘制条形图-python3使用matplotlib绘制条形图
  3. python画树叶-使用Python turtle画分形树叶图
  4. python游戏-练习项目19:使用python制作游戏(上)
  5. 重庆python培训-重庆Python培训班学完能做什么
  6. 21天精通python-21天学通Python 完整pdf扫描版[58MB]
  7. python介绍和用途-python中模块的介绍与使用
  8. python职能-高级Python开发工程师职位描述与岗位职责任职要求
  9. python语言的理解-Python动态语言理解
  10. python3.7.2教程-centos7系统下python2与python3共存