All of lore.kernel.org
 help / color / mirror / Atom feed
From: bjorn@mork.no (Bjørn Mork)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Proper way to get device file minor number from struct file
Date: Sun, 10 Jul 2016 18:02:23 +0200	[thread overview]
Message-ID: <877fcta3cg.fsf@miraculix.mork.no> (raw)
In-Reply-To: <nltp7i$5oi$1@ger.gmane.org> (Matwey V. Kornilov's message of "Sun, 10 Jul 2016 18:22:25 +0300")

"Matwey V. Kornilov" <matwey.kornilov@gmail.com> writes:

> Hello,
>
> I am looking through some legacy out of tree custom linux kernel device
> driver.
>
> It is full of lines like the following:
>
> iminor(fp->f_dentry->d_inode)
>
> here struct file *fp is an argument of callback of struct file_operations.
>
> Documentation/filesystems/porting says:
>
> "f_dentry is gone; use f_path.dentry, or, better yet, see if you can
> avoid it entirely"
>
> So, is there a proper compatible way to do the same?

Don't know how proper it is, but a "git grep iminor drivers/" shows that

   minor = iminor(file_inode(file));

is a very common construct.

Or alternatively, do the iminor(inode) lookup once in open() to lookup
up your device struct or whatever, and then save that reference in
file->private_data, thereby avoiding the need to know the minor anywhere
else.



Bj?rn

      reply	other threads:[~2016-07-10 16:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-10 15:22 Proper way to get device file minor number from struct file Matwey V. Kornilov
2016-07-10 16:02 ` Bjørn Mork [this message]

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=877fcta3cg.fsf@miraculix.mork.no \
    --to=bjorn@mork.no \
    --cc=kernelnewbies@lists.kernelnewbies.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.