From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] usb: fastboot: Fix error path
Date: Tue, 17 Nov 2020 13:54:59 +0100 [thread overview]
Message-ID: <20201117125459.12072-1-s.hauer@pengutronix.de> (raw)
fastboot_bind() can fail in multiple ways. Roll back things already
done in the error path.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/usb/gadget/f_fastboot.c | 48 ++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index da3e0c7a8f..96924c4cb9 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -207,34 +207,43 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
ret = fastboot_generic_init(&f_fb->fastboot, opts->common.export_bbu);
if (ret)
- return ret;
+ goto err_wq_unregister;
/* DYNAMIC interface numbers assignments */
id = usb_interface_id(c, f);
- if (id < 0)
- return id;
+ if (id < 0) {
+ ret = id;
+ goto fb_generic_free;
+ }
+
interface_desc.bInterfaceNumber = id;
id = usb_string_id(c->cdev);
- if (id < 0)
- return id;
+ if (id < 0) {
+ ret = id;
+ goto fb_generic_free;
+ }
fastboot_string_defs[0].id = id;
interface_desc.iInterface = id;
us = usb_gstrings_attach(cdev, fastboot_strings, 1);
if (IS_ERR(us)) {
ret = PTR_ERR(us);
- return ret;
+ goto fb_generic_free;
}
f_fb->in_ep = usb_ep_autoconfig(gadget, &fs_ep_in);
- if (!f_fb->in_ep)
- return -ENODEV;
+ if (!f_fb->in_ep) {
+ ret = -ENODEV;
+ goto fb_generic_free;
+ }
f_fb->in_ep->driver_data = c->cdev;
f_fb->out_ep = usb_ep_autoconfig(gadget, &fs_ep_out);
- if (!f_fb->out_ep)
- return -ENODEV;
+ if (!f_fb->out_ep) {
+ ret = -ENODEV;
+ goto fb_generic_free;
+ }
f_fb->out_ep->driver_data = c->cdev;
hs_ep_out.bEndpointAddress = fs_ep_out.bEndpointAddress;
@@ -244,7 +253,7 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
if (!f_fb->out_req) {
puts("failed to alloc out req\n");
ret = -EINVAL;
- return ret;
+ goto fb_generic_free;
}
f_fb->out_req->complete = rx_handler_command;
@@ -254,15 +263,28 @@ static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
if (!f_fb->in_req) {
puts("failed alloc req in\n");
ret = -EINVAL;
- return ret;
+ goto err_free_out_req;
}
f_fb->in_req->complete = fastboot_complete;
ret = usb_assign_descriptors(f, fb_fs_descs, fb_hs_descs, NULL);
if (ret)
- return ret;
+ goto err_free_in_req;
return 0;
+
+err_free_in_req:
+ free(f_fb->in_req->buf);
+ usb_ep_free_request(f_fb->in_ep, f_fb->in_req);
+err_free_out_req:
+ free(f_fb->out_req->buf);
+ usb_ep_free_request(f_fb->out_ep, f_fb->out_req);
+fb_generic_free:
+ fastboot_generic_free(&f_fb->fastboot);
+err_wq_unregister:
+ wq_unregister(&f_fb->wq);
+
+ return ret;
}
static void fastboot_unbind(struct usb_configuration *c, struct usb_function *f)
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
reply other threads:[~2020-11-17 12:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201117125459.12072-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox