Skip to content

Commit

Permalink
smsc95xx: use usbnet->driver_priv
Browse files Browse the repository at this point in the history
Using `void *driver_priv` instead of `unsigned long data[]` is more
straightforward way to recover the `struct smsc95xx_priv *` from the
`struct net_device *`.

Signed-off-by: Andre Edich <andre.edich@microchip.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Andre Edich authored and David S. Miller committed Aug 28, 2020
1 parent 368be1c commit ad90a73
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions drivers/net/usb/smsc95xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ static unsigned int smsc95xx_hash(char addr[ETH_ALEN])
static void smsc95xx_set_multicast(struct net_device *netdev)
{
struct usbnet *dev = netdev_priv(netdev);
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
unsigned long flags;
int ret;

Expand Down Expand Up @@ -552,7 +552,7 @@ static int smsc95xx_phy_update_flowcontrol(struct usbnet *dev, u8 duplex,

static int smsc95xx_link_reset(struct usbnet *dev)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
struct mii_if_info *mii = &dev->mii;
struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
unsigned long flags;
Expand Down Expand Up @@ -620,7 +620,7 @@ static void smsc95xx_status(struct usbnet *dev, struct urb *urb)

static void set_carrier(struct usbnet *dev, bool link)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;

if (pdata->link_ok == link)
return;
Expand Down Expand Up @@ -749,7 +749,7 @@ static void smsc95xx_ethtool_get_wol(struct net_device *net,
struct ethtool_wolinfo *wolinfo)
{
struct usbnet *dev = netdev_priv(net);
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;

wolinfo->supported = SUPPORTED_WAKE;
wolinfo->wolopts = pdata->wolopts;
Expand All @@ -759,7 +759,7 @@ static int smsc95xx_ethtool_set_wol(struct net_device *net,
struct ethtool_wolinfo *wolinfo)
{
struct usbnet *dev = netdev_priv(net);
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
int ret;

if (wolinfo->wolopts & ~SUPPORTED_WAKE)
Expand Down Expand Up @@ -798,7 +798,7 @@ static int get_mdix_status(struct net_device *net)
static void set_mdix_status(struct net_device *net, __u8 mdix_ctrl)
{
struct usbnet *dev = netdev_priv(net);
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
int buf;

if ((pdata->chip_id == ID_REV_CHIP_ID_9500A_) ||
Expand Down Expand Up @@ -847,7 +847,7 @@ static int smsc95xx_get_link_ksettings(struct net_device *net,
struct ethtool_link_ksettings *cmd)
{
struct usbnet *dev = netdev_priv(net);
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
int retval;

retval = usbnet_get_link_ksettings(net, cmd);
Expand All @@ -862,7 +862,7 @@ static int smsc95xx_set_link_ksettings(struct net_device *net,
const struct ethtool_link_ksettings *cmd)
{
struct usbnet *dev = netdev_priv(net);
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
int retval;

if (pdata->mdix_ctrl != cmd->base.eth_tp_mdix_ctrl)
Expand Down Expand Up @@ -944,7 +944,7 @@ static int smsc95xx_set_mac_address(struct usbnet *dev)
/* starts the TX path */
static int smsc95xx_start_tx_path(struct usbnet *dev)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
unsigned long flags;
int ret;

Expand All @@ -964,7 +964,7 @@ static int smsc95xx_start_tx_path(struct usbnet *dev)
/* Starts the Receive path */
static int smsc95xx_start_rx_path(struct usbnet *dev, int in_pm)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
unsigned long flags;

spin_lock_irqsave(&pdata->mac_cr_lock, flags);
Expand Down Expand Up @@ -1021,7 +1021,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)

static int smsc95xx_reset(struct usbnet *dev)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
u32 read_buf, write_buf, burst_cap;
int ret = 0, timeout;

Expand Down Expand Up @@ -1249,7 +1249,7 @@ static const struct net_device_ops smsc95xx_netdev_ops = {

static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
{
struct smsc95xx_priv *pdata = NULL;
struct smsc95xx_priv *pdata;
u32 val;
int ret;

Expand All @@ -1261,13 +1261,12 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)
return ret;
}

dev->data[0] = (unsigned long)kzalloc(sizeof(struct smsc95xx_priv),
GFP_KERNEL);

pdata = (struct smsc95xx_priv *)(dev->data[0]);
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;

dev->driver_priv = pdata;

spin_lock_init(&pdata->mac_cr_lock);

/* LAN95xx devices do not alter the computed checksum of 0 to 0xffff.
Expand Down Expand Up @@ -1330,15 +1329,11 @@ static int smsc95xx_bind(struct usbnet *dev, struct usb_interface *intf)

static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);

if (pdata) {
cancel_delayed_work_sync(&pdata->carrier_check);
netif_dbg(dev, ifdown, dev->net, "free pdata\n");
kfree(pdata);
pdata = NULL;
dev->data[0] = 0;
}
struct smsc95xx_priv *pdata = dev->driver_priv;

cancel_delayed_work_sync(&pdata->carrier_check);
netif_dbg(dev, ifdown, dev->net, "free pdata\n");
kfree(pdata);
}

static u32 smsc_crc(const u8 *buffer, size_t len, int filter)
Expand Down Expand Up @@ -1388,7 +1383,7 @@ static int smsc95xx_link_ok_nopm(struct usbnet *dev)

static int smsc95xx_enter_suspend0(struct usbnet *dev)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
u32 val;
int ret;

Expand Down Expand Up @@ -1427,7 +1422,7 @@ static int smsc95xx_enter_suspend0(struct usbnet *dev)

static int smsc95xx_enter_suspend1(struct usbnet *dev)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
u32 val;
int ret;

Expand Down Expand Up @@ -1474,7 +1469,7 @@ static int smsc95xx_enter_suspend1(struct usbnet *dev)

static int smsc95xx_enter_suspend2(struct usbnet *dev)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
u32 val;
int ret;

Expand All @@ -1496,7 +1491,7 @@ static int smsc95xx_enter_suspend2(struct usbnet *dev)

static int smsc95xx_enter_suspend3(struct usbnet *dev)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
u32 val;
int ret;

Expand Down Expand Up @@ -1535,7 +1530,7 @@ static int smsc95xx_enter_suspend3(struct usbnet *dev)

static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
int ret;

if (!netif_running(dev->net)) {
Expand Down Expand Up @@ -1583,7 +1578,7 @@ static int smsc95xx_autosuspend(struct usbnet *dev, u32 link_up)
static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
{
struct usbnet *dev = usb_get_intfdata(intf);
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;
u32 val, link_up;
int ret;

Expand Down Expand Up @@ -1854,7 +1849,7 @@ static int smsc95xx_resume(struct usb_interface *intf)
u32 val;

BUG_ON(!dev);
pdata = (struct smsc95xx_priv *)(dev->data[0]);
pdata = dev->driver_priv;
suspend_flags = pdata->suspend_flags;

netdev_dbg(dev->net, "resume suspend_flags=0x%02x\n", suspend_flags);
Expand Down Expand Up @@ -2074,7 +2069,7 @@ static struct sk_buff *smsc95xx_tx_fixup(struct usbnet *dev,

static int smsc95xx_manage_power(struct usbnet *dev, int on)
{
struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
struct smsc95xx_priv *pdata = dev->driver_priv;

dev->intf->needs_remote_wakeup = on;

Expand Down

0 comments on commit ad90a73

Please sign in to comment.