corrupted pointer in 'net_device'

Discussion in 'Linux Networking' started by Mark, Oct 14, 2012.

  1. Mark

    Mark Guest


    the device driver I'm working on is implementing a virtual device. The logic
    is as follows:

    static struct net_device_ops virt_net_ops = {
    .ndo_init = virt_net_init,
    .ndo_open = virt_net_open,
    .ndo_stop = virt_net_stop,
    .ndo_do_ioctl = virt_net_ioctl,
    .ndo_get_stats = virt_net_get_stats,
    .ndo_start_xmit = virt_net_start_xmit,


    struct net_device *dev;
    struct my_dev *virt;

    dev = alloc_netdev(..);
    /* check for NULL */

    virt = netdev_priv(dev);

    dev->netdev_ops = &virt_net_ops;
    SET_ETHTOOL_OPS(dev, &virt_ethtool_ops);
    dev_net_set(dev, net);
    virt->magic = MY_VIRT_DEV_MAGIC;
    ret = register_netdev(dev);
    if (ret) {
    printk("register_netdev failed\n");
    return ret;

    What happens is that somewhere somehow the pointer net_device_ops in
    'net_dev' gets corrupted, i.e.

    1) create the device the first time (allocated net_dev, init the fields
    including net_device_ops,which is
    initialized with a static structure containing function pointers), register
    the device with the kernel invoking register_netdev() - OK

    2) attempt to create the device with the same name again, repeat the above
    steps, call register_netdev() which will return negative and we
    free_netdev(dev) and return error to the caller.

    And between these two events the pointer to net_device_ops has changed,
    although nowhere in the code it is done explicitly except the initialization

    The kernel version is, platform MIPS.

    Could anybody suggest what possibly can go wrong?
    Appreciate any advices, thanks.

    Mark, Oct 14, 2012
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.