Kernel modules syntaxes

Discussion in 'C Programming' started by InuY4sha, Apr 9, 2008.

  1. InuY4sha

    InuY4sha Guest

    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!
    InuY4sha, Apr 9, 2008
    #1
    1. Advertising

  2. 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.
    Antoninus Twink, Apr 9, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -
    Replies:
    2
    Views:
    358
    Bryce
    Jun 8, 2005
  2. Juan R.
    Replies:
    1
    Views:
    410
    Juan R.
    Feb 11, 2006
  3. yogesh
    Replies:
    3
    Views:
    575
    Kenny McCormack
    Feb 12, 2006
  4. Replies:
    3
    Views:
    160
  5. Lars Gierth
    Replies:
    6
    Views:
    212
    David Masover
    Mar 20, 2010
Loading...

Share This Page