Commit 9af27b28 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

fs/proc/inode.c: use typeof_member() macro

Don't repeat function signatures twice.

This is a kind-of-precursor for "struct proc_ops".

Note:

	typeof(pde->proc_fops->...) ...;

can't be used because ->proc_fops is "const struct file_operations *".
"const" prevents assignment down the code and it can't be deleted in the
type system.

Link: http://lkml.kernel.org/r/20190529191110.GB5703@avx2Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ce251e0e
...@@ -200,7 +200,8 @@ static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence) ...@@ -200,7 +200,8 @@ static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence)
struct proc_dir_entry *pde = PDE(file_inode(file)); struct proc_dir_entry *pde = PDE(file_inode(file));
loff_t rv = -EINVAL; loff_t rv = -EINVAL;
if (use_pde(pde)) { if (use_pde(pde)) {
loff_t (*llseek)(struct file *, loff_t, int); typeof_member(struct file_operations, llseek) llseek;
llseek = pde->proc_fops->llseek; llseek = pde->proc_fops->llseek;
if (!llseek) if (!llseek)
llseek = default_llseek; llseek = default_llseek;
...@@ -212,10 +213,11 @@ static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence) ...@@ -212,10 +213,11 @@ static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence)
static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{ {
ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
struct proc_dir_entry *pde = PDE(file_inode(file)); struct proc_dir_entry *pde = PDE(file_inode(file));
ssize_t rv = -EIO; ssize_t rv = -EIO;
if (use_pde(pde)) { if (use_pde(pde)) {
typeof_member(struct file_operations, read) read;
read = pde->proc_fops->read; read = pde->proc_fops->read;
if (read) if (read)
rv = read(file, buf, count, ppos); rv = read(file, buf, count, ppos);
...@@ -226,10 +228,11 @@ static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count, ...@@ -226,10 +228,11 @@ static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count,
static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{ {
ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
struct proc_dir_entry *pde = PDE(file_inode(file)); struct proc_dir_entry *pde = PDE(file_inode(file));
ssize_t rv = -EIO; ssize_t rv = -EIO;
if (use_pde(pde)) { if (use_pde(pde)) {
typeof_member(struct file_operations, write) write;
write = pde->proc_fops->write; write = pde->proc_fops->write;
if (write) if (write)
rv = write(file, buf, count, ppos); rv = write(file, buf, count, ppos);
...@@ -242,8 +245,9 @@ static __poll_t proc_reg_poll(struct file *file, struct poll_table_struct *pts) ...@@ -242,8 +245,9 @@ static __poll_t proc_reg_poll(struct file *file, struct poll_table_struct *pts)
{ {
struct proc_dir_entry *pde = PDE(file_inode(file)); struct proc_dir_entry *pde = PDE(file_inode(file));
__poll_t rv = DEFAULT_POLLMASK; __poll_t rv = DEFAULT_POLLMASK;
__poll_t (*poll)(struct file *, struct poll_table_struct *);
if (use_pde(pde)) { if (use_pde(pde)) {
typeof_member(struct file_operations, poll) poll;
poll = pde->proc_fops->poll; poll = pde->proc_fops->poll;
if (poll) if (poll)
rv = poll(file, pts); rv = poll(file, pts);
...@@ -256,8 +260,9 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne ...@@ -256,8 +260,9 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne
{ {
struct proc_dir_entry *pde = PDE(file_inode(file)); struct proc_dir_entry *pde = PDE(file_inode(file));
long rv = -ENOTTY; long rv = -ENOTTY;
long (*ioctl)(struct file *, unsigned int, unsigned long);
if (use_pde(pde)) { if (use_pde(pde)) {
typeof_member(struct file_operations, unlocked_ioctl) ioctl;
ioctl = pde->proc_fops->unlocked_ioctl; ioctl = pde->proc_fops->unlocked_ioctl;
if (ioctl) if (ioctl)
rv = ioctl(file, cmd, arg); rv = ioctl(file, cmd, arg);
...@@ -271,8 +276,9 @@ static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsigned ...@@ -271,8 +276,9 @@ static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsigned
{ {
struct proc_dir_entry *pde = PDE(file_inode(file)); struct proc_dir_entry *pde = PDE(file_inode(file));
long rv = -ENOTTY; long rv = -ENOTTY;
long (*compat_ioctl)(struct file *, unsigned int, unsigned long);
if (use_pde(pde)) { if (use_pde(pde)) {
typeof_member(struct file_operations, compat_ioctl) compat_ioctl;
compat_ioctl = pde->proc_fops->compat_ioctl; compat_ioctl = pde->proc_fops->compat_ioctl;
if (compat_ioctl) if (compat_ioctl)
rv = compat_ioctl(file, cmd, arg); rv = compat_ioctl(file, cmd, arg);
...@@ -286,8 +292,9 @@ static int proc_reg_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -286,8 +292,9 @@ static int proc_reg_mmap(struct file *file, struct vm_area_struct *vma)
{ {
struct proc_dir_entry *pde = PDE(file_inode(file)); struct proc_dir_entry *pde = PDE(file_inode(file));
int rv = -EIO; int rv = -EIO;
int (*mmap)(struct file *, struct vm_area_struct *);
if (use_pde(pde)) { if (use_pde(pde)) {
typeof_member(struct file_operations, mmap) mmap;
mmap = pde->proc_fops->mmap; mmap = pde->proc_fops->mmap;
if (mmap) if (mmap)
rv = mmap(file, vma); rv = mmap(file, vma);
...@@ -305,7 +312,7 @@ proc_reg_get_unmapped_area(struct file *file, unsigned long orig_addr, ...@@ -305,7 +312,7 @@ proc_reg_get_unmapped_area(struct file *file, unsigned long orig_addr,
unsigned long rv = -EIO; unsigned long rv = -EIO;
if (use_pde(pde)) { if (use_pde(pde)) {
typeof(proc_reg_get_unmapped_area) *get_area; typeof_member(struct file_operations, get_unmapped_area) get_area;
get_area = pde->proc_fops->get_unmapped_area; get_area = pde->proc_fops->get_unmapped_area;
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
...@@ -326,8 +333,8 @@ static int proc_reg_open(struct inode *inode, struct file *file) ...@@ -326,8 +333,8 @@ static int proc_reg_open(struct inode *inode, struct file *file)
{ {
struct proc_dir_entry *pde = PDE(inode); struct proc_dir_entry *pde = PDE(inode);
int rv = 0; int rv = 0;
int (*open)(struct inode *, struct file *); typeof_member(struct file_operations, open) open;
int (*release)(struct inode *, struct file *); typeof_member(struct file_operations, release) release;
struct pde_opener *pdeo; struct pde_opener *pdeo;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment