[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Prayer.1.3.4.1111300843050.31356@hermes-2.csi.cam.ac.uk>
Date: 30 Nov 2011 08:43:05 +0000
From: "J.I. Cameron" <jic23@....ac.uk>
To: Dan Carpenter <dan.carpenter@...cle.com>
Cc: Thomas Meyer <thomas@...3r.de>, gregkh@...e.de,
linux-iio@...r.kernel.org, devel@...verdev.osuosl.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] staging:iio: Use kcalloc instead of kzalloc to allocate
array
On Nov 30 2011, Dan Carpenter wrote:
>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
>>
Fine by me. Thanks. As stated by others though you might want to change the description
to not imply it's mainly about overflows.
>> Signed-off-by: Thomas Meyer <thomas@...3r.de>
Acked-by: Jonathan Cameron <jic23@...nel.org>
>> ---
>>
>> 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists