proc: Supply an accessor for getting the data from a PDE's parent
authorDavid Howells <dhowells@redhat.com>
Fri, 12 Apr 2013 13:06:01 +0000 (14:06 +0100)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 1 May 2013 21:29:42 +0000 (17:29 -0400)
Supply an accessor function for getting the private data from the parent
proc_dir_entry struct of the proc_dir_entry struct associated with an inode.

ReiserFS, for instance, stores the super_block pointer in the proc directory
it makes for that super_block, and a pointer to the respective seq_file show
function in each of the proc files in that directory.

This allows a reduction in the number of file_operations structs, open
functions and seq_operations structs required.  The problem otherwise is that
each show function requires two pieces of data but only has storage for one
per PDE (and this has no release function).

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
cc: Jerry Chuang <jerry-chuang@realtek.com>
cc: Maxim Mikityanskiy <maxtram95@gmail.com>
cc: YAMANE Toshiaki <yamanetoshi@gmail.com>
cc: linux-wireless@vger.kernel.org
cc: linux-scsi@vger.kernel.org
cc: devel@driverdev.osuosl.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/scsi/megaraid.c
drivers/staging/rtl8187se/r8180_core.c
drivers/staging/rtl8192u/r8192U_core.c
fs/proc/generic.c
include/linux/proc_fs.h

index ef3384d..7373255 100644 (file)
@@ -2760,7 +2760,7 @@ proc_show_rdrv_40(struct seq_file *m, void *v)
  */
 static int mega_proc_open(struct inode *inode, struct file *file)
 {
-       adapter_t *adapter = PDE(inode)->parent->data;
+       adapter_t *adapter = proc_get_parent_data(inode);
        int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
 
        return single_open(file, show, adapter);
index ab469ce..f7c1d99 100644 (file)
@@ -296,7 +296,7 @@ void rtl8180_proc_remove_one(struct net_device *dev)
  */
 static int rtl8180_proc_open(struct inode *inode, struct file *file)
 {
-       struct net_device *dev = PDE(inode)->parent->data;
+       struct net_device *dev = proc_get_parent_data(inode);
        int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
 
        return single_open(file, show, dev);
index 27ba2a3..1459233 100644 (file)
@@ -637,7 +637,7 @@ void rtl8192_proc_module_remove(void)
  */
 static int rtl8192_proc_open(struct inode *inode, struct file *file)
 {
-       struct net_device *dev = PDE(inode)->parent->data;
+       struct net_device *dev = proc_get_parent_data(inode);
        int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
 
        return single_open(file, show, dev);
index 4074da5..75e08d3 100644 (file)
@@ -617,3 +617,10 @@ int remove_proc_subtree(const char *name, struct proc_dir_entry *parent)
        return 0;
 }
 EXPORT_SYMBOL(remove_proc_subtree);
+
+void *proc_get_parent_data(const struct inode *inode)
+{
+       struct proc_dir_entry *de = PDE(inode);
+       return de->parent->data;
+}
+EXPORT_SYMBOL_GPL(proc_get_parent_data);
index a0fb1c2..bae8207 100644 (file)
@@ -86,6 +86,7 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
  
 extern void proc_set_size(struct proc_dir_entry *, loff_t);
 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
+extern void *proc_get_parent_data(const struct inode *);
 #else
 
 static inline void proc_flush_task(struct task_struct *task)