how to export symbol from kernel module in this case?

爱⌒轻易说出口 提交于 2019-12-12 01:53:33

问题


I've got two kernel modules built, one of which is a net_device. My net_device module A depends on module B which provide some extra control mechanism to export device info.

Now, I want to be able to call the xmit function in module A from module B. As a result, module B will become dependent on module A if I simple export symbol from A. This, obviously, creates a 'deadlock' like dependency situation.

Does anyone have experience resolving this? How can I properly export the xmit function in A and let B use it?

Thanks ahead.


回答1:


You may provide the callback function from module A. In that case you don't need to export each function you need to the kernel namespace. I presume you just could supply some structure to the B. Something like:

internal header:

struct possible_ops {
    int (*xmit)(...);
};

A:

struct private {
    struct possible_ops *ops;
};
...  
ops = kzalloc(sizeof(*ops));
ops->xmit = xmit;

B:

whatever(struct possible_ops *ops) {
    if (ops && ops->xmit) {
        ret = ops->xmit();
        ...
    }
}


来源:https://stackoverflow.com/questions/27769368/how-to-export-symbol-from-kernel-module-in-this-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!