fix(usbgadget): do not panic if a change isn't found (#481)

* fix(usbgadget): do not panic if a change isn't found

* chore(usbgadget): rebind usb after updating config
This commit is contained in:
Aveline
2025-05-20 00:34:32 +02:00
committed by GitHub
parent b4dd4961fc
commit a0f6d01465
3 changed files with 27 additions and 12 deletions

View File

@@ -177,12 +177,7 @@ func (u *UsbGadget) Init() error {
u.udc = udcs[0]
err := u.WithTransaction(func() error {
u.tx.MountConfigFS()
u.tx.CreateConfigPath()
u.tx.WriteGadgetConfig()
return nil
})
err := u.configureUsbGadget(false)
if err != nil {
return u.logError("unable to initialize USB stack", err)
}
@@ -196,13 +191,22 @@ func (u *UsbGadget) UpdateGadgetConfig() error {
u.loadGadgetConfig()
err := u.WithTransaction(func() error {
u.tx.WriteGadgetConfig()
return nil
})
err := u.configureUsbGadget(true)
if err != nil {
return u.logError("unable to update gadget config", err)
}
return nil
}
func (u *UsbGadget) configureUsbGadget(resetUsb bool) error {
return u.WithTransaction(func() error {
u.tx.MountConfigFS()
u.tx.CreateConfigPath()
u.tx.WriteGadgetConfig()
if resetUsb {
u.tx.RebindUsb(true)
}
return nil
})
}