Re: [PATCH v2 14/21] 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]

 



On Fri, Jul 19 2013, Andrzej Pietrasiewicz wrote:
> 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>

Acked-by: Michal Nazarewicz <mina86@xxxxxxxxxx>

> ---
>  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 9f36e12..3d4406a 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -3000,12 +3000,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))
> @@ -3030,72 +3025,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_it = kzalloc(sizeof(**curlun_it), GFP_KERNEL);
> -		curlun = *curlun_it;
> -		if (!curlun) {
> -			rc = -ENOMEM;
> -			common->nluns = i;
> -			goto error_release;
> -		}
> -		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);
> -		snprintf(curlun->name, MAX_LUN_NAME_LEN,
> -			 dev_name(&curlun->dev));
> -
> -		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();
> @@ -3107,7 +3040,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");
> @@ -3120,37 +3052,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
>

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@xxxxxxxxxx>--------------ooO--(_)--Ooo--

Attachment: signature.asc
Description: PGP signature


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

  Powered by Linux