Re: [PATCH] usb: gadget: ffs: Fix sparse error

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

 



On Wed, 2014-12-24 at 10:59 +0530, Rohith Seelaboyina wrote:
> Dynamic memory allocation through kmalloc is more safer
> than declaring variable array size, Fix this error by
> using kmalloc for memory allocation, Check if memory
> allocation is successful and return -ENOMEM on failure.
[]
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
[]
> @@ -397,10 +397,15 @@ static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
>  	 * We are holding ffs->ev.waitq.lock and ffs->mutex and we need
>  	 * to release them.
>  	 */
> -	struct usb_functionfs_event events[n];
>  	unsigned i = 0;
> +	int ret;
> +	struct usb_functionfs_event *events = kmalloc(n *
> +			sizeof(struct usb_functionfs_event), GFP_KERNEL);
> +
> +	if (unlikely(!events))
> +		return -ENOMEM;
>  
> -	memset(events, 0, sizeof events);
> +	memset(events, 0, n * sizeof(*events));

kcalloc without memset please.


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