fsg_common_init is a lengthy function. Now there are helper functions which cover all parts of it. Use them. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx> Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx> --- drivers/usb/gadget/f_mass_storage.c | 89 ++--------------------------------- 1 files changed, 4 insertions(+), 85 deletions(-) diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index fa27f21..6fe506b 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2983,12 +2983,7 @@ struct fsg_common *fsg_common_init(struct fsg_common *common, struct usb_composite_dev *cdev, struct fsg_config *cfg) { - struct usb_gadget *gadget = cdev->gadget; - struct fsg_lun **curlun; - struct fsg_lun_config *lcfg; - int nluns, i, rc; - char *pathbuf; - + int i, rc; common = fsg_common_setup(common, !!common); if (IS_ERR(common)) @@ -3013,61 +3008,10 @@ struct fsg_common *fsg_common_init(struct fsg_common *common, rc = fsg_common_set_nluns(common, cfg->nluns); if (rc) goto error_release; - curlun = common->luns; - nluns = cfg->nluns; - for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) { - *curlun = kzalloc(sizeof(**curlun), GFP_KERNEL); - if (!*curlun) { - rc = -ENOMEM; - common->nluns = i; - goto error_release; - } - (*curlun)->cdrom = !!lcfg->cdrom; - (*curlun)->ro = lcfg->cdrom || lcfg->ro; - (*curlun)->initially_ro = (*curlun)->ro; - (*curlun)->removable = lcfg->removable; - (*curlun)->dev.release = fsg_lun_release; - (*curlun)->dev.parent = &gadget->dev; - /* (curlun*)->dev.driver = &fsg_driver.driver; XXX */ - dev_set_drvdata(&(*curlun)->dev, &common->filesem); - dev_set_name(&(*curlun)->dev, "lun%d", i); - - rc = device_register(&(*curlun)->dev); - if (rc) { - INFO(common, "failed to register LUN%d: %d\n", i, rc); - common->nluns = i; - put_device(&(*curlun)->dev); - kfree(*curlun); - goto error_release; - } - - rc = device_create_file(&(*curlun)->dev, - (*curlun)->cdrom - ? &dev_attr_ro_cdrom - : &dev_attr_ro); - if (rc) - goto error_luns; - rc = device_create_file(&(*curlun)->dev, - (*curlun)->removable - ? &dev_attr_file - : &dev_attr_file_nonremovable); - if (rc) - goto error_luns; - rc = device_create_file(&(*curlun)->dev, &dev_attr_nofua); - if (rc) - goto error_luns; - - if (lcfg->filename) { - rc = fsg_lun_open(*curlun, lcfg->filename); - if (rc) - goto error_luns; - } else if (!(*curlun)->removable) { - ERROR(common, "no file given for LUN%d\n", i); - rc = -EINVAL; - goto error_luns; - } - } + rc = fsg_common_create_luns(common, cfg); + if (rc) + goto error_release; /* Prepare inquiryString */ i = get_default_bcdDevice(); @@ -3079,7 +3023,6 @@ struct fsg_common *fsg_common_init(struct fsg_common *common, : "File-Stor Gadget"), i); - /* Tell the thread to start working */ common->thread_task = kthread_create(fsg_main_thread, common, "file-storage"); @@ -3092,36 +3035,12 @@ struct fsg_common *fsg_common_init(struct fsg_common *common, INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); INFO(common, "Number of LUNs=%d\n", common->nluns); - pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); - for (i = 0, nluns = common->nluns, curlun = common->luns; - i < nluns; - ++curlun, ++i) { - char *p = "(no medium)"; - if (fsg_lun_is_open(*curlun)) { - p = "(error)"; - if (pathbuf) { - p = d_path(&(*curlun)->filp->f_path, - pathbuf, PATH_MAX); - if (IS_ERR(p)) - p = "(error)"; - } - } - LINFO(*curlun, "LUN: %s%s%sfile: %s\n", - (*curlun)->removable ? "removable " : "", - (*curlun)->ro ? "read only " : "", - (*curlun)->cdrom ? "CD-ROM " : "", - p); - } - kfree(pathbuf); - DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task)); wake_up_process(common->thread_task); return common; -error_luns: - common->nluns = i + 1; error_release: common->state = FSG_STATE_TERMINATED; /* The thread is dead */ /* Call fsg_common_release() directly, ref might be not initialised. */ -- 1.7.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html