From: Paulo Marques <pmarques@grupopie.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: sizeof(ptr) or sizeof(*ptr)?
Date: Tue, 08 Mar 2005 13:20:29 +0000 [thread overview]
Message-ID: <422DA69D.6070105@grupopie.com> (raw)
In-Reply-To: <20050227213946.199e82af.akpm@osdl.org>
[-- Attachment #1: Type: text/plain, Size: 1560 bytes --]
Andrew Morton wrote:
> "" <pmarques@grupopie.com> wrote:
>
>>Anyway, after improving the tool and checking for false positives, there is only
>> one more suspicious piece of code in drivers/acpi/video.c:561
>>
>> status = acpi_video_device_lcd_query_levels(device, &obj);
>>
>> if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) {
>> int count = 0;
>> union acpi_object *o;
>>
>> br = kmalloc(sizeof &br, GFP_KERNEL);
>
>
> yup, bug.
>
>
>> if (!br) {
>> printk(KERN_ERR "can't allocate memory\n");
>> } else {
>> memset(br, 0, sizeof &br);
>> br->levels = kmalloc(obj->package.count * sizeof &br->levels, GFP_KERNEL);
>
>
> And another one, although it happens to work out OK.
>
> I'll get these all fixed up, thanks.
I just checked the 2.6.11-mm1 release and this is only half-fixed there,
and it is the worst of both halves: the kmalloc only mallocs the size of
a pointer, but the memset is fixed, so it memset's the size of a
structure (oops). This is partially my fault for not sending the patch
in the first place, together with the bug report.
The attached patch against 2.6.11-mm1 should fix the kmalloc.
By the way, I haven't got any response from an alsa developer about the
bug in sound/core/control.c, but this is already fixed in 2.6.11-mm1,
along with several other changes to that file. So the status is: it was
a bug, but it is already fixed :)
--
Paulo Marques - www.grupopie.com
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke (1729 - 1797)
[-- Attachment #2: acpipatch --]
[-- Type: text/plain, Size: 569 bytes --]
--- ./drivers/acpi/video.c.orig 2005-03-08 13:07:42.000000000 +0000
+++ ./drivers/acpi/video.c 2005-03-08 13:09:05.000000000 +0000
@@ -564,11 +564,11 @@ acpi_video_device_find_cap (struct acpi_
int count = 0;
union acpi_object *o;
- br = kmalloc(sizeof &br, GFP_KERNEL);
+ br = kmalloc(sizeof(*br), GFP_KERNEL);
if (!br) {
printk(KERN_ERR "can't allocate memory\n");
} else {
- memset(br, 0, sizeof *br);
+ memset(br, 0, sizeof(*br));
br->levels = kmalloc(obj->package.count *
sizeof *(br->levels), GFP_KERNEL);
if (!br->levels)
prev parent reply other threads:[~2005-03-08 13:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-27 20:25 sizeof(ptr) or sizeof(*ptr)? pmarques
2005-02-27 20:45 ` Matthew Dharm
2005-02-27 23:13 ` pmarques
2005-02-28 5:39 ` Andrew Morton
2005-03-08 13:20 ` Paulo Marques [this message]
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=422DA69D.6070105@grupopie.com \
--to=pmarques@grupopie.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.