Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1289472
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v3 24/36] usb: gadget: f_hid: handle requests lifetime properly |
| Date | 2015-12-11 12:40 +0100 |
| Message-ID | <qEudk-3DB-13@gated-at.bofh.it> (permalink) |
| References | <qEu3E-3z9-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
So far USB requests allocated in hidg_set_alt() were not freed. Now we
free them in case of hidg_set_alt() failure (when we are not able to
allocate and enqueue all the requests) or in hidg_disable() function.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_hid.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 99285b4..0456a53 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -59,6 +59,7 @@ struct f_hidg {
bool write_pending;
wait_queue_head_t write_queue;
struct usb_request *req;
+ struct usb_request **out_reqs;
int minor;
struct cdev cdev;
@@ -490,6 +491,7 @@ static void hidg_disable(struct usb_function *f)
{
struct f_hidg *hidg = func_to_hidg(f);
struct f_hidg_req_list *list, *next;
+ int i;
usb_ep_disable(hidg->in_ep);
usb_ep_disable(hidg->out_ep);
@@ -498,6 +500,12 @@ static void hidg_disable(struct usb_function *f)
list_del(&list->list);
kfree(list);
}
+
+ for (i = 0; i < hidg->qlen; ++i) {
+ kfree(hidg->out_reqs[i]->buf);
+ kfree(hidg->out_reqs[i]);
+ }
+ kfree(hidg->out_reqs);
}
static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
@@ -547,11 +555,14 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
/*
* allocate a bunch of read buffers and queue them all at once.
*/
+ hidg->out_reqs = kzalloc(hidg->qlen *
+ sizeof(*hidg->out_reqs), GFP_KERNEL);
for (i = 0; i < hidg->qlen && status == 0; i++) {
struct usb_request *req =
hidg_alloc_ep_req(hidg->out_ep,
hidg->report_length);
if (req) {
+ hidg->out_reqs[i] = req;
req->complete = hidg_set_report_complete;
req->context = hidg;
status = usb_ep_queue(hidg->out_ep, req,
@@ -562,11 +573,20 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
} else {
usb_ep_disable(hidg->out_ep);
status = -ENOMEM;
- goto fail;
+ goto free_req;
}
}
}
+free_req:
+ if (status < 0) {
+ while (i--) {
+ kfree(hidg->out_reqs[i]->buf);
+ kfree(hidg->out_reqs[i]);
+ }
+ kfree(hidg->out_reqs);
+ }
+
fail:
return status;
}
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3 00/36] usb: gadget: composite: introduce new function API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 06/36] usb: gadget: composite: introduce new descriptors format Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 23/36] usb: gadget: f_rndis: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 26/36] usb: gadget: f_acm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 34/36] usb: gadget: f_uac1: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 18/36] usb: gadget: composite: enable adding USB functions using new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 04/36] usb: gadget: f_loopback: free requests in loopback_disable() Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 25/36] usb: gadget: f_hid: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 07/36] usb: gadget: composite: add functions for descriptors handling Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 35/36] usb: gadget: f_uac2: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 01/36] Documentation: usb: update usb-tools repository address Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
Re: [PATCH v3 01/36] Documentation: usb: update usb-tools repository address Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2015-12-11 13:40 +0100
[PATCH v3 33/36] usb: gadget: f_subset: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 21/36] usb: gadget: f_sourcesink: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 19/36] usb: gadget: configfs: add new composite API support Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 10/36] usb: gadget: composite: handle vendor descs Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 14/36] usb: gadget: composite: introduce clear_alt() operation Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 32/36] usb: gadget: f_phonet: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 28/36] usb: gadget: f_ncm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 36/36] usb: gadget: f_mass_storage: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:30 +0100
[PATCH v3 20/36] usb: gadget: f_loopback: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 09/36] usb: gadget: composite: handle function bind Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 22/36] usb: gadget: f_ecm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 24/36] usb: gadget: f_hid: handle requests lifetime properly Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 30/36] usb: gadget: f_serial: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 15/36] usb: gadget: composite: handle get_alt() automatically Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 17/36] usb: gadget: composite: add usb_get_interface_id() function Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 13/36] usb: gadget: composite: enable eps before calling set_alt() callback Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 27/36] usb: gadget: f_eem: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 11/36] usb: gadget: composite: generate old descs for compatibility Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 12/36] usb: gadget: composite: disable eps before calling disable() callback Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 31/36] usb: gadget: f_obex: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 29/36] usb: gadget: f_printer: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 05/36] usb: gadget: configfs: fix error path Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 08/36] usb: gadget: composite: introduce new USB function ops Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:40 +0100
[PATCH v3 03/36] usb: gadget: f_sourcesink: free requests in sourcesink_disable() Robert Baldyga <r.baldyga@samsung.com> - 2015-12-11 12:50 +0100
csiph-web