Skip to content

Commit

Permalink
usb: gadget: Use kcalloc instead of kzalloc to allocate array
Browse files Browse the repository at this point in the history
The advantage of kcalloc is, that will prevent integer overflows which could
result from the multiplication of number of elements and size and it is also
a bit nicer to read.

The semantic patch that makes this change is available
in https://lkml.org/lkml/2011/11/25/107

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
Acked-by: Michal Nazarewicz <[4]mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Thomas Meyer authored and Felipe Balbi committed Dec 12, 2011
1 parent b294b20 commit 9823a52
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/usb/gadget/f_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ static int ffs_epfiles_create(struct ffs_data *ffs)
ENTER();

count = ffs->eps_count;
epfiles = kzalloc(count * sizeof *epfiles, GFP_KERNEL);
epfiles = kcalloc(count, sizeof(*epfiles), GFP_KERNEL);
if (!epfiles)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/gadget/f_mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
* Create the LUNs, open their backing files, and register the
* LUN devices in sysfs.
*/
curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL);
curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL);
if (unlikely(!curlun)) {
rc = -ENOMEM;
goto error_release;
Expand Down

0 comments on commit 9823a52

Please sign in to comment.