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)?
On Sun, Feb 27, 2005 at 08:25:04PM +0000, pmarques@grupopie.com wrote:
> I decided to tweak sparse to give warnings on sizeof(pointer), so that I could
> check for other cases like this. The tweak was a very crude hack that I'm not
> proud of, and I am still trying to make it more reliable.
>
> So far I found 2 interesting cases (in 2.6.11-rc5). I'm not sure they are bugs,
> but they sure look suspicious.
>
> 1: drivers/usb/storage/usb.c:788
>
> /*
> * Since this is a new device, we need to register a SCSI
> * host definition with the higher SCSI layers.
> */
> us->host = scsi_host_alloc(&usb_stor_host_template, sizeof(us));
> if (!us->host) {
> printk(KERN_WARNING USB_STORAGE
> "Unable to allocate the scsi host\n");
> return -EBUSY;
> }
>
> "us" is a "struct us_data *". It seems pretty weird that we're allocating
> something the size of a pointer, and then waste a pointer to keep the address
> where it is allocated. So maybe this should be:
>
> 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.

Matt

--
Matthew Dharm Home: mdharm-usb@one-eyed-alien.net
Maintainer, Linux USB Mass Storage Driver

S: Another stupid question?
G: There's no such thing as a stupid question, only stupid people.
-- Stef and Greg
User Friendly, 7/15/1998
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 14:10    [W:0.120 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site