Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: cdnsp: Fix lack of spin_lock_irqsave/spin_lock_restore

Patch puts content of cdnsp_gadget_pullup function inside
spin_lock_irqsave and spin_lock_restore section.
This construction is required here to keep the data consistency,
otherwise some data can be changed e.g. from interrupt context.

Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver")
Reported-by: Ken (Jian) He <jianhe@ambarella.com>
cc: <stable@vger.kernel.org>
Signed-off-by: Pawel Laszczak <pawell@cadence.com>
--

Changelog:
v2:
- added disable_irq/enable_irq as sugester by Peter Chen

drivers/usb/cdns3/cdnsp-gadget.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

Reviewed-by: Peter Chen <peter.chen@kernel.org>
Link: https://lore.kernel.org/r/20211214045527.26823-1-pawell@gli-login.cadence.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Pawel Laszczak and committed by
Greg Kroah-Hartman
4c4e162d 0ad3bd56

+12
+12
drivers/usb/cdns3/cdnsp-gadget.c
··· 1541 1541 { 1542 1542 struct cdnsp_device *pdev = gadget_to_cdnsp(gadget); 1543 1543 struct cdns *cdns = dev_get_drvdata(pdev->dev); 1544 + unsigned long flags; 1544 1545 1545 1546 trace_cdnsp_pullup(is_on); 1547 + 1548 + /* 1549 + * Disable events handling while controller is being 1550 + * enabled/disabled. 1551 + */ 1552 + disable_irq(cdns->dev_irq); 1553 + spin_lock_irqsave(&pdev->lock, flags); 1546 1554 1547 1555 if (!is_on) { 1548 1556 cdnsp_reset_device(pdev); ··· 1558 1550 } else { 1559 1551 cdns_set_vbus(cdns); 1560 1552 } 1553 + 1554 + spin_unlock_irqrestore(&pdev->lock, flags); 1555 + enable_irq(cdns->dev_irq); 1556 + 1561 1557 return 0; 1562 1558 } 1563 1559