Commit 73212c9a authored by Stephen Hemminger's avatar Stephen Hemminger Committed by Greg Kroah-Hartman

[PATCH] usbnet: use alloc_etherdev to allocate private data

In order for network device lifetime stuff to work properly, it is necessary
for devices to allocate private data as part of alloc_etherdev.
Also, netdev_priv() is improvement over dereferencing netdev->priv
Signed-off-by: default avatarStephen Hemminger <shemminger@osdl.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent b52e3b4d
...@@ -567,7 +567,7 @@ static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 i ...@@ -567,7 +567,7 @@ static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 i
static void ax8817x_set_multicast(struct net_device *net) static void ax8817x_set_multicast(struct net_device *net)
{ {
struct usbnet *dev = (struct usbnet *) net->priv; struct usbnet *dev = netdev_priv(net);
struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
u8 rx_ctl = 0x8c; u8 rx_ctl = 0x8c;
...@@ -610,7 +610,7 @@ static void ax8817x_set_multicast(struct net_device *net) ...@@ -610,7 +610,7 @@ static void ax8817x_set_multicast(struct net_device *net)
static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
{ {
struct usbnet *dev = netdev->priv; struct usbnet *dev = netdev_priv(netdev);
u16 res; u16 res;
u8 buf[1]; u8 buf[1];
...@@ -623,7 +623,7 @@ static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) ...@@ -623,7 +623,7 @@ static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
{ {
struct usbnet *dev = netdev->priv; struct usbnet *dev = netdev_priv(netdev);
u16 res = val; u16 res = val;
u8 buf[1]; u8 buf[1];
...@@ -634,7 +634,7 @@ static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, i ...@@ -634,7 +634,7 @@ static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, i
static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
{ {
struct usbnet *dev = (struct usbnet *)net->priv; struct usbnet *dev = netdev_priv(net);
u8 opt; u8 opt;
if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
...@@ -654,7 +654,7 @@ static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *woli ...@@ -654,7 +654,7 @@ static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *woli
static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
{ {
struct usbnet *dev = (struct usbnet *)net->priv; struct usbnet *dev = netdev_priv(net);
u8 opt = 0; u8 opt = 0;
u8 buf[1]; u8 buf[1];
...@@ -675,7 +675,7 @@ static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolin ...@@ -675,7 +675,7 @@ static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolin
static int ax8817x_get_eeprom(struct net_device *net, static int ax8817x_get_eeprom(struct net_device *net,
struct ethtool_eeprom *eeprom, u8 *data) struct ethtool_eeprom *eeprom, u8 *data)
{ {
struct usbnet *dev = (struct usbnet *)net->priv; struct usbnet *dev = netdev_priv(net);
u16 *ebuf = (u16 *)data; u16 *ebuf = (u16 *)data;
int i; int i;
...@@ -704,14 +704,14 @@ static void ax8817x_get_drvinfo (struct net_device *net, ...@@ -704,14 +704,14 @@ static void ax8817x_get_drvinfo (struct net_device *net,
static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
{ {
struct usbnet *dev = (struct usbnet *)net->priv; struct usbnet *dev = netdev_priv(net);
return mii_ethtool_gset(&dev->mii,cmd); return mii_ethtool_gset(&dev->mii,cmd);
} }
static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
{ {
struct usbnet *dev = (struct usbnet *)net->priv; struct usbnet *dev = netdev_priv(net);
return mii_ethtool_sset(&dev->mii,cmd); return mii_ethtool_sset(&dev->mii,cmd);
} }
...@@ -2276,7 +2276,7 @@ static const struct driver_info zaurus_pxa_info = { ...@@ -2276,7 +2276,7 @@ static const struct driver_info zaurus_pxa_info = {
static int usbnet_change_mtu (struct net_device *net, int new_mtu) static int usbnet_change_mtu (struct net_device *net, int new_mtu)
{ {
struct usbnet *dev = (struct usbnet *) net->priv; struct usbnet *dev = netdev_priv(net);
if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET) if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET)
return -EINVAL; return -EINVAL;
...@@ -2302,7 +2302,8 @@ static int usbnet_change_mtu (struct net_device *net, int new_mtu) ...@@ -2302,7 +2302,8 @@ static int usbnet_change_mtu (struct net_device *net, int new_mtu)
static struct net_device_stats *usbnet_get_stats (struct net_device *net) static struct net_device_stats *usbnet_get_stats (struct net_device *net)
{ {
return &((struct usbnet *) net->priv)->stats; struct usbnet *dev = netdev_priv(net);
return &dev->stats;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -2569,7 +2570,7 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q) ...@@ -2569,7 +2570,7 @@ static int unlink_urbs (struct usbnet *dev, struct sk_buff_head *q)
static int usbnet_stop (struct net_device *net) static int usbnet_stop (struct net_device *net)
{ {
struct usbnet *dev = (struct usbnet *) net->priv; struct usbnet *dev = netdev_priv(net);
int temp; int temp;
DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup); DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
DECLARE_WAITQUEUE (wait, current); DECLARE_WAITQUEUE (wait, current);
...@@ -2616,7 +2617,7 @@ static int usbnet_stop (struct net_device *net) ...@@ -2616,7 +2617,7 @@ static int usbnet_stop (struct net_device *net)
static int usbnet_open (struct net_device *net) static int usbnet_open (struct net_device *net)
{ {
struct usbnet *dev = (struct usbnet *) net->priv; struct usbnet *dev = netdev_priv(net);
int retval = 0; int retval = 0;
struct driver_info *info = dev->driver_info; struct driver_info *info = dev->driver_info;
...@@ -2666,7 +2667,7 @@ static int usbnet_open (struct net_device *net) ...@@ -2666,7 +2667,7 @@ static int usbnet_open (struct net_device *net)
static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
{ {
struct usbnet *dev = net->priv; struct usbnet *dev = netdev_priv(net);
strncpy (info->driver, driver_name, sizeof info->driver); strncpy (info->driver, driver_name, sizeof info->driver);
strncpy (info->version, DRIVER_VERSION, sizeof info->version); strncpy (info->version, DRIVER_VERSION, sizeof info->version);
...@@ -2677,7 +2678,7 @@ static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo * ...@@ -2677,7 +2678,7 @@ static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *
static u32 usbnet_get_link (struct net_device *net) static u32 usbnet_get_link (struct net_device *net)
{ {
struct usbnet *dev = net->priv; struct usbnet *dev = netdev_priv(net);
/* If a check_connect is defined, return it's results */ /* If a check_connect is defined, return it's results */
if (dev->driver_info->check_connect) if (dev->driver_info->check_connect)
...@@ -2689,14 +2690,14 @@ static u32 usbnet_get_link (struct net_device *net) ...@@ -2689,14 +2690,14 @@ static u32 usbnet_get_link (struct net_device *net)
static u32 usbnet_get_msglevel (struct net_device *net) static u32 usbnet_get_msglevel (struct net_device *net)
{ {
struct usbnet *dev = net->priv; struct usbnet *dev = netdev_priv(net);
return dev->msg_level; return dev->msg_level;
} }
static void usbnet_set_msglevel (struct net_device *net, u32 level) static void usbnet_set_msglevel (struct net_device *net, u32 level)
{ {
struct usbnet *dev = net->priv; struct usbnet *dev = netdev_priv(net);
dev->msg_level = level; dev->msg_level = level;
} }
...@@ -2705,7 +2706,7 @@ static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd) ...@@ -2705,7 +2706,7 @@ static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
{ {
#ifdef NEED_MII #ifdef NEED_MII
{ {
struct usbnet *dev = (struct usbnet *)net->priv; struct usbnet *dev = netdev_priv(net);
if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL) if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL)
return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
...@@ -2817,7 +2818,7 @@ static void tx_complete (struct urb *urb, struct pt_regs *regs) ...@@ -2817,7 +2818,7 @@ static void tx_complete (struct urb *urb, struct pt_regs *regs)
static void usbnet_tx_timeout (struct net_device *net) static void usbnet_tx_timeout (struct net_device *net)
{ {
struct usbnet *dev = (struct usbnet *) net->priv; struct usbnet *dev = netdev_priv(net);
unlink_urbs (dev, &dev->txq); unlink_urbs (dev, &dev->txq);
tasklet_schedule (&dev->bh); tasklet_schedule (&dev->bh);
...@@ -2829,7 +2830,7 @@ static void usbnet_tx_timeout (struct net_device *net) ...@@ -2829,7 +2830,7 @@ static void usbnet_tx_timeout (struct net_device *net)
static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
{ {
struct usbnet *dev = (struct usbnet *) net->priv; struct usbnet *dev = netdev_priv(net);
int length; int length;
int retval = NET_XMIT_SUCCESS; int retval = NET_XMIT_SUCCESS;
struct urb *urb = NULL; struct urb *urb = NULL;
...@@ -3014,6 +3015,7 @@ static void usbnet_disconnect (struct usb_interface *intf) ...@@ -3014,6 +3015,7 @@ static void usbnet_disconnect (struct usb_interface *intf)
{ {
struct usbnet *dev; struct usbnet *dev;
struct usb_device *xdev; struct usb_device *xdev;
struct net_device *net;
dev = usb_get_intfdata(intf); dev = usb_get_intfdata(intf);
usb_set_intfdata(intf, NULL); usb_set_intfdata(intf, NULL);
...@@ -3026,7 +3028,8 @@ static void usbnet_disconnect (struct usb_interface *intf) ...@@ -3026,7 +3028,8 @@ static void usbnet_disconnect (struct usb_interface *intf)
xdev->bus->bus_name, xdev->devpath, xdev->bus->bus_name, xdev->devpath,
dev->driver_info->description); dev->driver_info->description);
unregister_netdev (dev->net); net = dev->net;
unregister_netdev (net);
/* we don't hold rtnl here ... */ /* we don't hold rtnl here ... */
flush_scheduled_work (); flush_scheduled_work ();
...@@ -3034,8 +3037,7 @@ static void usbnet_disconnect (struct usb_interface *intf) ...@@ -3034,8 +3037,7 @@ static void usbnet_disconnect (struct usb_interface *intf)
if (dev->driver_info->unbind) if (dev->driver_info->unbind)
dev->driver_info->unbind (dev, intf); dev->driver_info->unbind (dev, intf);
free_netdev(dev->net); free_netdev(net);
kfree (dev);
usb_put_dev (xdev); usb_put_dev (xdev);
} }
...@@ -3069,12 +3071,13 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) ...@@ -3069,12 +3071,13 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
status = -ENOMEM; status = -ENOMEM;
// set up our own records // set up our own records
if (!(dev = kmalloc (sizeof *dev, GFP_KERNEL))) { net = alloc_etherdev(sizeof(*dev));
if (!net) {
dbg ("can't kmalloc dev"); dbg ("can't kmalloc dev");
goto out; goto out;
} }
memset (dev, 0, sizeof *dev);
dev = netdev_priv(net);
dev->udev = xdev; dev->udev = xdev;
dev->driver_info = info; dev->driver_info = info;
dev->msg_level = msg_level; dev->msg_level = msg_level;
...@@ -3088,14 +3091,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) ...@@ -3088,14 +3091,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
dev->delay.data = (unsigned long) dev; dev->delay.data = (unsigned long) dev;
init_timer (&dev->delay); init_timer (&dev->delay);
// set up network interface records
net = alloc_etherdev(0);
if (!net)
goto out1;
SET_MODULE_OWNER (net); SET_MODULE_OWNER (net);
dev->net = net; dev->net = net;
net->priv = dev;
strcpy (net->name, "usb%d"); strcpy (net->name, "usb%d");
memcpy (net->dev_addr, node_id, sizeof node_id); memcpy (net->dev_addr, node_id, sizeof node_id);
...@@ -3144,8 +3141,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) ...@@ -3144,8 +3141,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
SET_NETDEV_DEV(dev->net, &udev->dev); SET_NETDEV_DEV(net, &udev->dev);
status = register_netdev (dev->net); status = register_netdev (net);
if (status) if (status)
goto out3; goto out3;
devinfo (dev, "register usbnet at usb-%s-%s, %s", devinfo (dev, "register usbnet at usb-%s-%s, %s",
...@@ -3156,16 +3153,15 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) ...@@ -3156,16 +3153,15 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
usb_set_intfdata (udev, dev); usb_set_intfdata (udev, dev);
// start as if the link is up // start as if the link is up
netif_device_attach (dev->net); netif_device_attach (net);
return 0; return 0;
out3: out3:
if (info->unbind) if (info->unbind)
info->unbind (dev, udev); info->unbind (dev, udev);
free_netdev(net);
out1: out1:
kfree(dev); free_netdev(net);
out: out:
usb_put_dev(xdev); usb_put_dev(xdev);
return status; return status;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment