-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
Bug Description
/usr/bin/usbdevice hardcodes android0 when reading the USB gadget state at line 519:
USB_STATE=$(cat /sys/class/android_usb/android0/state)The kernel uses a monotonic counter (gadget_index++) in drivers/usb/gadget/configfs.c (android_device_create()) to name android_usb devices. If the configfs gadget directory (/sys/kernel/config/usb_gadget/rockchip) is removed with rmdir and recreated, the new device is named android1 instead of android0, because the counter is never decremented.
This causes usbdevice update to silently fail — USB_STATE becomes empty, and any logic that depends on the gadget state (e.g., UMS mount/unmount in ums_start()) misbehaves.
Root Cause
In drivers/usb/gadget/configfs.c:
static int gadget_index; // never decremented
static int android_device_create(struct gadget_info *gi)
{
gi->dev = device_create(android_class, NULL,
MKDEV(0, 0), NULL, "android%d", gadget_index++);
// ...
}Fix
Use a glob instead of hardcoding android0:
USB_STATE=$(cat /sys/class/android_usb/android*/state 2>/dev/null | head -1)This works regardless of which androidN device exists.
Environment
- Board: RK3588 (LubanCat)
- Kernel: 5.10.160
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels