Kernel modules syntaxes

I

InuY4sha

Hi all,
I already asked about this line but now the question is slightly
different .. so I've got a module
"pippo.c" and within its code I've got the following lines:

00001 static int mynd_dev_init(struct net_device *dev);
00002 struct net_device my_device = { init: mynd_dev_init, };
.....
.....
00100 static int __init mynd_init(void){
00101 struct net_device *dev = &my_device;
00102 register_netdev(dev);
00103 }
00104 module_init(mynd_init);

I'm guessing, these instructions tell the kernel that when it
initializes "dev" (through the register_netdev function) it has to
use the mynd_dev_init function.
What I don't get is how the "dev" structure is then passed as the
input parameter to mynd_dev_init???
Again, I'm guessing this is implicitly done through the
"register_netdev" function, to which basically 2 information elements
are given as input parameters: the net_device structure and the
net_device initialization function (as a field of the net_device
structure itself).
Am I guessing right???

Thanks in advance,
Riccardo

Am I guessing right?
Thanks guys!
 
A

Antoninus Twink

Hi all,
I already asked about this line but now the question is slightly
different .. so I've got a module
"pippo.c" and within its code I've got the following lines:

00001 static int mynd_dev_init(struct net_device *dev);
00002 struct net_device my_device = { init: mynd_dev_init, };
....
....
00100 static int __init mynd_init(void){
00101 struct net_device *dev = &my_device;
00102 register_netdev(dev);
00103 }
00104 module_init(mynd_init);

Be warned that most of my programming is at user-level, with only a bit
of dabbling and hacking at kernel-level, so you should treat what I say
with skepticism.
I'm guessing, these instructions tell the kernel that when it
initializes "dev" (through the register_netdev function) it has to
use the mynd_dev_init function.

Yes: if the init field is not NULL, then it will be called during
registration, and passed the same struct net_device * argument that
register_netdev received.
What I don't get is how the "dev" structure is then passed as the
input parameter to mynd_dev_init???
Again, I'm guessing this is implicitly done through the
"register_netdev" function, to which basically 2 information elements
are given as input parameters: the net_device structure and the
net_device initialization function (as a field of the net_device
structure itself).
Am I guessing right???

Yes. Perhaps you are being confused by the fact that my_device is doing
double-duty: it's being passed as an argument to a function which is
(pointed to by) a field of itself. Probably mynd_dev_init will fill in
other fields in my_device.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top