Hello, I wrote:

That didn't stop you from using 'void *context' as an argument. ;-)

The void* that's "worse" is one that must only point to a
specific type of object.  When the type has that kind of
restriction, using void* is nothing but bug-bait.
      It's OK when the point is explicitly to pass around a handle
of arbitrary type, for interpretation by whatever provided it
in the first place -- the role of caller "context" in this and
many other interfaces.

You have yourself said that you'd like to use this approach uniformly in several drivers -- which would naturally have different device instance objects hiding behind 'void *'.

What I said was I wanted "struct at24_iface *" to
not be specific to the at24 driver.  Maybe a
"struct persistent_memory *" or "struct blob *".

I don't know how you can turn that into "void *".

  Sigh, I never suggested that. :-/
What I suggested is using 'void *' to pass a pointer to device data which 'struct at24_iface *' (or whatever the name will be) certainly is not.
  I wonder how many lines you were skipping reading my mails...

Foir the clarity, that's what I suggested after I'd agreed that diurect exporting of read()/write() methods was undesirable:

   And if you're so afraid of 'void *', wee can use the incoplete struct:

static ssize_t at24_iface_read(void *data, char *buf, off_t offset, size_t count)
{
    return at24_eeprom_read((struct at24_data *)data, buf, offset, count);
}

static ssize_t at24_iface_write(void *data, char *buf, off_t offset, size_t count)
{
    return at24_eeprom_write((struct at24_data *)data, buf, offset, count);
}

static const struct at24_iface {

Oops, I shouldn't have moved that 'struct' declaration from the header file and should've initialzied the variable (was in haste and overlooked that) -- so, it should've been:

static const struct at24_iface at24_iface = {
        .read  = at24_iface_read,
        .write = at24_iface_write
};

static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
    struct at24_platform_data chip;

[...]

    /* export data to kernel code */
    if (chip.setup)
        chip.setup(&at24_iface, at24, chip.context);

    return 0;

[...]

   And in the header:

struct at24_iface {
        ssize_t (*read)(void *data, char *buf, off_t offset, size_t count);
        ssize_t (*write)(void *data, char *buf, off_t offset, size_t count);
};

struct at24_data;

struct at24_platform_data {
    u32        byte_len;        /* size (sum of all addr) */
    u16        page_size;        /* for writes */
[...]

        int     (*setup)(const struct at24_iface *iface, struct ata24_data 
*data,
                         void *context);
    void        *context;
};

WBR, Sergei

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to