[PATCH 09/14] usbgadget: autostart: fix indeterminism around usbgadget.autostart
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Apr 12 23:34:57 BST 2021
The setter for usbgadget.autostart evaluates other device paramaters, so
it must happen postenvironment, otherwise it could run too early and not
see the device parameters it depends on. This was observed with
usbgadget.dfu_function, which wasn't loaded from the environment early
enough, but it now does.
While at it, remove some more wonkyness:
- usbgadget_autostart_set is only ever called when the
IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART), so drop the check
- There is no need to make usbgadget.acm specific to autostart.
It's behavior now is counter intuitive (enable Kconfig symbol,
but don't set global variable and it will have an effect.
Disable CONFIG_USB_GADGET_AUTOSTART, which looks completely
unrelated and it no longer works.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
common/usbgadget.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/common/usbgadget.c b/common/usbgadget.c
index feec0b6634be..0b2d9a2120f7 100644
--- a/common/usbgadget.c
+++ b/common/usbgadget.c
@@ -97,7 +97,7 @@ static int usbgadget_autostart_set(struct param_d *param, void *ctx)
bool fastboot_bbu = get_fastboot_bbu();
int err;
- if (!IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART) || !autostart || started)
+ if (!autostart || started)
return 0;
err = usbgadget_register(true, NULL, true, NULL, acm, fastboot_bbu);
@@ -109,17 +109,21 @@ static int usbgadget_autostart_set(struct param_d *param, void *ctx)
static int usbgadget_globalvars_init(void)
{
- if (IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART)) {
- globalvar_add_bool("usbgadget.autostart", usbgadget_autostart_set,
- &autostart, NULL);
- globalvar_add_simple_bool("usbgadget.acm", &acm);
- }
+ globalvar_add_simple_bool("usbgadget.acm", &acm);
globalvar_add_simple_string("usbgadget.dfu_function", &dfu_function);
return 0;
}
device_initcall(usbgadget_globalvars_init);
+static int usbgadget_autostart_init(void)
+{
+ if (IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART))
+ globalvar_add_bool("usbgadget.autostart", usbgadget_autostart_set, &autostart, NULL);
+ return 0;
+}
+postenvironment_initcall(usbgadget_autostart_init);
+
BAREBOX_MAGICVAR(global.usbgadget.autostart,
"usbgadget: Automatically start usbgadget on boot");
BAREBOX_MAGICVAR(global.usbgadget.acm,
--
2.29.2
More information about the barebox
mailing list