[PATCH v4 12/19] usb/gadget: f_mass_storage: use fsg_common_create_luns in fsg_common_init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 |  101 ++---------------------------------
 1 files changed, 4 insertions(+), 97 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 970213f..c55950f 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3032,12 +3032,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_it;
-	struct fsg_lun_config *lcfg;
-	int nluns, i, rc;
-	char *pathbuf;
-
+	int i, rc;
 
 	common = fsg_common_setup(common, !!common);
 	if (IS_ERR(common))
@@ -3062,72 +3057,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_it = common->luns;
-	nluns = cfg->nluns;
-	for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun_it, ++lcfg) {
-		struct fsg_lun *curlun;
-
-		curlun = kzalloc(sizeof(*curlun), GFP_KERNEL);
-		if (!curlun) {
-			rc = -ENOMEM;
-			common->nluns = i;
-			goto error_release;
-		}
-		*curlun_it = curlun;
-
-		curlun->name = kzalloc(MAX_LUN_NAME_LEN, GFP_KERNEL);
-		if (!curlun->name) {
-			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);
-		strlcpy(curlun->name, dev_name(&curlun->dev), MAX_LUN_NAME_LEN);
-
-		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();
@@ -3139,7 +3072,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");
@@ -3152,37 +3084,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_it = common->luns;
-	     i < nluns;
-	     ++curlun_it, ++i) {
-		struct fsg_lun *curlun = *curlun_it;
-		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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux