[PATCH v4] usb: gadget: f_mass_storage: stop thread in bind failure case
After the worker thread is launched, bind function is doing further configuration. In case of failure stop the thread. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- history: v3: - handled Michal's comment; used existing function to change state and exit thread. - tested for f_mass_storage.c only; dropped patches for legacy. v2: - Handled review comment from Michal. - Merged v2 patch-2/3/4 to make patch-2. - Added acked-by from Michal to patch-1. v1: - Handled review comments from Michal. - updated patch-2 : added thread wake in legacy client of function (patch-2). - added patch-4 : freeing file-storage thread in configuration error case. - added patch-3 (needed by patch-4) : moved fsg_common structure to header file, as code is dereferencing common-thread_task. --- drivers/usb/gadget/function/f_mass_storage.c | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index f936268..c5b3db5 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3080,7 +3080,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) /* New interface */ i = usb_interface_id(c, f); if (i 0) - return i; + goto fail; fsg_intf_desc.bInterfaceNumber = i; fsg-interface_number = i; @@ -3123,7 +3123,14 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) autoconf_fail: ERROR(fsg, unable to autoconfigure all endpoints\n); - return -ENOTSUPP; + i = -ENOTSUPP; +fail: + /* terminate the thread */ + if (fsg-common-state != FSG_STATE_TERMINATED) { + raise_exception(fsg-common, FSG_STATE_EXIT); + wait_for_completion(fsg-common-thread_notifier); + } + return i; } /** ALLOCATE FUNCTION */ -- 1.9.1 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 3/4] usb: gadget: move common storage gadget structure to header file
struct fsg_common is used in multiple files, moving it to header file from the source file. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 70 drivers/usb/gadget/function/f_mass_storage.h | 68 ++- 2 files changed, 67 insertions(+), 71 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index a996f3f..560e73d 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -251,76 +251,6 @@ static struct usb_gadget_strings *fsg_strings_array[] = { /*-*/ -struct fsg_dev; -struct fsg_common; - -/* Data shared by all the FSG instances. */ -struct fsg_common { - struct usb_gadget *gadget; - struct usb_composite_dev *cdev; - struct fsg_dev *fsg, *new_fsg; - wait_queue_head_t fsg_wait; - - /* filesem protects: backing files in use */ - struct rw_semaphore filesem; - - /* lock protects: state, all the req_busy's */ - spinlock_t lock; - - struct usb_ep *ep0; /* Copy of gadget-ep0 */ - struct usb_request *ep0req;/* Copy of cdev-req */ - unsigned intep0_req_tag; - - struct fsg_buffhd *next_buffhd_to_fill; - struct fsg_buffhd *next_buffhd_to_drain; - struct fsg_buffhd *buffhds; - unsigned intfsg_num_buffers; - - int cmnd_size; - u8 cmnd[MAX_COMMAND_SIZE]; - - unsigned intnluns; - unsigned intlun; - struct fsg_lun **luns; - struct fsg_lun *curlun; - - unsigned intbulk_out_maxpacket; - enum fsg_state state; /* For exception handling */ - unsigned intexception_req_tag; - - enum data_direction data_dir; - u32 data_size; - u32 data_size_from_cmnd; - u32 tag; - u32 residue; - u32 usb_amount_left; - - unsigned intcan_stall:1; - unsigned intfree_storage_on_release:1; - unsigned intphase_error:1; - unsigned intshort_packet_received:1; - unsigned intbad_lun_okay:1; - unsigned intrunning:1; - unsigned intsysfs:1; - - int thread_wakeup_needed; - struct completion thread_notifier; - struct task_struct *thread_task; - - /* Callback functions. */ - const struct fsg_operations *ops; - /* Gadget's private data. */ - void*private_data; - - /* -* Vendor (8 chars), product (16 chars), release (4 -* hexadecimal digits) and NUL byte -*/ - char inquiry_string[8 + 16 + 4 + 1]; - - struct kref ref; -}; - struct fsg_dev { struct usb_function function; struct usb_gadget *gadget;/* Copy of cdev-gadget */ diff --git a/drivers/usb/gadget/function/f_mass_storage.h b/drivers/usb/gadget/function/f_mass_storage.h index b4866fc..c05fe16 100644 --- a/drivers/usb/gadget/function/f_mass_storage.h +++ b/drivers/usb/gadget/function/f_mass_storage.h @@ -57,7 +57,73 @@ struct fsg_module_parameters { #endif -struct fsg_common; +/* Data shared by all the FSG instances. */ +struct fsg_common { + struct usb_gadget *gadget; + struct usb_composite_dev *cdev; + struct fsg_dev *fsg, *new_fsg; + wait_queue_head_t fsg_wait; + + /* filesem protects: backing files in use */ + struct rw_semaphore filesem; + + /* lock protects: state, all the req_busy's */ + spinlock_t lock; + + struct usb_ep *ep0; /* Copy of gadget-ep0 */ + struct usb_request *ep0req;/* Copy of cdev-req */ + unsigned intep0_req_tag; + + struct fsg_buffhd *next_buffhd_to_fill; + struct fsg_buffhd *next_buffhd_to_drain; + struct fsg_buffhd *buffhds; + unsigned intfsg_num_buffers; + + int cmnd_size; + u8 cmnd[MAX_COMMAND_SIZE]; + + unsigned intnluns; + unsigned intlun; + struct fsg_lun **luns; + struct fsg_lun *curlun; + + unsigned intbulk_out_maxpacket; + enum fsg_state state; /* For exception handling */ + unsigned intexception_req_tag; + + enum data_direction data_dir; + + u32
[PATCH v2 2/4] usb: gadget: mass-storage: defer storage thread wakeup
As the configuration is not complete at the time of thread creation, defering the thread wakeup till the end. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 5 +++-- drivers/usb/gadget/legacy/acm_ms.c | 3 +++ drivers/usb/gadget/legacy/mass_storage.c | 3 +++ drivers/usb/gadget/legacy/multi.c| 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 0e90e38..a996f3f 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3013,8 +3013,6 @@ int fsg_common_run_thread(struct fsg_common *common) DBG(common, I/O thread pid: %d\n, task_pid_nr(common-thread_task)); - wake_up_process(common-thread_task); - return 0; } EXPORT_SYMBOL_GPL(fsg_common_run_thread); @@ -3121,6 +3119,9 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) if (ret) goto autoconf_fail; + /* wakeup the thread */ + wake_up_process(fsg-common-thread_task); + return 0; autoconf_fail: diff --git a/drivers/usb/gadget/legacy/acm_ms.c b/drivers/usb/gadget/legacy/acm_ms.c index 1194b09..ec79c74 100644 --- a/drivers/usb/gadget/legacy/acm_ms.c +++ b/drivers/usb/gadget/legacy/acm_ms.c @@ -155,6 +155,9 @@ static int acm_ms_do_config(struct usb_configuration *c) if (status) goto remove_acm; + /* wakeup the thread */ + wake_up_process(opts-common-thread_task); + return 0; remove_acm: usb_remove_function(c, f_acm); diff --git a/drivers/usb/gadget/legacy/mass_storage.c b/drivers/usb/gadget/legacy/mass_storage.c index e7bfb08..a8746b9 100644 --- a/drivers/usb/gadget/legacy/mass_storage.c +++ b/drivers/usb/gadget/legacy/mass_storage.c @@ -154,6 +154,9 @@ static int msg_do_config(struct usb_configuration *c) if (ret) goto put_func; + /* wakeup the thread */ + wake_up_process(opts-common-thread_task); + return 0; put_func: diff --git a/drivers/usb/gadget/legacy/multi.c b/drivers/usb/gadget/legacy/multi.c index b21b51f..00af0da 100644 --- a/drivers/usb/gadget/legacy/multi.c +++ b/drivers/usb/gadget/legacy/multi.c @@ -192,6 +192,8 @@ static int rndis_do_config(struct usb_configuration *c) if (ret) goto err_run; + /* wakeup the thread */ + wake_up_process(fsg_opts-common-thread_task); return 0; err_run: usb_put_function(f_msg_rndis); -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 0/4] usb: gadget: mass-storage: handle thread in error case
This patch set releases storage thread in error case. Changes since v1: - Handled review comments from Michal. - updated patch-2 : added thread wake in legacy client of function (patch-2). - added patch-4 : freeing file-storage thread in configuration error case. - added patch-3 (needed by patch-4) : moved fsg_common structure to header file, as code is dereferencing common-thread_task. Sanjay Singh Rawat (4): usb: gadget: f_mass_storage: stop thread in bind failure case usb: gadget: mass-storage: defer storage thread wakeup usb: gadget: move common storage gadget structure to header file usb: gadget: stop mass storage thread in failure case drivers/usb/gadget/function/f_mass_storage.c | 82 +++- drivers/usb/gadget/function/f_mass_storage.h | 68 ++- drivers/usb/gadget/legacy/acm_ms.c | 5 ++ drivers/usb/gadget/legacy/mass_storage.c | 4 ++ drivers/usb/gadget/legacy/multi.c| 4 ++ 5 files changed, 88 insertions(+), 75 deletions(-) -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 1/4] usb: gadget: f_mass_storage: stop thread in bind failure case
After the worker thread is launched, bind function is doing further configuration. In case of failure stop the thread. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 3cc109f..0e90e38 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3082,7 +3082,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) /* New interface */ i = usb_interface_id(c, f); if (i 0) - return i; + goto fail; fsg_intf_desc.bInterfaceNumber = i; fsg-interface_number = i; @@ -3125,7 +3125,10 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) autoconf_fail: ERROR(fsg, unable to autoconfigure all endpoints\n); - return -ENOTSUPP; + i = -ENOTSUPP; +fail: + kthread_stop(fsg-common-thread_task); + return i; } /** ALLOCATE FUNCTION */ -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 4/4] usb: gadget: stop mass storage thread in failure case
We are launching the mass-storage thread during the function configuration phase, in case of failure adding function to stop the thread. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/legacy/acm_ms.c | 2 ++ drivers/usb/gadget/legacy/mass_storage.c | 1 + drivers/usb/gadget/legacy/multi.c| 2 ++ 3 files changed, 5 insertions(+) diff --git a/drivers/usb/gadget/legacy/acm_ms.c b/drivers/usb/gadget/legacy/acm_ms.c index ec79c74..bbdb867 100644 --- a/drivers/usb/gadget/legacy/acm_ms.c +++ b/drivers/usb/gadget/legacy/acm_ms.c @@ -15,6 +15,7 @@ */ #include linux/kernel.h +#include linux/kthread.h #include linux/module.h #include u_serial.h @@ -160,6 +161,7 @@ static int acm_ms_do_config(struct usb_configuration *c) return 0; remove_acm: + kthread_stop(opts-common-thread_task); usb_remove_function(c, f_acm); put_msg: usb_put_function(f_msg); diff --git a/drivers/usb/gadget/legacy/mass_storage.c b/drivers/usb/gadget/legacy/mass_storage.c index a8746b9..ee1f61f 100644 --- a/drivers/usb/gadget/legacy/mass_storage.c +++ b/drivers/usb/gadget/legacy/mass_storage.c @@ -160,6 +160,7 @@ static int msg_do_config(struct usb_configuration *c) return 0; put_func: + kthread_stop(opts-common-thread_task); usb_put_function(f_msg); return ret; } diff --git a/drivers/usb/gadget/legacy/multi.c b/drivers/usb/gadget/legacy/multi.c index 00af0da..f9d8d13 100644 --- a/drivers/usb/gadget/legacy/multi.c +++ b/drivers/usb/gadget/legacy/multi.c @@ -14,6 +14,7 @@ #include linux/kernel.h +#include linux/kthread.h #include linux/module.h #include linux/netdevice.h @@ -196,6 +197,7 @@ static int rndis_do_config(struct usb_configuration *c) wake_up_process(fsg_opts-common-thread_task); return 0; err_run: + kthread_stop(fsg_opts-common-thread_task); usb_put_function(f_msg_rndis); err_fsg: usb_remove_function(c, f_acm_rndis); -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH V3 0/2] usb: gadget: mass-storage: handle thread in error case
History: v2: - Handled review comment from Michal. - Merged v2 patch-2/3/4 to make patch-2. - Added acked-by from Michal to patch-1. v1: - Handled review comments from Michal. - updated patch-2 : added thread wake in legacy client of function (patch-2). - added patch-4 : freeing file-storage thread in configuration error case. - added patch-3 (needed by patch-4) : moved fsg_common structure to header file, as code is dereferencing common-thread_task. Sanjay Singh Rawat (2): usb: gadget: f_mass_storage: stop thread in bind failure case usb: gadget: mass-storage: defer storage thread wakeup drivers/usb/gadget/function/f_mass_storage.c | 82 +++- drivers/usb/gadget/function/f_mass_storage.h | 68 ++- drivers/usb/gadget/legacy/acm_ms.c | 5 ++ drivers/usb/gadget/legacy/mass_storage.c | 4 ++ drivers/usb/gadget/legacy/multi.c| 4 ++ 5 files changed, 88 insertions(+), 75 deletions(-) -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH V3 1/2] usb: gadget: f_mass_storage: stop thread in bind failure case
After the worker thread is launched, bind function is doing further configuration. In case of failure stop the thread. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com Acked-by: Michal Nazarewicz min...@mina86.com --- drivers/usb/gadget/function/f_mass_storage.c | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 3cc109f..0e90e38 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3082,7 +3082,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) /* New interface */ i = usb_interface_id(c, f); if (i 0) - return i; + goto fail; fsg_intf_desc.bInterfaceNumber = i; fsg-interface_number = i; @@ -3125,7 +3125,10 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) autoconf_fail: ERROR(fsg, unable to autoconfigure all endpoints\n); - return -ENOTSUPP; + i = -ENOTSUPP; +fail: + kthread_stop(fsg-common-thread_task); + return i; } /** ALLOCATE FUNCTION */ -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH V3 2/2] usb: gadget: mass-storage: defer storage thread wakeup
As the configuration is not complete at the time of thread creation, defering the file-storage thread wakeup till the end. Also stop the thread in case of failure during configuration. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 75 ++-- drivers/usb/gadget/function/f_mass_storage.h | 68 - drivers/usb/gadget/legacy/acm_ms.c | 5 ++ drivers/usb/gadget/legacy/mass_storage.c | 4 ++ drivers/usb/gadget/legacy/multi.c| 4 ++ 5 files changed, 83 insertions(+), 73 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 0e90e38..560e73d 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -251,76 +251,6 @@ static struct usb_gadget_strings *fsg_strings_array[] = { /*-*/ -struct fsg_dev; -struct fsg_common; - -/* Data shared by all the FSG instances. */ -struct fsg_common { - struct usb_gadget *gadget; - struct usb_composite_dev *cdev; - struct fsg_dev *fsg, *new_fsg; - wait_queue_head_t fsg_wait; - - /* filesem protects: backing files in use */ - struct rw_semaphore filesem; - - /* lock protects: state, all the req_busy's */ - spinlock_t lock; - - struct usb_ep *ep0; /* Copy of gadget-ep0 */ - struct usb_request *ep0req;/* Copy of cdev-req */ - unsigned intep0_req_tag; - - struct fsg_buffhd *next_buffhd_to_fill; - struct fsg_buffhd *next_buffhd_to_drain; - struct fsg_buffhd *buffhds; - unsigned intfsg_num_buffers; - - int cmnd_size; - u8 cmnd[MAX_COMMAND_SIZE]; - - unsigned intnluns; - unsigned intlun; - struct fsg_lun **luns; - struct fsg_lun *curlun; - - unsigned intbulk_out_maxpacket; - enum fsg_state state; /* For exception handling */ - unsigned intexception_req_tag; - - enum data_direction data_dir; - u32 data_size; - u32 data_size_from_cmnd; - u32 tag; - u32 residue; - u32 usb_amount_left; - - unsigned intcan_stall:1; - unsigned intfree_storage_on_release:1; - unsigned intphase_error:1; - unsigned intshort_packet_received:1; - unsigned intbad_lun_okay:1; - unsigned intrunning:1; - unsigned intsysfs:1; - - int thread_wakeup_needed; - struct completion thread_notifier; - struct task_struct *thread_task; - - /* Callback functions. */ - const struct fsg_operations *ops; - /* Gadget's private data. */ - void*private_data; - - /* -* Vendor (8 chars), product (16 chars), release (4 -* hexadecimal digits) and NUL byte -*/ - char inquiry_string[8 + 16 + 4 + 1]; - - struct kref ref; -}; - struct fsg_dev { struct usb_function function; struct usb_gadget *gadget;/* Copy of cdev-gadget */ @@ -3013,8 +2943,6 @@ int fsg_common_run_thread(struct fsg_common *common) DBG(common, I/O thread pid: %d\n, task_pid_nr(common-thread_task)); - wake_up_process(common-thread_task); - return 0; } EXPORT_SYMBOL_GPL(fsg_common_run_thread); @@ -3121,6 +3049,9 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) if (ret) goto autoconf_fail; + /* wakeup the thread */ + wake_up_process(fsg-common-thread_task); + return 0; autoconf_fail: diff --git a/drivers/usb/gadget/function/f_mass_storage.h b/drivers/usb/gadget/function/f_mass_storage.h index b4866fc..c05fe16 100644 --- a/drivers/usb/gadget/function/f_mass_storage.h +++ b/drivers/usb/gadget/function/f_mass_storage.h @@ -57,7 +57,73 @@ struct fsg_module_parameters { #endif -struct fsg_common; +/* Data shared by all the FSG instances. */ +struct fsg_common { + struct usb_gadget *gadget; + struct usb_composite_dev *cdev; + struct fsg_dev *fsg, *new_fsg; + wait_queue_head_t fsg_wait; + + /* filesem protects: backing files in use */ + struct rw_semaphore filesem; + + /* lock protects: state, all the req_busy's */ + spinlock_t lock; + + struct usb_ep *ep0; /* Copy of gadget-ep0 */ + struct usb_request *ep0req
Re: [PATCH 2/2] usb: gadget: f_mass_storage: defer storage thread wakeup
On 6/6/2015 3:22 PM, Michal Nazarewicz wrote: On Fri, Jun 05 2015, Sanjay Singh Rawat wrote: As the bind configuration is not complete during thread creation, defering the thread wake to end of bind. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 0e90e38..a996f3f 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3013,8 +3013,6 @@ int fsg_common_run_thread(struct fsg_common *common) DBG(common, I/O thread pid: %d\n, task_pid_nr(common-thread_task)); - wake_up_process(common-thread_task); - return 0; } This will unfortunately break other users of the function, namely those in drivers/usb/gadget/legacy directory. They will need to be updated as well. ack, thanks for notifying Michal. I will update the patch. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/2] handle thread in error case
This patch set handles storage thread in error case. Sanjay Singh Rawat (2): usb: gadget: f_mass_storage: stop thread in bind failure case usb: gadget: f_mass_storage: defer storage thread wakeup drivers/usb/gadget/function/f_mass_storage.c | 12 1 file changed, 8 insertions(+), 4 deletions(-) -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/2] usb: gadget: f_mass_storage: defer storage thread wakeup
As the bind configuration is not complete during thread creation, defering the thread wake to end of bind. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 0e90e38..a996f3f 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3013,8 +3013,6 @@ int fsg_common_run_thread(struct fsg_common *common) DBG(common, I/O thread pid: %d\n, task_pid_nr(common-thread_task)); - wake_up_process(common-thread_task); - return 0; } EXPORT_SYMBOL_GPL(fsg_common_run_thread); @@ -3121,6 +3119,9 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) if (ret) goto autoconf_fail; + /* wakeup the thread */ + wake_up_process(fsg-common-thread_task); + return 0; autoconf_fail: -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] usb: gadget: f_mass_storage: stop thread in bind failure case
After the worker thread is launched, bind function is doing further configuration. In case of failure stop the thread. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 3cc109f..0e90e38 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3082,7 +3082,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) /* New interface */ i = usb_interface_id(c, f); if (i 0) - return i; + goto fail; fsg_intf_desc.bInterfaceNumber = i; fsg-interface_number = i; @@ -3125,7 +3125,10 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) autoconf_fail: ERROR(fsg, unable to autoconfigure all endpoints\n); - return -ENOTSUPP; + i = -ENOTSUPP; +fail: + kthread_stop(fsg-common-thread_task); + return i; } /** ALLOCATE FUNCTION */ -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] usb: gadget: f_mass_storage: stop thread in bind failure case
After the worker thread is launched, bind function is doing further configuration. Stop the thread in case of failure. Also use kthread_run to encapsulate thread creation and launch. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 3cc109f..835764a 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3005,7 +3005,7 @@ int fsg_common_run_thread(struct fsg_common *common) common-state = FSG_STATE_IDLE; /* Tell the thread to start working */ common-thread_task = - kthread_create(fsg_main_thread, common, file-storage); + kthread_run(fsg_main_thread, common, file-storage); if (IS_ERR(common-thread_task)) { common-state = FSG_STATE_TERMINATED; return PTR_ERR(common-thread_task); @@ -3013,8 +3013,6 @@ int fsg_common_run_thread(struct fsg_common *common) DBG(common, I/O thread pid: %d\n, task_pid_nr(common-thread_task)); - wake_up_process(common-thread_task); - return 0; } EXPORT_SYMBOL_GPL(fsg_common_run_thread); @@ -3082,7 +3080,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) /* New interface */ i = usb_interface_id(c, f); if (i 0) - return i; + goto fail; fsg_intf_desc.bInterfaceNumber = i; fsg-interface_number = i; @@ -3125,7 +3123,10 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f) autoconf_fail: ERROR(fsg, unable to autoconfigure all endpoints\n); - return -ENOTSUPP; + i = -ENOTSUPP; +fail: + kthread_stop(fsg-common-thread_task); + return i; } /** ALLOCATE FUNCTION */ -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] usb: gadget: f_mass_storage: restore address range on exit
At the start of the thread we are changing the address limit, restoring it to the default while exiting. Signed-off-by: Sanjay Singh Rawat snjs...@gmail.com --- drivers/usb/gadget/function/f_mass_storage.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 811929c..c4a2ded 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -2489,6 +2489,7 @@ static void handle_exception(struct fsg_common *common) static int fsg_main_thread(void *common_) { struct fsg_common *common = common_; + mm_segment_t fs = get_fs(); /* * Allow the thread to be killed by a signal, but set the signal mask @@ -2567,6 +2568,7 @@ static int fsg_main_thread(void *common_) up_write(common-filesem); } + set_fs(fs); /* Let fsg_unbind() know the thread has exited */ complete_and_exit(common-thread_notifier, 0); } -- 1.8.3.2 -- To unsubscribe from this list: send the line unsubscribe linux-usb in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html