public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Rohith Seelaboyina <rseelaboyina@nvidia.com>
Cc: balbi@ti.com, gregkh@linuxfoundation.org, mina86@mina86.com,
	r.baldyga@samsung.com, andrzej.p@samsung.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] usb: gadget: ffs: Fix sparse error
Date: Wed, 24 Dec 2014 03:08:29 -0800	[thread overview]
Message-ID: <1419419309.6157.13.camel@perches.com> (raw)
In-Reply-To: <1419412728-12846-1-git-send-email-rseelaboyina@nvidia.com>

On Wed, 2014-12-24 at 14:48 +0530, Rohith Seelaboyina wrote:
> Dynamic memory allocation through kcalloc is more safer
> than declaring variable array size, Fix this error by
> using kcalloc for memory allocation, Check if memory
> allocation is successful and return -ENOMEM on failure.
> 
> Signed-off-by: Rohith Seelaboyina <rseelaboyina@nvidia.com>
> ---
> Changes in v2:
>    - Use kcalloc to allocate memory instead of using
>      kmalloc and memset.

style trivia:

> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
[]
> @@ -397,10 +397,13 @@ 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 = kcalloc(n,
> +			sizeof(struct usb_functionfs_event), GFP_KERNEL);
>  
> -	memset(events, 0, sizeof events);
> +	if (unlikely(!events))
> +		return -ENOMEM;

unlikely is not commonly used here.

I might be better to separate the declaration and the alloc
{
	[...]
	struct usb_functionfs_event *events;

	events = kcalloc(n, sizeof(*events), GFP_KERNEL);
	if (!events)
		return -ENOMEM;



      reply	other threads:[~2014-12-24 11:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-24  9:18 [PATCH v2] usb: gadget: ffs: Fix sparse error Rohith Seelaboyina
2014-12-24 11:08 ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1419419309.6157.13.camel@perches.com \
    --to=joe@perches.com \
    --cc=andrzej.p@samsung.com \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mina86@mina86.com \
    --cc=r.baldyga@samsung.com \
    --cc=rseelaboyina@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox