From: Christophe LEROY <christophe.leroy@c-s.fr>
To: Matthew Wilcox <willy@infradead.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org
Subject: Re: Question: how to retrieve drvdata from open() ?
Date: Tue, 28 Nov 2017 08:29:22 +0100 [thread overview]
Message-ID: <18ca88f1-b115-f8e8-f56f-a7b9a946e7cc@c-s.fr> (raw)
In-Reply-To: <20171127163825.GB8265@bombadil.infradead.org>
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 ?
next prev parent reply other threads:[~2017-11-28 7:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2017-11-29 10:55 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18ca88f1-b115-f8e8-f56f-a7b9a946e7cc@c-s.fr \
--to=christophe.leroy@c-s.fr \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).