Re: [PATCH] usb:xhci:Fix slot_id resource race conflict

From: WeitaoWang-oc@xxxxxxxxxxx
Date: Thu Jul 24 2025 - 03:32:42 EST


On 2025/7/24 14:36, Greg KH wrote:


[这封邮件来自外部发件人 谨防风险]

On Thu, Jul 24, 2025 at 08:40:12PM +0800, Weitao Wang wrote:
@@ -4085,10 +4086,11 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
for (i = 0; i < 31; i++)
virt_dev->eps[i].ep_state &= ~EP_STOP_CMD_PENDING;
virt_dev->udev = NULL;
- xhci_disable_slot(xhci, udev->slot_id);
+ ret = xhci_disable_slot(xhci, udev->slot_id);

spin_lock_irqsave(&xhci->lock, flags);
- xhci_free_virt_device(xhci, udev->slot_id);
+ if (ret)
+ xhci_free_virt_device(xhci, udev->slot_id);
spin_unlock_irqrestore(&xhci->lock, flags);

Shouldn't you lock/unlock only if ret is set?

Yes,it's my mistake,here's code should like this:

ret = xhci_disable_slot(xhci, udev->slot_id);
if (ret) {
spin_lock_irqsave(&xhci->lock, flags);
xhci_free_virt_device(xhci, udev->slot_id);
spin_unlock_irqrestore(&xhci->lock, flags);
}
Thanks for your suggestion. I'll revise it in the next patch version.

Best Regards,
weitao


greg k-h
.