Skip to content

Commit

Permalink
r8152: Fix a deadlock by doubly PM resume
Browse files Browse the repository at this point in the history
[ Upstream commit 776ac63 ]

r8152 driver sets up the MAC address at reset-resume, while
rtl8152_set_mac_address() has the temporary autopm get/put.  This may
lead to a deadlock as the PM lock has been already taken for the
execution of the runtime PM callback.

This patch adds the workaround to avoid the superfluous autpm when
called from rtl8152_reset_resume().

Link: https://bugzilla.suse.com/show_bug.cgi?id=1186194
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
tiwai authored and gregkh committed Aug 8, 2021
1 parent 5feeb2d commit a6b2ef5
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions drivers/net/usb/r8152.c
Expand Up @@ -1550,7 +1550,8 @@ static int
rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex,
u32 advertising);

static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
static int __rtl8152_set_mac_address(struct net_device *netdev, void *p,
bool in_resume)
{
struct r8152 *tp = netdev_priv(netdev);
struct sockaddr *addr = p;
Expand All @@ -1559,9 +1560,11 @@ static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
if (!is_valid_ether_addr(addr->sa_data))
goto out1;

ret = usb_autopm_get_interface(tp->intf);
if (ret < 0)
goto out1;
if (!in_resume) {
ret = usb_autopm_get_interface(tp->intf);
if (ret < 0)
goto out1;
}

mutex_lock(&tp->control);

Expand All @@ -1573,11 +1576,17 @@ static int rtl8152_set_mac_address(struct net_device *netdev, void *p)

mutex_unlock(&tp->control);

usb_autopm_put_interface(tp->intf);
if (!in_resume)
usb_autopm_put_interface(tp->intf);
out1:
return ret;
}

static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
{
return __rtl8152_set_mac_address(netdev, p, false);
}

/* Devices containing proper chips can support a persistent
* host system provided MAC address.
* Examples of this are Dell TB15 and Dell WD15 docks
Expand Down Expand Up @@ -1696,7 +1705,7 @@ static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa)
return ret;
}

static int set_ethernet_addr(struct r8152 *tp)
static int set_ethernet_addr(struct r8152 *tp, bool in_resume)
{
struct net_device *dev = tp->netdev;
struct sockaddr sa;
Expand All @@ -1709,7 +1718,7 @@ static int set_ethernet_addr(struct r8152 *tp)
if (tp->version == RTL_VER_01)
ether_addr_copy(dev->dev_addr, sa.sa_data);
else
ret = rtl8152_set_mac_address(dev, &sa);
ret = __rtl8152_set_mac_address(dev, &sa, in_resume);

return ret;
}
Expand Down Expand Up @@ -8442,7 +8451,7 @@ static int rtl8152_reset_resume(struct usb_interface *intf)
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
tp->rtl_ops.init(tp);
queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0);
set_ethernet_addr(tp);
set_ethernet_addr(tp, true);
return rtl8152_resume(intf);
}

Expand Down Expand Up @@ -9562,7 +9571,7 @@ static int rtl8152_probe(struct usb_interface *intf,
tp->rtl_fw.retry = true;
#endif
queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0);
set_ethernet_addr(tp);
set_ethernet_addr(tp, false);

usb_set_intfdata(intf, tp);

Expand Down

0 comments on commit a6b2ef5

Please sign in to comment.