Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Kernel modules syntaxes

Reply
Thread Tools

Kernel modules syntaxes

 
 
InuY4sha
Guest
Posts: n/a
 
      04-09-2008
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!
 
Reply With Quote
 
 
 
 
Antoninus Twink
Guest
Posts: n/a
 
      04-09-2008
On 9 Apr 2008 at 11:08, InuY4sha wrote:
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
relative speed of incremention syntaxes (or "i=i+1" VS "i+=1") Laurent Python 33 08-22-2011 05:22 PM
kernel hangs after "UNCOMPRESSING KERNEL OK BOOTING KERNEL" yogesh C Programming 3 02-12-2006 11:19 AM
Canonical Science Today, and notation/syntaxes for CanonMath Juan R. XML 1 02-11-2006 06:37 PM
eclipse doesn't support new syntaxes - Java 2 06-08-2005 02:03 PM



Advertisments