Re: [PATCH v5 04/15] usb/gadget: f_mass_storage: create fsg_common_set_num_buffers for use in fsg_common_init

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

 



On Thu, Oct 03 2013, Andrzej Pietrasiewicz wrote:
> fsg_common_init is a lengthy function. Factor a portion of it out.
>
> 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 |   68 +++++++++++++++++++++-------------
>  drivers/usb/gadget/f_mass_storage.h |    2 +
>  2 files changed, 44 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
> index b7ed792..4833710 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -2682,6 +2682,45 @@ static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
>  	}
>  }
>  
> +int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
> +{
> +	struct fsg_buffhd *bh, *new_buffhds;
> +	int i, rc;
> +
> +	rc = fsg_num_buffers_validate(n);
> +	if (rc != 0)
> +		return rc;
> +
> +	new_buffhds = kcalloc(n, sizeof *(new_buffhds), GFP_KERNEL);

What's with the parens around new_buffhds?  And why call it
“new_buffhds”?  What's wrong with “buffhds”?

> +	if (!new_buffhds)
> +		return -ENOMEM;
> +
> +	/* Data buffers cyclic list */
> +	bh = new_buffhds;
> +	i = n;
> +	goto buffhds_first_it;
> +	do {
> +		bh->next = bh + 1;
> +		++bh;
> +buffhds_first_it:
> +		bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
> +		if (unlikely(!bh->buf))
> +			goto error_release;
> +	} while (--i);
> +	bh->next = new_buffhds;
> +
> +	_fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
> +	common->fsg_num_buffers = n;
> +	common->buffhds = new_buffhds;
> +
> +	return 0;
> +
> +error_release:
> +	_fsg_common_free_buffers(new_buffhds, n - i);

Just pass n.  kfree() is a no-op for NULL, so _fsg_common_free_buffers()
should handle initialised buffhds pointers gracefully.

> +
> +	return -ENOMEM;
> +}
> +
>  static inline void fsg_common_remove_sysfs(struct fsg_lun *lun)
>  {
>  	device_remove_file(&lun->dev, &dev_attr_nofua);

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