mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-12 00:38:55 +00:00
usb: gadget: f_mass_storage: create fsg_common_setup for use in fsg_common_init
fsg_common_init is a lengthy function. Factor a portion of it out. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
This commit is contained in:
parent
bd528d4e69
commit
b24650df95
@ -2643,6 +2643,27 @@ static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct fsg_common *fsg_common_setup(struct fsg_common *common)
|
||||||
|
{
|
||||||
|
if (!common) {
|
||||||
|
common = kzalloc(sizeof(*common), GFP_KERNEL);
|
||||||
|
if (!common)
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
common->free_storage_on_release = 1;
|
||||||
|
} else {
|
||||||
|
memset(common, 0, sizeof(*common));
|
||||||
|
common->free_storage_on_release = 0;
|
||||||
|
}
|
||||||
|
init_rwsem(&common->filesem);
|
||||||
|
spin_lock_init(&common->lock);
|
||||||
|
kref_init(&common->ref);
|
||||||
|
init_completion(&common->thread_notifier);
|
||||||
|
init_waitqueue_head(&common->fsg_wait);
|
||||||
|
common->state = FSG_STATE_TERMINATED;
|
||||||
|
|
||||||
|
return common;
|
||||||
|
}
|
||||||
|
|
||||||
void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs)
|
void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs)
|
||||||
{
|
{
|
||||||
common->sysfs = sysfs;
|
common->sysfs = sysfs;
|
||||||
@ -2711,16 +2732,9 @@ struct fsg_common *fsg_common_init(struct fsg_common *common,
|
|||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate? */
|
common = fsg_common_setup(common);
|
||||||
if (!common) {
|
if (IS_ERR(common))
|
||||||
common = kzalloc(sizeof *common, GFP_KERNEL);
|
return common;
|
||||||
if (!common)
|
|
||||||
return ERR_PTR(-ENOMEM);
|
|
||||||
common->free_storage_on_release = 1;
|
|
||||||
} else {
|
|
||||||
memset(common, 0, sizeof *common);
|
|
||||||
common->free_storage_on_release = 0;
|
|
||||||
}
|
|
||||||
fsg_common_set_sysfs(common, true);
|
fsg_common_set_sysfs(common, true);
|
||||||
common->state = FSG_STATE_IDLE;
|
common->state = FSG_STATE_IDLE;
|
||||||
|
|
||||||
@ -2760,8 +2774,6 @@ struct fsg_common *fsg_common_init(struct fsg_common *common,
|
|||||||
}
|
}
|
||||||
common->luns = curlun_it;
|
common->luns = curlun_it;
|
||||||
|
|
||||||
init_rwsem(&common->filesem);
|
|
||||||
|
|
||||||
for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun_it, ++lcfg) {
|
for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun_it, ++lcfg) {
|
||||||
struct fsg_lun *curlun;
|
struct fsg_lun *curlun;
|
||||||
|
|
||||||
@ -2855,8 +2867,6 @@ buffhds_first_it:
|
|||||||
common->can_stall = cfg->can_stall &&
|
common->can_stall = cfg->can_stall &&
|
||||||
!(gadget_is_at91(common->gadget));
|
!(gadget_is_at91(common->gadget));
|
||||||
|
|
||||||
spin_lock_init(&common->lock);
|
|
||||||
kref_init(&common->ref);
|
|
||||||
|
|
||||||
/* Tell the thread to start working */
|
/* Tell the thread to start working */
|
||||||
common->thread_task =
|
common->thread_task =
|
||||||
@ -2865,8 +2875,6 @@ buffhds_first_it:
|
|||||||
rc = PTR_ERR(common->thread_task);
|
rc = PTR_ERR(common->thread_task);
|
||||||
goto error_release;
|
goto error_release;
|
||||||
}
|
}
|
||||||
init_completion(&common->thread_notifier);
|
|
||||||
init_waitqueue_head(&common->fsg_wait);
|
|
||||||
|
|
||||||
/* Information */
|
/* Information */
|
||||||
INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
|
INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user