lkml.org 
[lkml]   [2014]   [Dec]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2] usb: gadget: ffs: Fix sparse error
From
Date
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;




\
 
 \ /
  Last update: 2014-12-24 12:41    [W:0.037 / U:0.776 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site