From: Michael Dunsky <michael.dunsky@p4all.de>
To: linux-kernel@vger.kernel.org
Cc: Peter Chubb <peter@chubb.wattle.id.au>,
Russel King <rmk@arm.linux.org.uk>
Subject: Re: Strange code in ide_cdrom_register
Date: Thu, 30 May 2002 22:19:38 +0200 [thread overview]
Message-ID: <3CF6895A.2050801@p4all.de> (raw)
In-Reply-To: <15605.34861.599803.405864@wombat.chubb.wattle.id.au> <3CF5D424.2060500@p4all.de> <15605.60268.673419.701625@wombat.chubb.wattle.id.au>
Hi!
Peter Chubb wrote:
....
> The cast is *wrong*, and potentially dangerous.
>
> I'll submit a patch....
OK. Maybe my problem is this
(in thinking - last night was definetly too short...):
---------- from ide-cd.c ------------------
static int ide_cdrom_register (ide_drive_t *drive, int nslots)
{
struct cdrom_info *info = drive->driver_data;
struct cdrom_device_info *devinfo = &info->devinfo;
...
*(int *)&devinfo->speed = CDROM_STATE_FLAGS (drive)->current_speed;
*(int *)&devinfo->capacity = nslots;
---------- from ide-cd.c ------------------
As you can see there are several stages of pointers:
Parameter "drive" is pointer to the original var,
"info" is a pointer to "drive->driver_data",
"devinfo" is a pointer to the address of "info->devinfo".
So we put a value into a mem-address referenced by several pointers -
but whats the type of that address? The other values are (nearly all)
just simply ints or pointers. Just putting a byte-value into a field
defined as int would probably be wrong.
But, Russel, you're right:
If we had to cast we would do it with the source.
This _is_ strange code *scratch head* :-/
ciao
Michael
prev parent reply other threads:[~2002-05-30 20:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-30 2:02 Strange code in ide_cdrom_register Peter Chubb
2002-05-30 7:26 ` Michael Dunsky
2002-05-30 9:05 ` Peter Chubb
2002-05-30 10:35 ` J.A. Magallon
2002-05-30 20:19 ` Michael Dunsky [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=3CF6895A.2050801@p4all.de \
--to=michael.dunsky@p4all.de \
--cc=linux-kernel@vger.kernel.org \
--cc=peter@chubb.wattle.id.au \
--cc=rmk@arm.linux.org.uk \
/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