From: Dan Carpenter <dan.carpenter@oracle.com>
To: Thomas Meyer <thomas@m3y3r.de>
Cc: gregkh@suse.de, linux-iio@vger.kernel.org,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging:iio: Use kcalloc instead of kzalloc to allocate array
Date: Wed, 30 Nov 2011 09:35:23 +0300 [thread overview]
Message-ID: <20111130063523.GS3195@mwanda> (raw)
In-Reply-To: <1322600880.1534.334.camel@localhost.localdomain>
[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]
On Tue, Nov 29, 2011 at 10:08:00PM +0100, Thomas Meyer wrote:
> 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>
> ---
>
> diff -u -p a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
> --- a/drivers/staging/iio/accel/lis3l02dq_ring.c 2011-11-13 11:07:47.933826988 +0100
> +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c 2011-11-28 20:00:44.704446880 +0100
> @@ -93,8 +93,7 @@ static int lis3l02dq_read_all(struct iio
> struct spi_message msg;
> int ret, i, j = 0;
>
> - xfers = kzalloc((buffer->scan_count) * 2
> - * sizeof(*xfers), GFP_KERNEL);
> + xfers = kcalloc((buffer->scan_count) * 2, sizeof(*xfers), GFP_KERNEL);
I've looked at these and none of them can actually overflow.
But if they could then there would still be the potential for
overflow here. If buffer->scan_count were a negative number then
the first for loop could cause memory corruption.
Still it's a cleanup and the patch is fine.
regards,
dan carpenter
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2011-11-30 6:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-29 21:08 [PATCH] staging:iio: Use kcalloc instead of kzalloc to allocate array Thomas Meyer
2011-11-30 1:04 ` JohnLM
2011-11-30 6:35 ` Dan Carpenter [this message]
2011-11-30 8:43 ` J.I. Cameron
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=20111130063523.GS3195@mwanda \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@suse.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thomas@m3y3r.de \
/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