mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matthew Dharm <mdharm-kernel@one-eyed-alien.net>
To: pmarques@grupopie.com
Cc: linux-kernel@vger.kernel.org, perex@suse.cz
Subject: Re: sizeof(ptr) or sizeof(*ptr)?
Date: Sun, 27 Feb 2005 12:45:24 -0800	[thread overview]
Message-ID: <20050227204524.GA29026@one-eyed-alien.net> (raw)
In-Reply-To: <1109535904.42222ca0b0b78@webmail.grupopie.com>

[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]

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

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2005-02-27 20:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-27 20:25 pmarques
2005-02-27 20:45 ` Matthew Dharm [this message]
2005-02-27 23:13   ` pmarques
2005-02-28  5:39     ` Andrew Morton
2005-03-08 13:20       ` Paulo Marques

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=20050227204524.GA29026@one-eyed-alien.net \
    --to=mdharm-kernel@one-eyed-alien.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@suse.cz \
    --cc=pmarques@grupopie.com \
    /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

Powered by JetHome