Skip to content

Commit 0400004

Browse files
maade93791thestinger
authored andcommitted
usb: gadget: f_ncm: fix double-free in ncm_unbind()
1 parent 2269b30 commit 0400004

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

drivers/usb/gadget/function/f_ncm.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,18 +1670,24 @@ static void ncm_unbind(struct usb_configuration *c, struct usb_function *f)
16701670
hrtimer_cancel(&ncm->task_timer);
16711671

16721672
kfree(f->os_desc_table);
1673+
f->os_desc_table = NULL;
16731674
f->os_desc_n = 0;
16741675

16751676
ncm_string_defs[0].id = 0;
16761677
usb_free_all_descriptors(f);
16771678

16781679
if (atomic_read(&ncm->notify_count)) {
1679-
usb_ep_dequeue(ncm->notify, ncm->notify_req);
1680+
if (ncm->notify_req)
1681+
usb_ep_dequeue(ncm->notify, ncm->notify_req);
16801682
atomic_set(&ncm->notify_count, 0);
16811683
}
16821684

1683-
kfree(ncm->notify_req->buf);
1684-
usb_ep_free_request(ncm->notify, ncm->notify_req);
1685+
if (ncm->notify_req) {
1686+
kfree(ncm->notify_req->buf);
1687+
ncm->notify_req->buf = NULL;
1688+
usb_ep_free_request(ncm->notify, ncm->notify_req);
1689+
ncm->notify_req = NULL;
1690+
}
16851691

16861692
ncm_opts->bind_count--;
16871693
if (ncm_opts->bind_count == 0)

0 commit comments

Comments
 (0)