mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
BACKPORT: USB: gadget: core: create sysfs link between udc and gadget
udc device and gadget device are tightly coupled, yet there's no good way to corelate the two. Add a sysfs link in udc that points to the corresponding gadget device. An example use case: userspace configures a f_midi configfs driver and bind the udc device, then it tries to locate the corresponding midi device, which is a child device of the gadget device. The gadget device that's associated to the udc device has to be identified in order to index the midi device. Having a sysfs link would make things much easier. Signed-off-by: Roy Luo <royluo@google.com> Link: https://lore.kernel.org/r/20240307030922.3573161-1-royluo@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Bug: 333778731 Change-Id: I9e3f782543eba5e026a65031aaae754daafb69ab (cherry picked from commit 0ef40f399aa2be8c04aee9b7430705612c104ce5) [royluo: Resolved conflict in drivers/usb/gadget/udc/core.c ] Signed-off-by: Roy Luo <royluo@google.com>
This commit is contained in:
@@ -1414,6 +1414,11 @@ int usb_add_gadget(struct usb_gadget *gadget)
|
||||
if (ret)
|
||||
goto err_del_udc;
|
||||
|
||||
ret = sysfs_create_link(&udc->dev.kobj,
|
||||
&gadget->dev.kobj, "gadget");
|
||||
if (ret)
|
||||
goto err_del_udc;
|
||||
|
||||
mutex_unlock(&udc_lock);
|
||||
|
||||
return 0;
|
||||
@@ -1556,6 +1561,7 @@ void usb_del_gadget(struct usb_gadget *gadget)
|
||||
mutex_unlock(&udc_lock);
|
||||
|
||||
kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
|
||||
sysfs_remove_link(&udc->dev.kobj, "gadget");
|
||||
flush_work(&gadget->work);
|
||||
device_unregister(&udc->dev);
|
||||
device_del(&gadget->dev);
|
||||
|
||||
Reference in New Issue
Block a user