Re: [PATCH v5 01/15] usb/gadget: f_mass_storage: create _fsg_common_free_buffers

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

 



On Thu, Oct 03 2013, Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx> wrote:
> When configfs is in place, gadgets will have to be able to free
> fsg buffers. Add a helper function.
>
> 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 |   24 +++++++++++++++---------
>  1 files changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
> index 32e5ab7..7d57542 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -2642,6 +2642,18 @@ static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
>  	return -EINVAL;
>  }
>  
> +static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
> +{
> +	if (buffhds) {
> +		struct fsg_buffhd *bh = buffhds;
> +		while (n--) {
> +			kfree(bh->buf);
> +			++bh;
> +		}
> +		kfree(buffhds);
> +	}
> +}
> +
>  struct fsg_common *fsg_common_init(struct fsg_common *common,
>  				   struct usb_composite_dev *cdev,
>  				   struct fsg_config *cfg)
> @@ -2897,15 +2909,9 @@ static void fsg_common_release(struct kref *ref)
>  		kfree(common->luns);
>  	}
>  
> -	{
> -		struct fsg_buffhd *bh = common->buffhds;
> -		unsigned i = common->fsg_num_buffers;
> -		do {
> -			kfree(bh->buf);
> -		} while (++bh, --i);
> -	}
> -
> -	kfree(common->buffhds);
> +	if (likely(common->buffhds))

You're checking for that in the free function anyway, so just drop the
condition here.

> +		_fsg_common_free_buffers(common->buffhds,
> +					 common->fsg_num_buffers);
>  	if (common->free_storage_on_release)
>  		kfree(common);
>  }

-- 
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