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 | 22 +++++----------------- 1 files changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 1234990..45b44d7 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -3039,12 +3039,6 @@ struct fsg_common *fsg_common_init(struct fsg_common *common, int nluns, i, rc; char *pathbuf; - /* Find out how many LUNs there should be */ - nluns = cfg->nluns; - if (nluns < 1 || nluns > FSG_MAX_LUNS) { - dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns); - return ERR_PTR(-EINVAL); - } common = fsg_common_setup(common, !!common); if (IS_ERR(common)) @@ -3074,17 +3068,12 @@ struct fsg_common *fsg_common_init(struct fsg_common *common, } fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id; - /* - * Create the LUNs, open their backing files, and register the - * LUN devices in sysfs. - */ - curlun_it = kcalloc(nluns, sizeof(*curlun_it), GFP_KERNEL); - if (unlikely(!curlun_it)) { - rc = -ENOMEM; - goto error_release; - } - common->luns = curlun_it; + rc = fsg_common_set_nluns(common, cfg->nluns); + if (rc) + goto error_release; + curlun_it = common->luns; + nluns = cfg->nluns; for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun_it, ++lcfg) { struct fsg_lun *curlun; @@ -3148,7 +3137,6 @@ struct fsg_common *fsg_common_init(struct fsg_common *common, goto error_luns; } } - common->nluns = nluns; /* Prepare inquiryString */ -- 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