summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-01-20 10:03:45 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-03-09 09:37:03 +0100
commit2b9bcff79a02f770fa730e2689ba35cc03c0da7d (patch)
treea72b52a9e256fecb01d1a1d69acb6359343cff20 /commands
parent25fd64ed22b56b875c3f8d8bffd737a38084cf96 (diff)
downloadbarebox-2b9bcff79a02f770fa730e2689ba35cc03c0da7d.tar.gz
barebox-2b9bcff79a02f770fa730e2689ba35cc03c0da7d.tar.xz
usb: gadget: properly release f_multi_opts
The usbgadget commands uses statically allocated f_multi_opts and passes this to usb_multi_register(). These f_multi_opts are of course no longer valid when we leave the usbgadget command. Luckily we do not use the data after we left the usbgadget command, so this never has been a problem. However, f_multi_opts has some allocated members which we can not free anymore on gadget unregistration because we no longer have the pointer to them. Fix this by adding a release function to struct f_multi_opts. This way we can allocate all memory dynamically and properly free it when not used anymore. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/usbgadget.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index a7e8d6c0c3..314884aee8 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -31,10 +31,10 @@
static int do_usbgadget(int argc, char *argv[])
{
- int opt;
+ int opt, ret;
int acm = 1, create_serial = 0;
char *fastboot_opts = NULL, *dfu_opts = NULL;
- struct f_multi_opts opts = {};
+ struct f_multi_opts *opts;
while ((opt = getopt(argc, argv, "asdA:D:")) > 0) {
switch (opt) {
@@ -73,19 +73,26 @@ static int do_usbgadget(int argc, char *argv[])
return -EINVAL;
}
+ opts = xzalloc(sizeof(*opts));
+ opts->release = usb_multi_opts_release;
+
if (fastboot_opts) {
- opts.fastboot_opts.files = file_list_parse(fastboot_opts);
+ opts->fastboot_opts.files = file_list_parse(fastboot_opts);
}
if (dfu_opts) {
- opts.dfu_opts.files = file_list_parse(dfu_opts);
+ opts->dfu_opts.files = file_list_parse(dfu_opts);
}
if (create_serial) {
- opts.create_acm = acm;
+ opts->create_acm = acm;
}
- return usb_multi_register(&opts);
+ ret = usb_multi_register(opts);
+ if (ret)
+ usb_multi_opts_release(opts);
+
+ return ret;
}
BAREBOX_CMD_HELP_START(usbgadget)