From: Arjun Sreedharan <arjun024@gmail.com>
To: gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: use kcalloc instead of kzalloc
Date: Tue, 19 Aug 2014 16:08:01 +0530 [thread overview]
Message-ID: <1408444681-1601-1-git-send-email-arjun024@gmail.com> (raw)
kcalloc has protection from integer overflows
which could arise from the multiplication of
number of elements and size.
Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>
---
drivers/usb/core/config.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index b2a540b..abde67d 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -318,7 +318,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
struct usb_interface_cache *intfc;
struct usb_host_interface *alt;
int i, n;
- int len, retval;
+ int retval;
int num_ep, num_ep_orig;
d = (struct usb_interface_descriptor *) buffer;
@@ -380,8 +380,7 @@ static int usb_parse_interface(struct device *ddev, int cfgno,
if (num_ep > 0) {
/* Can't allocate 0 bytes */
- len = sizeof(struct usb_host_endpoint) * num_ep;
- alt->endpoint = kzalloc(len, GFP_KERNEL);
+ alt->endpoint = kcalloc(num_ep, sizeof(struct usb_host_endpoint), GFP_KERNEL);
if (!alt->endpoint)
return -ENOMEM;
}
@@ -683,13 +682,11 @@ int usb_get_configuration(struct usb_device *dev)
return -EINVAL;
}
- length = ncfg * sizeof(struct usb_host_config);
- dev->config = kzalloc(length, GFP_KERNEL);
+ dev->config = kcalloc(ncfg, sizeof(struct usb_host_config), GFP_KERNEL);
if (!dev->config)
goto err2;
- length = ncfg * sizeof(char *);
- dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
+ dev->rawdescriptors = kcalloc(ncfg, sizeof(char *), GFP_KERNEL);
if (!dev->rawdescriptors)
goto err2;
--
1.8.1.msysgit.1
next reply other threads:[~2014-08-19 10:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-19 10:38 Arjun Sreedharan [this message]
2014-08-19 10:56 ` [PATCH] usb: use kcalloc instead of kzalloc Clemens Ladisch
2014-08-19 14:41 ` Alan Stern
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=1408444681-1601-1-git-send-email-arjun024@gmail.com \
--to=arjun024@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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