检索 list_head 对象的父结构

dai*_*isy 1 c linux struct kernel linked-list

在 linux 内核中有一个struct XX包含struct list_head YY.

现在给出一个指向struct XX对象的指针,我想XX在链表中找到所有结构。所以我会遍历list_head结构体,然后找到对应的父结构体。

但是这里的第二步似乎不适用。所以我不确定是否有可能实现这一目标。

例子:

struct XX {
    ...
    struct list_head YY;
};
Run Code Online (Sandbox Code Playgroud)

jml*_*jml 5

您应该使用container_of宏(LDD3 第 3 章:打开方法)。