USB: chipidea: fix interrupt deadlock

commit 9aaa81c3366e8393a62374e3a1c67c69edc07b8a upstream.

Chipidea core was calling the interrupt handler from non-IRQ context
with interrupts enabled, something which can lead to a deadlock if
there's an actual interrupt trying to take a lock that's already held
(e.g. the controller lock in udc_irq()).

Add a wrapper that can be used to fake interrupts instead of calling the
handler directly.

Fixes: 3ecb3e09b0 ("usb: chipidea: Use extcon framework for VBUS and ID detect")
Fixes: 876d4e1e82 ("usb: chipidea: core: add wakeup support for extcon")
Cc: Peter Chen <peter.chen@kernel.org>
Cc: stable@vger.kernel.org      # 4.4
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20211021083447.20078-1-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Johan Hovold
2021-10-21 10:34:47 +02:00
committed by Greg Kroah-Hartman
parent 6edf4cffe1
commit 898622adb7

View File

@@ -509,7 +509,7 @@ int hw_device_reset(struct ci_hdrc *ci)
return 0; return 0;
} }
static irqreturn_t ci_irq(int irq, void *data) static irqreturn_t ci_irq_handler(int irq, void *data)
{ {
struct ci_hdrc *ci = data; struct ci_hdrc *ci = data;
irqreturn_t ret = IRQ_NONE; irqreturn_t ret = IRQ_NONE;
@@ -562,6 +562,15 @@ static irqreturn_t ci_irq(int irq, void *data)
return ret; return ret;
} }
static void ci_irq(struct ci_hdrc *ci)
{
unsigned long flags;
local_irq_save(flags);
ci_irq_handler(ci->irq, ci);
local_irq_restore(flags);
}
static int ci_cable_notifier(struct notifier_block *nb, unsigned long event, static int ci_cable_notifier(struct notifier_block *nb, unsigned long event,
void *ptr) void *ptr)
{ {
@@ -571,7 +580,7 @@ static int ci_cable_notifier(struct notifier_block *nb, unsigned long event,
cbl->connected = event; cbl->connected = event;
cbl->changed = true; cbl->changed = true;
ci_irq(ci->irq, ci); ci_irq(ci);
return NOTIFY_DONE; return NOTIFY_DONE;
} }
@@ -612,7 +621,7 @@ static int ci_usb_role_switch_set(struct usb_role_switch *sw,
if (cable) { if (cable) {
cable->changed = true; cable->changed = true;
cable->connected = false; cable->connected = false;
ci_irq(ci->irq, ci); ci_irq(ci);
spin_unlock_irqrestore(&ci->lock, flags); spin_unlock_irqrestore(&ci->lock, flags);
if (ci->wq && role != USB_ROLE_NONE) if (ci->wq && role != USB_ROLE_NONE)
flush_workqueue(ci->wq); flush_workqueue(ci->wq);
@@ -630,7 +639,7 @@ static int ci_usb_role_switch_set(struct usb_role_switch *sw,
if (cable) { if (cable) {
cable->changed = true; cable->changed = true;
cable->connected = true; cable->connected = true;
ci_irq(ci->irq, ci); ci_irq(ci);
} }
spin_unlock_irqrestore(&ci->lock, flags); spin_unlock_irqrestore(&ci->lock, flags);
pm_runtime_put_sync(ci->dev); pm_runtime_put_sync(ci->dev);
@@ -1166,7 +1175,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
} }
} }
ret = devm_request_irq(dev, ci->irq, ci_irq, IRQF_SHARED, ret = devm_request_irq(dev, ci->irq, ci_irq_handler, IRQF_SHARED,
ci->platdata->name, ci); ci->platdata->name, ci);
if (ret) if (ret)
goto stop; goto stop;
@@ -1287,11 +1296,11 @@ static void ci_extcon_wakeup_int(struct ci_hdrc *ci)
if (!IS_ERR(cable_id->edev) && ci->is_otg && if (!IS_ERR(cable_id->edev) && ci->is_otg &&
(otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS)) (otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS))
ci_irq(ci->irq, ci); ci_irq(ci);
if (!IS_ERR(cable_vbus->edev) && ci->is_otg && if (!IS_ERR(cable_vbus->edev) && ci->is_otg &&
(otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS)) (otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS))
ci_irq(ci->irq, ci); ci_irq(ci);
} }
static int ci_controller_resume(struct device *dev) static int ci_controller_resume(struct device *dev)