Commit 0fb2c2a1 authored by Michal Nazarewicz's avatar Michal Nazarewicz Committed by Greg Kroah-Hartman

USB: gadget: f_mass_storage: per function

Mass Storage Function (MSF) used the same descriptors for each
usb_function instance (meaning usb_function::descriptors of different
functions pointed to the same static area (the same was true for
usb_function::hs_descriptors)).

This would leads to problems if MSF were used in several USB
configurations with different interface and/or endpoint numbers.
Descriptors for all configurations would have interface/endpoint
numbers overwritten by the values valid for the last configuration.

This patch adds code that copies the descriptors each time MSF is
added to USB configuration (that is for each usb_function).
Signed-off-by: default avatarMichal Nazarewicz <m.nazarewicz@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
parent dd0543ec
...@@ -2919,6 +2919,8 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f) ...@@ -2919,6 +2919,8 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
DBG(fsg, "unbind\n"); DBG(fsg, "unbind\n");
fsg_common_put(fsg->common); fsg_common_put(fsg->common);
usb_free_descriptors(fsg->function.descriptors);
usb_free_descriptors(fsg->function.hs_descriptors);
kfree(fsg); kfree(fsg);
} }
...@@ -2959,7 +2961,9 @@ static int __init fsg_bind(struct usb_configuration *c, struct usb_function *f) ...@@ -2959,7 +2961,9 @@ static int __init fsg_bind(struct usb_configuration *c, struct usb_function *f)
fsg_fs_bulk_in_desc.bEndpointAddress; fsg_fs_bulk_in_desc.bEndpointAddress;
fsg_hs_bulk_out_desc.bEndpointAddress = fsg_hs_bulk_out_desc.bEndpointAddress =
fsg_fs_bulk_out_desc.bEndpointAddress; fsg_fs_bulk_out_desc.bEndpointAddress;
f->hs_descriptors = fsg_hs_function; f->hs_descriptors = usb_copy_descriptors(fsg_hs_function);
if (unlikely(!f->hs_descriptors))
return -ENOMEM;
} }
return 0; return 0;
...@@ -2991,7 +2995,11 @@ static int fsg_add(struct usb_composite_dev *cdev, ...@@ -2991,7 +2995,11 @@ static int fsg_add(struct usb_composite_dev *cdev,
fsg->function.name = FSG_DRIVER_DESC; fsg->function.name = FSG_DRIVER_DESC;
fsg->function.strings = fsg_strings_array; fsg->function.strings = fsg_strings_array;
fsg->function.descriptors = fsg_fs_function; fsg->function.descriptors = usb_copy_descriptors(fsg_fs_function);
if (unlikely(!fsg->function.descriptors)) {
rc = -ENOMEM;
goto error_free_fsg;
}
fsg->function.bind = fsg_bind; fsg->function.bind = fsg_bind;
fsg->function.unbind = fsg_unbind; fsg->function.unbind = fsg_unbind;
fsg->function.setup = fsg_setup; fsg->function.setup = fsg_setup;
...@@ -3006,10 +3014,18 @@ static int fsg_add(struct usb_composite_dev *cdev, ...@@ -3006,10 +3014,18 @@ static int fsg_add(struct usb_composite_dev *cdev,
* call to usb_add_function() was successful. */ * call to usb_add_function() was successful. */
rc = usb_add_function(c, &fsg->function); rc = usb_add_function(c, &fsg->function);
if (unlikely(rc))
goto error_free_all;
if (likely(rc == 0))
fsg_common_get(fsg->common); fsg_common_get(fsg->common);
else return 0;
error_free_all:
usb_free_descriptors(fsg->function.descriptors);
/* fsg_bind() might have copied those; or maybe not? who cares
* -- free it just in case. */
usb_free_descriptors(fsg->function.hs_descriptors);
error_free_fsg:
kfree(fsg); kfree(fsg);
return rc; return rc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment