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

USB: g_mass_storage: thread_exits callback added

thread_exits callback has been added to fsg_common structure.
This callback is called when MSF's thread exits (is terminated
by a signal or function is unregistered).  It's then gadget's
responsibility to unregister the gadget.
Signed-off-by: default avatarMichal Nazarewicz <m.nazarewicz@samsung.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 915c8bef
...@@ -367,6 +367,11 @@ struct fsg_common { ...@@ -367,6 +367,11 @@ struct fsg_common {
struct completion thread_notifier; struct completion thread_notifier;
struct task_struct *thread_task; struct task_struct *thread_task;
/* Callback function to call when thread exits. */
void (*thread_exits)(struct fsg_common *common);
/* Gadget's private data. */
void *private_data;
/* Vendor (8 chars), product (16 chars), release (4 /* Vendor (8 chars), product (16 chars), release (4
* hexadecimal digits) and NUL byte */ * hexadecimal digits) and NUL byte */
char inquiry_string[8 + 16 + 4 + 1]; char inquiry_string[8 + 16 + 4 + 1];
...@@ -387,6 +392,11 @@ struct fsg_config { ...@@ -387,6 +392,11 @@ struct fsg_config {
const char *lun_name_format; const char *lun_name_format;
const char *thread_name; const char *thread_name;
/* Callback function to call when thread exits. */
void (*thread_exits)(struct fsg_common *common);
/* Gadget's private data. */
void *private_data;
const char *vendor_name; /* 8 characters or less */ const char *vendor_name; /* 8 characters or less */
const char *product_name; /* 16 characters or less */ const char *product_name; /* 16 characters or less */
u16 release; u16 release;
...@@ -2605,11 +2615,8 @@ static int fsg_main_thread(void *common_) ...@@ -2605,11 +2615,8 @@ static int fsg_main_thread(void *common_)
common->thread_task = NULL; common->thread_task = NULL;
spin_unlock_irq(&common->lock); spin_unlock_irq(&common->lock);
/* XXX */ if (common->thread_exits)
/* If we are exiting because of a signal, unregister the common->thread_exits(common);
* gadget driver. */
/* if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags)) */
/* usb_gadget_unregister_driver(&fsg_driver); */
/* Let the unbind and cleanup routines know the thread has exited */ /* Let the unbind and cleanup routines know the thread has exited */
complete_and_exit(&common->thread_notifier, 0); complete_and_exit(&common->thread_notifier, 0);
...@@ -2672,6 +2679,8 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, ...@@ -2672,6 +2679,8 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
common->free_storage_on_release = 0; common->free_storage_on_release = 0;
} }
common->private_data = cfg->private_data;
common->gadget = gadget; common->gadget = gadget;
common->ep0 = gadget->ep0; common->ep0 = gadget->ep0;
common->ep0req = cdev->req; common->ep0req = cdev->req;
...@@ -2791,6 +2800,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, ...@@ -2791,6 +2800,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
/* Tell the thread to start working */ /* Tell the thread to start working */
common->thread_exits = cfg->thread_exits;
common->thread_task = common->thread_task =
kthread_create(fsg_main_thread, common, kthread_create(fsg_main_thread, common,
OR(cfg->thread_name, "file-storage")); OR(cfg->thread_name, "file-storage"));
...@@ -3057,6 +3067,9 @@ fsg_config_from_params(struct fsg_config *cfg, ...@@ -3057,6 +3067,9 @@ fsg_config_from_params(struct fsg_config *cfg,
cfg->product_name = 0; cfg->product_name = 0;
cfg->release = 0xffff; cfg->release = 0xffff;
cfg->thread_exits = 0;
cfg->private_data = 0;
/* Finalise */ /* Finalise */
cfg->can_stall = params->stall; cfg->can_stall = params->stall;
} }
......
...@@ -132,9 +132,13 @@ static struct fsg_module_parameters mod_data = { ...@@ -132,9 +132,13 @@ static struct fsg_module_parameters mod_data = {
}; };
FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); FSG_MODULE_PARAMETERS(/* no prefix */, mod_data);
static unsigned long msg_registered = 0;
static void msg_cleanup(void);
static int __init msg_do_config(struct usb_configuration *c) static int __init msg_do_config(struct usb_configuration *c)
{ {
struct fsg_common *common; struct fsg_common *common;
struct fsg_config config;
int ret; int ret;
if (gadget_is_otg(c->cdev->gadget)) { if (gadget_is_otg(c->cdev->gadget)) {
...@@ -142,7 +146,9 @@ static int __init msg_do_config(struct usb_configuration *c) ...@@ -142,7 +146,9 @@ static int __init msg_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
} }
common = fsg_common_from_params(0, c->cdev, &mod_data); fsg_config_from_params(&config, &mod_data);
config.thread_exits = (void(*)(struct fsg_common*))&msg_cleanup;
common = fsg_common_init(0, c->cdev, &config);
if (IS_ERR(common)) if (IS_ERR(common))
return PTR_ERR(common); return PTR_ERR(common);
...@@ -201,11 +207,7 @@ static int __init msg_bind(struct usb_composite_dev *cdev) ...@@ -201,11 +207,7 @@ static int __init msg_bind(struct usb_composite_dev *cdev)
return status; return status;
dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
return 0; set_bit(0, &msg_registered);
}
static int __exit msg_unbind(struct usb_composite_dev *cdev)
{
return 0; return 0;
} }
...@@ -218,7 +220,6 @@ static struct usb_composite_driver msg_driver = { ...@@ -218,7 +220,6 @@ static struct usb_composite_driver msg_driver = {
.dev = &msg_device_desc, .dev = &msg_device_desc,
.strings = dev_strings, .strings = dev_strings,
.bind = msg_bind, .bind = msg_bind,
.unbind = __exit_p(msg_unbind),
}; };
MODULE_DESCRIPTION(DRIVER_DESC); MODULE_DESCRIPTION(DRIVER_DESC);
...@@ -231,8 +232,9 @@ static int __init msg_init(void) ...@@ -231,8 +232,9 @@ static int __init msg_init(void)
} }
module_init(msg_init); module_init(msg_init);
static void __exit msg_cleanup(void) static void msg_cleanup(void)
{ {
if (test_and_clear_bit(0, &msg_registered))
usb_composite_unregister(&msg_driver); usb_composite_unregister(&msg_driver);
} }
module_exit(msg_cleanup); module_exit(msg_cleanup);
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