Skip to content

Commit 5b1d9c1

Browse files
hayesorzdavem330
authored andcommitted
r8152: avoid to call napi_disable twice
Call napi_disable() twice would cause dead lock. There are three situations may result in the issue. 1. rtl8152_pre_reset() and set_carrier() are run at the same time. 2. Call rtl8152_set_tunable() after rtl8152_close(). 3. Call rtl8152_set_ringparam() after rtl8152_close(). For #1, use the same solution as commit 8481141 ("r8152: Re-order napi_disable in rtl8152_close"). For #2 and #3, add checking the flag of IFF_UP and using napi_disable/napi_enable during mutex. Signed-off-by: Hayes Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0682993 commit 5b1d9c1

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

drivers/net/usb/r8152.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,10 +4552,10 @@ static int rtl8152_pre_reset(struct usb_interface *intf)
45524552

45534553
netif_stop_queue(netdev);
45544554
tasklet_disable(&tp->tx_tl);
4555-
napi_disable(&tp->napi);
45564555
clear_bit(WORK_ENABLE, &tp->flags);
45574556
usb_kill_urb(tp->intr_urb);
45584557
cancel_delayed_work_sync(&tp->schedule);
4558+
napi_disable(&tp->napi);
45594559
if (netif_carrier_ok(netdev)) {
45604560
mutex_lock(&tp->control);
45614561
tp->rtl_ops.disable(tp);
@@ -4673,7 +4673,7 @@ static int rtl8152_system_resume(struct r8152 *tp)
46734673

46744674
netif_device_attach(netdev);
46754675

4676-
if (netif_running(netdev) && netdev->flags & IFF_UP) {
4676+
if (netif_running(netdev) && (netdev->flags & IFF_UP)) {
46774677
tp->rtl_ops.up(tp);
46784678
netif_carrier_off(netdev);
46794679
set_bit(WORK_ENABLE, &tp->flags);
@@ -5244,9 +5244,15 @@ static int rtl8152_set_tunable(struct net_device *netdev,
52445244
}
52455245

52465246
if (tp->rx_copybreak != val) {
5247-
napi_disable(&tp->napi);
5248-
tp->rx_copybreak = val;
5249-
napi_enable(&tp->napi);
5247+
if (netdev->flags & IFF_UP) {
5248+
mutex_lock(&tp->control);
5249+
napi_disable(&tp->napi);
5250+
tp->rx_copybreak = val;
5251+
napi_enable(&tp->napi);
5252+
mutex_unlock(&tp->control);
5253+
} else {
5254+
tp->rx_copybreak = val;
5255+
}
52505256
}
52515257
break;
52525258
default:
@@ -5274,9 +5280,15 @@ static int rtl8152_set_ringparam(struct net_device *netdev,
52745280
return -EINVAL;
52755281

52765282
if (tp->rx_pending != ring->rx_pending) {
5277-
napi_disable(&tp->napi);
5278-
tp->rx_pending = ring->rx_pending;
5279-
napi_enable(&tp->napi);
5283+
if (netdev->flags & IFF_UP) {
5284+
mutex_lock(&tp->control);
5285+
napi_disable(&tp->napi);
5286+
tp->rx_pending = ring->rx_pending;
5287+
napi_enable(&tp->napi);
5288+
mutex_unlock(&tp->control);
5289+
} else {
5290+
tp->rx_pending = ring->rx_pending;
5291+
}
52805292
}
52815293

52825294
return 0;

0 commit comments

Comments
 (0)