Skip to content

Commit 72c6187

Browse files
wensgregkh
authored andcommitted
phy: sun4i-usb: Use spinlock to guard phyctl register access
commit 919ab25 upstream. The musb driver calls into this phy driver to disable/enable squelch detection. This function was introduced in 24fe86a ("phy: sun4i-usb: Add a sunxi specific function for setting squelch-detect"). This function in turn calls sun4i_usb_phy_write, which uses a mutex to guard the common access register. Unfortunately musb does this in atomic context, which results in the following warning with lock debugging enabled: BUG: sleeping function called from invalid context at kernel/locking/mutex.c:97 in_atomic(): 1, irqs_disabled(): 128, pid: 96, name: kworker/0:2 CPU: 0 PID: 96 Comm: kworker/0:2 Not tainted 4.8.0-rc4-00181-gd502f8ad1c3e #13 Hardware name: Allwinner sun8i Family Workqueue: events musb_deassert_reset [<c010bc01>] (unwind_backtrace) from [<c0109237>] (show_stack+0xb/0xc) [<c0109237>] (show_stack) from [<c02a669b>] (dump_stack+0x67/0x74) [<c02a669b>] (dump_stack) from [<c05d68c9>] (mutex_lock+0x15/0x2c) [<c05d68c9>] (mutex_lock) from [<c02c3589>] (sun4i_usb_phy_write+0x39/0xec) [<c02c3589>] (sun4i_usb_phy_write) from [<c03e6327>] (musb_port_reset+0xfb/0x184) [<c03e6327>] (musb_port_reset) from [<c03e4917>] (musb_deassert_reset+0x1f/0x2c) [<c03e4917>] (musb_deassert_reset) from [<c012ecb5>] (process_one_work+0x129/0x2b8) [<c012ecb5>] (process_one_work) from [<c012f5e3>] (worker_thread+0xf3/0x424) [<c012f5e3>] (worker_thread) from [<c0132dbd>] (kthread+0xa1/0xb8) [<c0132dbd>] (kthread) from [<c0105f31>] (ret_from_fork+0x11/0x20) Since the register access is mmio, we can use a spinlock to guard this specific access, rather than the mutex that guards the entire phy. Fixes: ba4bdc9 ("PHY: sunxi: Add driver for sunxi usb phy") Cc: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Chen-Yu Tsai <wens@csie.org> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ac8aa11 commit 72c6187

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/phy/phy-sun4i-usb.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/power_supply.h>
4141
#include <linux/regulator/consumer.h>
4242
#include <linux/reset.h>
43+
#include <linux/spinlock.h>
4344
#include <linux/usb/of.h>
4445
#include <linux/workqueue.h>
4546

@@ -112,7 +113,7 @@ struct sun4i_usb_phy_data {
112113
void __iomem *base;
113114
const struct sun4i_usb_phy_cfg *cfg;
114115
enum usb_dr_mode dr_mode;
115-
struct mutex mutex;
116+
spinlock_t reg_lock; /* guard access to phyctl reg */
116117
struct sun4i_usb_phy {
117118
struct phy *phy;
118119
void __iomem *pmu;
@@ -179,9 +180,10 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
179180
struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy);
180181
u32 temp, usbc_bit = BIT(phy->index * 2);
181182
void __iomem *phyctl = phy_data->base + phy_data->cfg->phyctl_offset;
183+
unsigned long flags;
182184
int i;
183185

184-
mutex_lock(&phy_data->mutex);
186+
spin_lock_irqsave(&phy_data->reg_lock, flags);
185187

186188
if (phy_data->cfg->type == sun8i_a33_phy) {
187189
/* A33 needs us to set phyctl to 0 explicitly */
@@ -218,7 +220,8 @@ static void sun4i_usb_phy_write(struct sun4i_usb_phy *phy, u32 addr, u32 data,
218220

219221
data >>= 1;
220222
}
221-
mutex_unlock(&phy_data->mutex);
223+
224+
spin_unlock_irqrestore(&phy_data->reg_lock, flags);
222225
}
223226

224227
static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable)
@@ -577,7 +580,7 @@ static int sun4i_usb_phy_probe(struct platform_device *pdev)
577580
if (!data)
578581
return -ENOMEM;
579582

580-
mutex_init(&data->mutex);
583+
spin_lock_init(&data->reg_lock);
581584
INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan);
582585
dev_set_drvdata(dev, data);
583586
data->cfg = of_device_get_match_data(dev);

0 commit comments

Comments
 (0)