summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-03-19 12:02:44 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2022-03-28 10:52:55 +0200
commitc3dca9f42aba61f0393dda0ba24ef96e792dcd18 (patch)
tree01a182eab1826eb124fabc8c079f9d05ebff914f /include
parent20ac8bbc2c6d521bbfd78ae9f91b9f9e76b432b3 (diff)
downloadbarebox-c3dca9f42aba61f0393dda0ba24ef96e792dcd18.tar.gz
barebox-c3dca9f42aba61f0393dda0ba24ef96e792dcd18.tar.xz
usb: gadget: mass-storage: reference count allocations used in bthread
Since 997cca0f15dc ("bthread: replace blocking bthread_stop with nonblocking bthread_cancel"), the bthread may survive longer than the multigadget unbind. This didn't cause issues so far, because the multi gadget unbind didn't call usb_put_function[_instance] for mass-storage (but did so for other functions), so we just leaked the memory. In preparation for fixing the memory leak, we will need to straighten out the mass storage cleanup. We do so by reference counting the two shared structures: If bthread runs before usb_put_function[_instance], it will not free them yet (avoiding a double free) and if bthread runs after usb_put_function[_instance], it will still be able to access them (avoiding a use-after-free). A cleaner way would've been to wait for bthread completion, but we can't do that here, because gadget could be unbound in a poller and bthreads are only scheduled in command context. Fixes: 997cca0f15dc ("bthread: replace blocking bthread_stop with nonblocking bthread_cancel") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220319110246.2850396-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/usb/mass_storage.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/usb/mass_storage.h b/include/usb/mass_storage.h
index 084b3c8e8f..7be665ee47 100644
--- a/include/usb/mass_storage.h
+++ b/include/usb/mass_storage.h
@@ -20,6 +20,7 @@ struct f_ums_opts {
struct file_list *files;
unsigned int num_sectors;
int fd;
+ int refcnt;
char name[16];
};