Re: [PATCH] usb: core: Prevent infinite loops when usb_reset_device() unbinds/binds

From: Alan Stern
Date: Fri Oct 20 2023 - 11:46:54 EST


On Fri, Oct 20, 2023 at 08:31:38AM -0700, Douglas Anderson wrote:
> When we call usb_reset_device() and a driver doesn't implement
> pre_reset() and post_reset() methods then the USB core will attempt to
> unbind and rebind the driver in order to make reset work. This is a
> great general solution, but it has the potential to loop forever.
> Specifically, if the USB device is in a state that the USB device
> driver issues another usb_reset_device() after each rebind then we'll
> just continually unbind and rebind with no end.
>
> It's difficult to address this condition in a USB device driver
> because it's hard for the driver to keep state across each
> unbind/bind.

How about just adding appropriate pre_reset() and post_reset() methods?
This is precisely what they are meant for. Then the the unbind/rebind
loop wouldn't ever get started.

Alan Stern