Re: Strange code in ide_cdrom_register

Michael Dunsky (michael.dunsky@p4all.de)
Thu, 30 May 2002 22:19:38 +0200


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

-
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/