Hi Alan, > > On Fri, Jan 19, 2024 at 03:23:50PM +0000, Xu Yang wrote: > > > What happens if the provider module is unloaded but then > > > usb_role_switch_put() is called after usb_role_switch_unregister()? > > > Won't there be a NULL pointer dereference inside the put_device() call? > > > > The get_device() will be called after the user successfully get usb_role_switch > > device. So the resource of sw will continue to exist until usb_role_switch_put() > > is called. > > But look: Your patch essentially prevents usb_role_switch_set_role() > from running after the role-switch device has been unregistered. But > what if someone had already called usb_role_switch_set_role() before the > device was unregistered? Won't that eventually lead to problems if the > provider's module is then unloaded from memory? Yes, exactly it may happen. > > To put it another way, all those try_module_get() and module_put() calls > were originally added to prevent a specific problem from occurring. > Once you remove them, won't that problem be able to occur again? Yes, it will. Thanks for reminder about this. Thanks, Xu Yang