Re: Question: how to retrieve drvdata from open() ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Nov 27, 2017 at 04:18:42PM +0100, Christophe LEROY wrote:
> When registering a device node with device_create(), it is possible to pass
> a drvdata pointer.
> 
> How can I retrieve that drvdata pointer from the open() fops ? I've not been
> able to find any exemple.

You're not supposed to do it that way ... assuming you're talking about
a character device, you embed the cdev in your own data structure and
do this:

struct my_struct *my = container_of(inode->i_cdev, struct my_struct, cdev);

after calling:

cdev_init(&my->cdev, &my_dev_fops);

You'll use the drvdata when trying to go from the struct device to
'my_struct'.  There's no struct device in struct cdev.  I mean, you
could probably get to it, but it's easier if you just do it the way that
everybody else does it.



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux