mirror of https://lore.kernel.org/lkml/
 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,
	david.a.cohen@linux.intel.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: ffs: Fix sparse error
Date: Tue, 23 Dec 2014 21:39:32 -0800	[thread overview]
Message-ID: <1419399572.6157.7.camel@perches.com> (raw)
In-Reply-To: <1419398988-14576-1-git-send-email-rseelaboyina@nvidia.com>

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.



      reply	other threads:[~2014-12-24  5:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-24  5:29 Rohith Seelaboyina
2014-12-24  5:39 ` 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=1419399572.6157.7.camel@perches.com \
    --to=joe@perches.com \
    --cc=andrzej.p@samsung.com \
    --cc=balbi@ti.com \
    --cc=david.a.cohen@linux.intel.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

Powered by JetHome