Commit bd1f6829 authored by Max Filippov's avatar Max Filippov Committed by Luis Henriques

xtensa: ISS: fix locking in TAP network adapter

commit 24e94454 upstream.

- don't lock lp->lock in the iss_net_timer for the call of iss_net_poll,
  it will lock it itself;
- invert order of lp->lock and opened_lock acquisition in the
  iss_net_open to make it consistent with iss_net_poll;
- replace spin_lock with spin_lock_bh when acquiring locks used in
  iss_net_timer from non-atomic context;
- replace spin_lock_irqsave with spin_lock_bh in the iss_net_start_xmit
  as the driver doesn't use lp->lock in the hard IRQ context;
- replace __SPIN_LOCK_UNLOCKED(lp.lock) with spin_lock_init, otherwise
  lockdep is unhappy about using non-static key.
Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent f16f64f9
...@@ -349,8 +349,8 @@ static void iss_net_timer(unsigned long priv) ...@@ -349,8 +349,8 @@ static void iss_net_timer(unsigned long priv)
{ {
struct iss_net_private *lp = (struct iss_net_private *)priv; struct iss_net_private *lp = (struct iss_net_private *)priv;
spin_lock(&lp->lock);
iss_net_poll(); iss_net_poll();
spin_lock(&lp->lock);
mod_timer(&lp->timer, jiffies + lp->timer_val); mod_timer(&lp->timer, jiffies + lp->timer_val);
spin_unlock(&lp->lock); spin_unlock(&lp->lock);
} }
...@@ -361,7 +361,7 @@ static int iss_net_open(struct net_device *dev) ...@@ -361,7 +361,7 @@ static int iss_net_open(struct net_device *dev)
struct iss_net_private *lp = netdev_priv(dev); struct iss_net_private *lp = netdev_priv(dev);
int err; int err;
spin_lock(&lp->lock); spin_lock_bh(&lp->lock);
err = lp->tp.open(lp); err = lp->tp.open(lp);
if (err < 0) if (err < 0)
...@@ -376,9 +376,11 @@ static int iss_net_open(struct net_device *dev) ...@@ -376,9 +376,11 @@ static int iss_net_open(struct net_device *dev)
while ((err = iss_net_rx(dev)) > 0) while ((err = iss_net_rx(dev)) > 0)
; ;
spin_lock(&opened_lock); spin_unlock_bh(&lp->lock);
spin_lock_bh(&opened_lock);
list_add(&lp->opened_list, &opened); list_add(&lp->opened_list, &opened);
spin_unlock(&opened_lock); spin_unlock_bh(&opened_lock);
spin_lock_bh(&lp->lock);
init_timer(&lp->timer); init_timer(&lp->timer);
lp->timer_val = ISS_NET_TIMER_VALUE; lp->timer_val = ISS_NET_TIMER_VALUE;
...@@ -387,7 +389,7 @@ static int iss_net_open(struct net_device *dev) ...@@ -387,7 +389,7 @@ static int iss_net_open(struct net_device *dev)
mod_timer(&lp->timer, jiffies + lp->timer_val); mod_timer(&lp->timer, jiffies + lp->timer_val);
out: out:
spin_unlock(&lp->lock); spin_unlock_bh(&lp->lock);
return err; return err;
} }
...@@ -395,7 +397,7 @@ static int iss_net_close(struct net_device *dev) ...@@ -395,7 +397,7 @@ static int iss_net_close(struct net_device *dev)
{ {
struct iss_net_private *lp = netdev_priv(dev); struct iss_net_private *lp = netdev_priv(dev);
netif_stop_queue(dev); netif_stop_queue(dev);
spin_lock(&lp->lock); spin_lock_bh(&lp->lock);
spin_lock(&opened_lock); spin_lock(&opened_lock);
list_del(&opened); list_del(&opened);
...@@ -405,18 +407,17 @@ static int iss_net_close(struct net_device *dev) ...@@ -405,18 +407,17 @@ static int iss_net_close(struct net_device *dev)
lp->tp.close(lp); lp->tp.close(lp);
spin_unlock(&lp->lock); spin_unlock_bh(&lp->lock);
return 0; return 0;
} }
static int iss_net_start_xmit(struct sk_buff *skb, struct net_device *dev) static int iss_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct iss_net_private *lp = netdev_priv(dev); struct iss_net_private *lp = netdev_priv(dev);
unsigned long flags;
int len; int len;
netif_stop_queue(dev); netif_stop_queue(dev);
spin_lock_irqsave(&lp->lock, flags); spin_lock_bh(&lp->lock);
len = lp->tp.write(lp, &skb); len = lp->tp.write(lp, &skb);
...@@ -438,7 +439,7 @@ static int iss_net_start_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -438,7 +439,7 @@ static int iss_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
pr_err("%s: %s failed(%d)\n", dev->name, __func__, len); pr_err("%s: %s failed(%d)\n", dev->name, __func__, len);
} }
spin_unlock_irqrestore(&lp->lock, flags); spin_unlock_bh(&lp->lock);
dev_kfree_skb(skb); dev_kfree_skb(skb);
return NETDEV_TX_OK; return NETDEV_TX_OK;
...@@ -466,9 +467,9 @@ static int iss_net_set_mac(struct net_device *dev, void *addr) ...@@ -466,9 +467,9 @@ static int iss_net_set_mac(struct net_device *dev, void *addr)
if (!is_valid_ether_addr(hwaddr->sa_data)) if (!is_valid_ether_addr(hwaddr->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
spin_lock(&lp->lock); spin_lock_bh(&lp->lock);
memcpy(dev->dev_addr, hwaddr->sa_data, ETH_ALEN); memcpy(dev->dev_addr, hwaddr->sa_data, ETH_ALEN);
spin_unlock(&lp->lock); spin_unlock_bh(&lp->lock);
return 0; return 0;
} }
...@@ -520,11 +521,11 @@ static int iss_net_configure(int index, char *init) ...@@ -520,11 +521,11 @@ static int iss_net_configure(int index, char *init)
*lp = (struct iss_net_private) { *lp = (struct iss_net_private) {
.device_list = LIST_HEAD_INIT(lp->device_list), .device_list = LIST_HEAD_INIT(lp->device_list),
.opened_list = LIST_HEAD_INIT(lp->opened_list), .opened_list = LIST_HEAD_INIT(lp->opened_list),
.lock = __SPIN_LOCK_UNLOCKED(lp.lock),
.dev = dev, .dev = dev,
.index = index, .index = index,
}; };
spin_lock_init(&lp->lock);
/* /*
* If this name ends up conflicting with an existing registered * If this name ends up conflicting with an existing registered
* netdevice, that is OK, register_netdev{,ice}() will notice this * netdevice, that is OK, register_netdev{,ice}() will notice this
......
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