lkml.org 
[lkml]   [2002]   [May]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: Strange code in ide_cdrom_register
    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/

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