Skip to content

Commit 7985239

Browse files
sudeep-hollaFelipe Balbi
authored and
Felipe Balbi
committed
usb: isp1760: fix possible deadlock in isp1760_udc_irq
Use spin_{un,}lock_irq{save,restore} in isp1760_udc_{start,stop} to prevent following potentially deadlock scenario between isp1760_udc_{start,stop} and isp1760_udc_irq : ================================= [ INFO: inconsistent lock state ] 4.0.0-rc2-00004-gf7bb2ef60173 #51 Not tainted --------------------------------- inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage. in:imklog/2118 [HC1[1]:SC0[0]:HE0:SE1] takes: (&(&udc->lock)->rlock){?.+...}, at: [<c0397a93>] isp1760_udc_irq+0x367/0x9dc {HARDIRQ-ON-W} state was registered at: [<c05135b3>] _raw_spin_lock+0x23/0x30 [<c0396b87>] isp1760_udc_start+0x23/0xf8 [<c039dc21>] udc_bind_to_driver+0x71/0xb0 [<c039de4f>] usb_gadget_probe_driver+0x53/0x9c [<bf80d0df>] usb_composite_probe+0x8a/0xa4 [libcomposite] [<bf8311a7>] 0xbf8311a7 [<c00088c5>] do_one_initcall+0x8d/0x17c [<c050b92d>] do_init_module+0x49/0x148 [<c0087323>] load_module+0xb7f/0xbc4 [<c0087471>] SyS_finit_module+0x51/0x74 [<c000d8c1>] ret_fast_syscall+0x1/0x68 irq event stamp: 4966 hardirqs last enabled at (4965): [<c05137df>] _raw_spin_unlock_irq+0x1f/0x24 hardirqs last disabled at (4966): [<c00110b3>] __irq_svc+0x33/0x64 softirqs last enabled at (4458): [<c0023475>] __do_softirq+0x23d/0x2d0 softirqs last disabled at (4389): [<c002380b>] irq_exit+0xef/0x15c other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&(&udc->lock)->rlock); <Interrupt> lock(&(&udc->lock)->rlock); *** DEADLOCK *** 1 lock held by in:imklog/2118: #0: (&f->f_pos_lock){+.+.+.}, at: [<c010a101>] __fdget_pos+0x31/0x34 Signed-off-by: Sudeep Holla <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Acked-by: Laurent Pinchart <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent 9eccca0 commit 7985239

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/usb/isp1760/isp1760-udc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,14 +1191,15 @@ static int isp1760_udc_start(struct usb_gadget *gadget,
11911191
struct usb_gadget_driver *driver)
11921192
{
11931193
struct isp1760_udc *udc = gadget_to_udc(gadget);
1194+
unsigned long flags;
11941195

11951196
/* The hardware doesn't support low speed. */
11961197
if (driver->max_speed < USB_SPEED_FULL) {
11971198
dev_err(udc->isp->dev, "Invalid gadget driver\n");
11981199
return -EINVAL;
11991200
}
12001201

1201-
spin_lock(&udc->lock);
1202+
spin_lock_irqsave(&udc->lock, flags);
12021203

12031204
if (udc->driver) {
12041205
dev_err(udc->isp->dev, "UDC already has a gadget driver\n");
@@ -1208,7 +1209,7 @@ static int isp1760_udc_start(struct usb_gadget *gadget,
12081209

12091210
udc->driver = driver;
12101211

1211-
spin_unlock(&udc->lock);
1212+
spin_unlock_irqrestore(&udc->lock, flags);
12121213

12131214
dev_dbg(udc->isp->dev, "starting UDC with driver %s\n",
12141215
driver->function);
@@ -1232,16 +1233,17 @@ static int isp1760_udc_start(struct usb_gadget *gadget,
12321233
static int isp1760_udc_stop(struct usb_gadget *gadget)
12331234
{
12341235
struct isp1760_udc *udc = gadget_to_udc(gadget);
1236+
unsigned long flags;
12351237

12361238
dev_dbg(udc->isp->dev, "%s\n", __func__);
12371239

12381240
del_timer_sync(&udc->vbus_timer);
12391241

12401242
isp1760_udc_write(udc, DC_MODE, 0);
12411243

1242-
spin_lock(&udc->lock);
1244+
spin_lock_irqsave(&udc->lock, flags);
12431245
udc->driver = NULL;
1244-
spin_unlock(&udc->lock);
1246+
spin_unlock_irqrestore(&udc->lock, flags);
12451247

12461248
return 0;
12471249
}

0 commit comments

Comments
 (0)