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 84811412464d ("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 <hayeswang@realtek.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Hayes Wang and committed by David S. Miller 5b1d9c17 06829937

Changed files
+20 -8
drivers
net
usb
+20 -8
drivers/net/usb/r8152.c
··· 4552 4552 4553 4553 netif_stop_queue(netdev); 4554 4554 tasklet_disable(&tp->tx_tl); 4555 - napi_disable(&tp->napi); 4556 4555 clear_bit(WORK_ENABLE, &tp->flags); 4557 4556 usb_kill_urb(tp->intr_urb); 4558 4557 cancel_delayed_work_sync(&tp->schedule); 4558 + napi_disable(&tp->napi); 4559 4559 if (netif_carrier_ok(netdev)) { 4560 4560 mutex_lock(&tp->control); 4561 4561 tp->rtl_ops.disable(tp); ··· 4673 4673 4674 4674 netif_device_attach(netdev); 4675 4675 4676 - if (netif_running(netdev) && netdev->flags & IFF_UP) { 4676 + if (netif_running(netdev) && (netdev->flags & IFF_UP)) { 4677 4677 tp->rtl_ops.up(tp); 4678 4678 netif_carrier_off(netdev); 4679 4679 set_bit(WORK_ENABLE, &tp->flags); ··· 5244 5244 } 5245 5245 5246 5246 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 + } 5250 5256 } 5251 5257 break; 5252 5258 default: ··· 5280 5274 return -EINVAL; 5281 5275 5282 5276 if (tp->rx_pending != ring->rx_pending) { 5283 - napi_disable(&tp->napi); 5284 - tp->rx_pending = ring->rx_pending; 5285 - napi_enable(&tp->napi); 5277 + if (netdev->flags & IFF_UP) { 5278 + mutex_lock(&tp->control); 5279 + napi_disable(&tp->napi); 5280 + tp->rx_pending = ring->rx_pending; 5281 + napi_enable(&tp->napi); 5282 + mutex_unlock(&tp->control); 5283 + } else { 5284 + tp->rx_pending = ring->rx_pending; 5285 + } 5286 5286 } 5287 5287 5288 5288 return 0;