Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c605f3cd authored by Joe Lawrence's avatar Joe Lawrence Committed by Greg Kroah-Hartman
Browse files

usb: hub: take hub->hdev reference when processing from eventlist



During surprise device hotplug removal tests, it was observed that
hub_events may try to call usb_lock_device on a device that has already
been freed. Protect the usb_device by taking out a reference (under the
hub_event_lock) when hub_events pulls it off the list, returning the
reference after hub_events is finished using it.

Signed-off-by: default avatarJoe Lawrence <joe.lawrence@stratus.com>
Suggested-by: David Bulkow <david.bulkow@stratus.com> for using kref
Suggested-by: Alan Stern <stern@rowland.harvard.edu> for placement
Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a9c54caa
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -5024,9 +5024,10 @@ static void hub_events(void)


		hub = list_entry(tmp, struct usb_hub, event_list);
		hub = list_entry(tmp, struct usb_hub, event_list);
		kref_get(&hub->kref);
		kref_get(&hub->kref);
		hdev = hub->hdev;
		usb_get_dev(hdev);
		spin_unlock_irq(&hub_event_lock);
		spin_unlock_irq(&hub_event_lock);


		hdev = hub->hdev;
		hub_dev = hub->intfdev;
		hub_dev = hub->intfdev;
		intf = to_usb_interface(hub_dev);
		intf = to_usb_interface(hub_dev);
		dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n",
		dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n",
@@ -5139,6 +5140,7 @@ static void hub_events(void)
		usb_autopm_put_interface(intf);
		usb_autopm_put_interface(intf);
 loop_disconnected:
 loop_disconnected:
		usb_unlock_device(hdev);
		usb_unlock_device(hdev);
		usb_put_dev(hdev);
		kref_put(&hub->kref, hub_release);
		kref_put(&hub->kref, hub_release);


	} /* end while (1) */
	} /* end while (1) */