linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Question: how to retrieve drvdata from open() ?
@ 2017-11-27 15:18 Christophe LEROY
  2017-11-27 16:38 ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Christophe LEROY @ 2017-11-27 15:18 UTC (permalink / raw)
  To: Alexander Viro, linux-fsdevel

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.

Thanks
Christophe

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question: how to retrieve drvdata from open() ?
  2017-11-27 15:18 Question: how to retrieve drvdata from open() ? Christophe LEROY
@ 2017-11-27 16:38 ` Matthew Wilcox
  2017-11-28  7:29   ` Christophe LEROY
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2017-11-27 16:38 UTC (permalink / raw)
  To: Christophe LEROY; +Cc: Alexander Viro, linux-fsdevel

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question: how to retrieve drvdata from open() ?
  2017-11-27 16:38 ` Matthew Wilcox
@ 2017-11-28  7:29   ` Christophe LEROY
  2017-11-29 10:55     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Christophe LEROY @ 2017-11-28  7:29 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: Alexander Viro, linux-fsdevel

Hi, thanks for your answwer,

Le 27/11/2017 à 17:38, Matthew Wilcox a écrit :
> 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.
> 

I see, you are right I'm talking about a character device.

The driver I'm trying to clean is using __register_chrdev() which hides 
cdev and cdev operations. Does it mean it has to be changed to do cdev 
operations explicitely ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Question: how to retrieve drvdata from open() ?
  2017-11-28  7:29   ` Christophe LEROY
@ 2017-11-29 10:55     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2017-11-29 10:55 UTC (permalink / raw)
  To: Christophe LEROY; +Cc: Matthew Wilcox, Alexander Viro, linux-fsdevel

On Tue, Nov 28, 2017 at 08:29:22AM +0100, Christophe LEROY wrote:
> Hi, thanks for your answwer,
> 
> Le 27/11/2017 � 17:38, Matthew Wilcox a �crit�:
> > 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.
> > 
> 
> I see, you are right I'm talking about a character device.
> 
> The driver I'm trying to clean is using __register_chrdev() which hides cdev
> and cdev operations. Does it mean it has to be changed to do cdev operations
> explicitely ?

If you want to get access to that, probably.  The cdev interface is
messy and tricky and can be used in about 5 different ways right now.
It's all up to what you need to do with it as to how to use it.

Have a pointer to your code somewhere?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-29 11:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-27 15:18 Question: how to retrieve drvdata from open() ? Christophe LEROY
2017-11-27 16:38 ` Matthew Wilcox
2017-11-28  7:29   ` Christophe LEROY
2017-11-29 10:55     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).