lkml.org 
[lkml]   [2005]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: sizeof(ptr) or sizeof(*ptr)?
    Quoting Matthew Dharm <mdharm-kernel@one-eyed-alien.net>:
    > [...]
    > us->host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
    >
    > This is actually correct as-is. We're allocating a host, and asking for
    > the sizeof(pointer) in the 'extra storage' section. We then store the
    > pointer (not what it points to) in the extra storage section a few lines
    > down.

    Thanks for clarifying that. I guess the weekend effect got me, because at a
    certain point I was starting to read the scsi_host_alloc as if it were a
    kmalloc or something... :P

    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);
    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);
    if (!br->levels)
    goto out;

    "br" if of type "struct acpi_video_device_brightness *".

    "sizeof &br" doesn't make much sense there (besides the unconventional use of
    sizeof without parenthesis) because the rest of the code seem to suggest that a
    whole structure should have been allocated. This is the last case I've seen,
    and I've added the maintainer to the cc list, so that he can check the code for
    correctness.

    Well, sorry about bothering you with a false positive (that I should've
    recognised on my own, anyway), and thanks for the help.

    --
    Paulo Marques - www.grupopie.com

    All that is necessary for the triumph of evil is that good men do nothing.
    Edmund Burke (1729 - 1797)

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 14:10    [W:4.754 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site