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 *".
Passing "void *" is generally considered worse

  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:

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 {
        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);
} at24_iface;

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;


[...]

struct at24_platform_data {
        u32             byte_len;               /* size (sum of all addr) */
        u16             page_size;              /* for writes */
[...]
        int             (*setup)(struct at24_iface *iface, void *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