Skip to content

Commit 6dfbbae

Browse files
Muchun Songtorvalds
authored andcommitted
fs: proc: store PDE()->data into inode->i_private
PDE_DATA(inode) is introduced to get user private data and hide the layout of struct proc_dir_entry. The inode->i_private is used to do the same thing as well. Save a copy of user private data to inode-> i_private when proc inode is allocated. This means the user also can get their private data by inode->i_private. Introduce pde_data() to wrap inode->i_private so that we can remove PDE_DATA() from fs/proc/generic.c and make PTE_DATE() as a wrapper of pde_data(). It will be easier if we decide to remove PDE_DATE() in the future. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Muchun Song <[email protected]> Acked-by: Christian Brauner <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Alexey Gladkov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a372659 commit 6dfbbae

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

fs/proc/generic.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,6 @@ void proc_remove(struct proc_dir_entry *de)
791791
}
792792
EXPORT_SYMBOL(proc_remove);
793793

794-
void *PDE_DATA(const struct inode *inode)
795-
{
796-
return __PDE_DATA(inode);
797-
}
798-
EXPORT_SYMBOL(PDE_DATA);
799-
800794
/*
801795
* Pull a user buffer into memory and pass it to the file's write handler if
802796
* one is supplied. The ->write() method is permitted to modify the

fs/proc/inode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
650650
return NULL;
651651
}
652652

653+
inode->i_private = de->data;
653654
inode->i_ino = de->low_ino;
654655
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
655656
PROC_I(inode)->pde = de;

fs/proc/internal.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ static inline struct proc_dir_entry *PDE(const struct inode *inode)
115115
return PROC_I(inode)->pde;
116116
}
117117

118-
static inline void *__PDE_DATA(const struct inode *inode)
119-
{
120-
return PDE(inode)->data;
121-
}
122-
123118
static inline struct pid *proc_pid(const struct inode *inode)
124119
{
125120
return PROC_I(inode)->pid;

include/linux/proc_fs.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,18 @@ extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
110110
struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
111111
extern void proc_set_size(struct proc_dir_entry *, loff_t);
112112
extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
113-
extern void *PDE_DATA(const struct inode *);
113+
114+
/*
115+
* Obtain the private data passed by user through proc_create_data() or
116+
* related.
117+
*/
118+
static inline void *pde_data(const struct inode *inode)
119+
{
120+
return inode->i_private;
121+
}
122+
123+
#define PDE_DATA(i) pde_data(i)
124+
114125
extern void *proc_get_parent_data(const struct inode *);
115126
extern void proc_remove(struct proc_dir_entry *);
116127
extern void remove_proc_entry(const char *, struct proc_dir_entry *);

0 commit comments

Comments
 (0)