2013-04-16 18:26:01

by David Howells

[permalink] [raw]
Subject: [PATCH 00/28] Privatise procfs internals [RFC]


Here is a series of patches to make the procfs internals private to the procfs
filesystem. This is built on top of the patches to eliminate
create_proc_read_entry() after the kill-read_proc_t tag.

These patches include fixes for the places that are attempting to abuse
proc_dir_entry->count and doing it incorrectly because PID namespaces now
exist.

All accesses to the PDE struct have been replaced with out-of-line accessor
functions. This is a bit less efficient than it used to be, but this could be
mitigated by using inode->i_private.

The internal procfs structs have moved to fs/procfs/internal.h. Some of the
remaining stuff in linux/proc_fs.h has been split out to linux/kcore.h and
linux/proc_ns.h as they's separate specialised intefaces.

These patches can be seen here also:

http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=vfs-experimental

David
---
David Howells (28):
Include missing linux/slab.h inclusions
Include missing linux/magic.h inclusions
proc: Split kcore bits from linux/procfs.h into linux/kcore.h
proc: Supply PDE attribute setting accessor functions
proc: Uninline pid_delete_dentry()
proc: Move proc_fd() to fs/proc/fd.h
proc: Split the namespace stuff out into linux/proc_ns.h
proc: Move PDE_NET() to fs/proc/proc_net.c
proc: Move some bits from linux/proc_fs.h to linux/{of.h,signal.h,tty.h}
proc: Add proc_mkdir_data()
rtl8187se: Use a dir under /proc/net/r8180/
rtl8192u: Don't need to save device proc dir PDE
airo: Use remove_proc_subtree()
proc: Supply an accessor for getting the data from a PDE's parent
reiserfs: Don't access the proc_dir_entry in r_open(), r_start() r_show()
zoran: Don't print proc_dir_entry data in debug
drm: Constify drm_proc_list[]
drm: proc: Use minor->index to label things, not PDE->name
drm: proc: Use remove_proc_subtree()
hostap: proc: Use remove_proc_subtree()
dgrp: Clean up the use of procfs
ppc: Clean up rtas_flash driver somewhat
ppc: Clean up scanlog
proc: Supply an accessor to get the name in a proc_dir_entry struct
proc: Supply an accessor to get the process ID associated with some proc files
proc: Supply a function to remove a proc entry by PDE
proc: Make the PROC_I() and PDE() macros internal to procfs
proc: Move non-public stuff from linux/proc_fs.h to fs/proc/internal.h


arch/mips/mm/init.c | 1
arch/powerpc/kernel/proc_powerpc.c | 2
arch/powerpc/kernel/rtas_flash.c | 446 +++++++++++++----------------
arch/powerpc/platforms/pseries/reconfig.c | 2
arch/powerpc/platforms/pseries/scanlog.c | 29 +-
arch/s390/kernel/os_info.c | 1
arch/score/mm/init.c | 2
arch/sparc/kernel/sun4d_irq.c | 1
arch/x86/mm/init_64.c | 1
arch/x86/platform/efi/efi.c | 1
arch/x86/platform/efi/efi_64.c | 1
drivers/acpi/sbs.c | 21 -
drivers/char/ipmi/ipmi_msghandler.c | 2
drivers/firmware/efivars.c | 1
drivers/gpu/drm/drm_proc.c | 41 +--
drivers/gpu/drm/drm_stub.c | 2
drivers/media/pci/ttpci/av7110_ir.c | 2
drivers/media/pci/zoran/zoran_procfs.c | 2
drivers/message/i2o/i2o_proc.c | 8 -
drivers/misc/sgi-gru/gruprocfs.c | 2
drivers/mtd/mtdcore.c | 1
drivers/net/irda/vlsi_ir.c | 2
drivers/net/wireless/airo.c | 83 ++---
drivers/net/wireless/hostap/hostap_proc.c | 20 -
drivers/of/base.c | 11 -
drivers/pci/proc.c | 14 -
drivers/pps/clients/pps_parport.c | 1
drivers/scsi/megaraid.c | 6
drivers/staging/dgrp/dgrp_dpa_ops.c | 1
drivers/staging/dgrp/dgrp_mon_ops.c | 1
drivers/staging/dgrp/dgrp_net_ops.c | 2
drivers/staging/dgrp/dgrp_specproc.c | 83 ++---
drivers/staging/rtl8187se/r8180.h | 1
drivers/staging/rtl8187se/r8180_core.c | 28 +-
drivers/staging/rtl8192u/r8192U.h | 1
drivers/staging/rtl8192u/r8192U_core.c | 21 -
fs/namespace.c | 6
fs/proc/base.c | 14 +
fs/proc/fd.h | 5
fs/proc/generic.c | 71 +++--
fs/proc/inode.c | 9 -
fs/proc/internal.h | 346 +++++++++++++++-------
fs/proc/kcore.c | 2
fs/proc/namespaces.c | 17 +
fs/proc/proc_devtree.c | 2
fs/proc/proc_net.c | 4
fs/proc/self.c | 1
fs/proc/vmcore.c | 5
fs/reiserfs/procfs.c | 32 +-
include/drm/drmP.h | 5
include/linux/kcore.h | 38 ++
include/linux/of.h | 10 +
include/linux/proc_fs.h | 299 +++----------------
include/linux/proc_ns.h | 74 +++++
include/linux/signal.h | 5
include/linux/tty.h | 7
init/version.c | 2
ipc/msgutil.c | 2
ipc/namespace.c | 2
kernel/cgroup.c | 3
kernel/configs.c | 2
kernel/cpuset.c | 3
kernel/irq/proc.c | 6
kernel/nsproxy.c | 6
kernel/pid.c | 1
kernel/pid_namespace.c | 2
kernel/profile.c | 2
kernel/user.c | 2
kernel/user_namespace.c | 2
kernel/utsname.c | 2
net/8021q/vlanproc.c | 9 -
net/core/net_namespace.c | 7
net/core/pktgen.c | 6
net/ipv4/netfilter/ipt_CLUSTERIP.c | 4
net/ipv6/proc.c | 3
net/netfilter/xt_hashlimit.c | 6
net/netfilter/xt_recent.c | 3
sound/core/info.c | 21 -
78 files changed, 898 insertions(+), 994 deletions(-)
create mode 100644 include/linux/kcore.h
create mode 100644 include/linux/proc_ns.h


2013-04-16 18:26:05

by David Howells

[permalink] [raw]
Subject: [PATCH 02/28] Include missing linux/magic.h inclusions [RFC]

Include missing linux/magic.h inclusions where the source file is currently
expecting to get magic numbers through linux/proc_fs.h.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
---

drivers/firmware/efivars.c | 1 +
fs/proc/inode.c | 1 +
2 files changed, 2 insertions(+)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 7acafb8..0f102601 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -80,6 +80,7 @@
#include <linux/slab.h>
#include <linux/pstore.h>
#include <linux/ctype.h>
+#include <linux/magic.h>

#include <linux/fs.h>
#include <linux/ramfs.h>
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index d50224c..bd2f764 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -22,6 +22,7 @@
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/mount.h>
+#include <linux/magic.h>

#include <asm/uaccess.h>

2013-04-16 18:26:13

by David Howells

[permalink] [raw]
Subject: [PATCH 01/28] Include missing linux/slab.h inclusions [RFC]

Include missing linux/slab.h inclusions where the source file is currently
expecting to get kmalloc() and co. through linux/proc_fs.h.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
---

arch/s390/kernel/os_info.c | 1 +
arch/sparc/kernel/sun4d_irq.c | 1 +
arch/x86/platform/efi/efi.c | 1 +
arch/x86/platform/efi/efi_64.c | 1 +
drivers/mtd/mtdcore.c | 1 +
drivers/pps/clients/pps_parport.c | 1 +
drivers/staging/dgrp/dgrp_dpa_ops.c | 1 +
drivers/staging/dgrp/dgrp_mon_ops.c | 1 +
drivers/staging/dgrp/dgrp_net_ops.c | 2 +-
drivers/staging/dgrp/dgrp_specproc.c | 1 +
fs/proc/self.c | 1 +
11 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/s390/kernel/os_info.c b/arch/s390/kernel/os_info.c
index 46480d8..d112fc6 100644
--- a/arch/s390/kernel/os_info.c
+++ b/arch/s390/kernel/os_info.c
@@ -10,6 +10,7 @@

#include <linux/crash_dump.h>
#include <linux/kernel.h>
+#include <linux/slab.h>
#include <asm/checksum.h>
#include <asm/lowcore.h>
#include <asm/os_info.h>
diff --git a/arch/sparc/kernel/sun4d_irq.c b/arch/sparc/kernel/sun4d_irq.c
index e490ac9..f8933be 100644
--- a/arch/sparc/kernel/sun4d_irq.c
+++ b/arch/sparc/kernel/sun4d_irq.c
@@ -6,6 +6,7 @@
*/

#include <linux/kernel_stat.h>
+#include <linux/slab.h>
#include <linux/seq_file.h>

#include <asm/timer.h>
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 5f2ecaf..55ea7df 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -34,6 +34,7 @@
#include <linux/efi-bgrt.h>
#include <linux/export.h>
#include <linux/bootmem.h>
+#include <linux/slab.h>
#include <linux/memblock.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index 2b20038..39a0e7f 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -27,6 +27,7 @@
#include <linux/uaccess.h>
#include <linux/io.h>
#include <linux/reboot.h>
+#include <linux/slab.h>

#include <asm/setup.h>
#include <asm/page.h>
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 61d5f56..322ca65 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -36,6 +36,7 @@
#include <linux/idr.h>
#include <linux/backing-dev.h>
#include <linux/gfp.h>
+#include <linux/slab.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
diff --git a/drivers/pps/clients/pps_parport.c b/drivers/pps/clients/pps_parport.c
index e1b4705..38a8bbe 100644
--- a/drivers/pps/clients/pps_parport.c
+++ b/drivers/pps/clients/pps_parport.c
@@ -32,6 +32,7 @@
#include <linux/init.h>
#include <linux/irqnr.h>
#include <linux/time.h>
+#include <linux/slab.h>
#include <linux/parport.h>
#include <linux/pps_kernel.h>

diff --git a/drivers/staging/dgrp/dgrp_dpa_ops.c b/drivers/staging/dgrp/dgrp_dpa_ops.c
index 43209c1..1fc13de 100644
--- a/drivers/staging/dgrp/dgrp_dpa_ops.c
+++ b/drivers/staging/dgrp/dgrp_dpa_ops.c
@@ -40,6 +40,7 @@
#include <linux/cred.h>
#include <linux/sched.h>
#include <linux/ratelimit.h>
+#include <linux/slab.h>
#include <asm/unaligned.h>

#include "dgrp_common.h"
diff --git a/drivers/staging/dgrp/dgrp_mon_ops.c b/drivers/staging/dgrp/dgrp_mon_ops.c
index 6edbbf0..d18be41 100644
--- a/drivers/staging/dgrp/dgrp_mon_ops.c
+++ b/drivers/staging/dgrp/dgrp_mon_ops.c
@@ -37,6 +37,7 @@
#include <linux/tty.h>
#include <linux/sched.h>
#include <asm/unaligned.h>
+#include <linux/slab.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>

diff --git a/drivers/staging/dgrp/dgrp_net_ops.c b/drivers/staging/dgrp/dgrp_net_ops.c
index 5448fc7..9914f1c 100644
--- a/drivers/staging/dgrp/dgrp_net_ops.c
+++ b/drivers/staging/dgrp/dgrp_net_ops.c
@@ -35,7 +35,7 @@

#include <linux/module.h>
#include <linux/proc_fs.h>
-#include <linux/types.h>
+#include <linux/slab.h>
#include <linux/string.h>
#include <linux/device.h>
#include <linux/tty.h>
diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c
index b990b26..205d80e 100644
--- a/drivers/staging/dgrp/dgrp_specproc.c
+++ b/drivers/staging/dgrp/dgrp_specproc.c
@@ -37,6 +37,7 @@
#include <linux/sched.h>
#include <linux/cred.h>
#include <linux/proc_fs.h>
+#include <linux/slab.h>
#include <linux/ctype.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
diff --git a/fs/proc/self.c b/fs/proc/self.c
index 21940d8..6b6a993 100644
--- a/fs/proc/self.c
+++ b/fs/proc/self.c
@@ -1,5 +1,6 @@
#include <linux/sched.h>
#include <linux/namei.h>
+#include <linux/slab.h>
#include <linux/pid_namespace.h>
#include "internal.h"

2013-04-16 18:26:19

by David Howells

[permalink] [raw]
Subject: [PATCH 05/28] proc: Uninline pid_delete_dentry() [RFC]

Uninline pid_delete_dentry() as it's only used by three function pointers.

Signed-off-by: David Howells <[email protected]>
---

fs/proc/base.c | 9 +++++++++
fs/proc/internal.h | 14 +++++---------
2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 593e7c5..f2637c9 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1621,6 +1621,15 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
return 0;
}

+int pid_delete_dentry(const struct dentry *dentry)
+{
+ /* Is the task we represent dead?
+ * If so, then don't put the dentry on the lru list,
+ * kill it immediately.
+ */
+ return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
+}
+
const struct dentry_operations pid_dentry_operations =
{
.d_revalidate = pid_revalidate,
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 4b13417..aaf2dd8 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -114,15 +114,6 @@ static inline int task_dumpable(struct task_struct *task)
return 0;
}

-static inline int pid_delete_dentry(const struct dentry * dentry)
-{
- /* Is the task we represent dead?
- * If so, then don't put the dentry on the lru list,
- * kill it immediately.
- */
- return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
-}
-
static inline unsigned name_to_int(struct dentry *dentry)
{
const char *name = dentry->d_name.name;
@@ -145,6 +136,11 @@ out:
return ~0U;
}

+/*
+ * base.c
+ */
+extern int pid_delete_dentry(const struct dentry *);
+
struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *ino,
struct dentry *dentry);
int proc_readdir_de(struct proc_dir_entry *de, struct file *filp, void *dirent,

2013-04-16 18:26:31

by David Howells

[permalink] [raw]
Subject: [PATCH 08/28] proc: Move PDE_NET() to fs/proc/proc_net.c [RFC]

Move PDE_NET() to fs/proc/proc_net.c as that's where the only user is.

Signed-off-by: David Howells <[email protected]>
---

fs/proc/proc_net.c | 4 ++++
include/linux/proc_fs.h | 5 -----
2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
index b4ac657..986e832 100644
--- a/fs/proc/proc_net.c
+++ b/fs/proc/proc_net.c
@@ -26,6 +26,10 @@

#include "internal.h"

+static inline struct net *PDE_NET(struct proc_dir_entry *pde)
+{
+ return pde->parent->data;
+}

static struct net *get_proc_net(const struct inode *inode)
{
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 8f7d8f2..3377224 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -187,11 +187,6 @@ static inline void *PDE_DATA(const struct inode *inode)
return PROC_I(inode)->pde->data;
}

-static inline struct net *PDE_NET(struct proc_dir_entry *pde)
-{
- return pde->parent->data;
-}
-
#include <linux/signal.h>

void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);

2013-04-16 18:26:46

by David Howells

[permalink] [raw]
Subject: [PATCH 10/28] proc: Add proc_mkdir_data() [RFC]

Add proc_mkdir_data() to allow procfs directories to be created that are
annotated at the time of creation with private data rather than doing this
post-creation. This means no access is then required to the proc_dir_entry
struct to set this.

Signed-off-by: David Howells <[email protected]>
cc: Neela Syam Kolli <[email protected]>
cc: Jerry Chuang <[email protected]>
cc: Mauro Carvalho Chehab <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
---

drivers/message/i2o/i2o_proc.c | 8 ++------
drivers/scsi/megaraid.c | 4 ++--
drivers/staging/rtl8192u/r8192U_core.c | 3 +--
fs/proc/generic.c | 30 ++++++++++++------------------
include/linux/proc_fs.h | 11 ++++++++---
5 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
index 70a840f..b7d87cd 100644
--- a/drivers/message/i2o/i2o_proc.c
+++ b/drivers/message/i2o/i2o_proc.c
@@ -1913,14 +1913,12 @@ static void i2o_proc_device_add(struct proc_dir_entry *dir,

osm_debug("adding device /proc/i2o/%s/%s\n", dev->iop->name, buff);

- devdir = proc_mkdir(buff, dir);
+ devdir = proc_mkdir_data(buff, 0, dir, dev);
if (!devdir) {
osm_warn("Could not allocate procdir!\n");
return;
}

- devdir->data = dev;
-
i2o_proc_create_entries(devdir, generic_dev_entries, dev);

/* Inform core that we want updates about this device's status */
@@ -1954,12 +1952,10 @@ static int i2o_proc_iop_add(struct proc_dir_entry *dir,

osm_debug("adding IOP /proc/i2o/%s\n", c->name);

- iopdir = proc_mkdir(c->name, dir);
+ iopdir = proc_mkdir_data(c->name, 0, dir, c);
if (!iopdir)
return -1;

- iopdir->data = c;
-
i2o_proc_create_entries(iopdir, i2o_proc_generic_iop_entries, c);

list_for_each_entry(dev, &c->devices, list)
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index a1c90bd..ef3384d 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -2818,12 +2818,12 @@ mega_create_proc_entry(int index, struct proc_dir_entry *parent)

sprintf(string, "hba%d", adapter->host->host_no);

- dir = adapter->controller_proc_dir_entry = proc_mkdir(string, parent);
+ dir = adapter->controller_proc_dir_entry =
+ proc_mkdir_data(string, 0, parent, adapter);
if(!dir) {
printk(KERN_WARNING "\nmegaraid: proc_mkdir failed\n");
return;
}
- dir->data = adapter;

for (f = mega_proc_files; f->name; f++) {
de = proc_create_data(f->name, S_IRUSR, dir, &mega_proc_fops,
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 433c3df..d81d7d5 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -672,13 +672,12 @@ void rtl8192_proc_init_one(struct net_device *dev)
struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);

if (rtl8192_proc) {
- priv->dir_dev = proc_mkdir(dev->name, rtl8192_proc);
+ priv->dir_dev = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
if (!priv->dir_dev) {
RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
dev->name);
return;
}
- priv->dir_dev->data = dev;

for (f = rtl8192_proc_files; f->name[0]; f++) {
if (!proc_create_data(f->name, S_IFREG | S_IRUGO,
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 5f6f6c3..4074da5 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -428,13 +428,17 @@ struct proc_dir_entry *proc_symlink(const char *name,
}
EXPORT_SYMBOL(proc_symlink);

-struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
- struct proc_dir_entry *parent)
+struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
+ struct proc_dir_entry *parent, void *data)
{
struct proc_dir_entry *ent;

+ if (mode == 0)
+ mode = S_IRUGO | S_IXUGO;
+
ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
if (ent) {
+ ent->data = data;
if (proc_register(parent, ent) < 0) {
kfree(ent);
ent = NULL;
@@ -442,29 +446,19 @@ struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
}
return ent;
}
-EXPORT_SYMBOL(proc_mkdir_mode);
+EXPORT_SYMBOL_GPL(proc_mkdir_data);

-struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
- struct proc_dir_entry *parent)
+struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
+ struct proc_dir_entry *parent)
{
- struct proc_dir_entry *ent;
-
- ent = __proc_create(&parent, name, S_IFDIR | S_IRUGO | S_IXUGO, 2);
- if (ent) {
- ent->data = net;
- if (proc_register(parent, ent) < 0) {
- kfree(ent);
- ent = NULL;
- }
- }
- return ent;
+ return proc_mkdir_data(name, mode, parent, NULL);
}
-EXPORT_SYMBOL_GPL(proc_net_mkdir);
+EXPORT_SYMBOL(proc_mkdir_mode);

struct proc_dir_entry *proc_mkdir(const char *name,
struct proc_dir_entry *parent)
{
- return proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
+ return proc_mkdir_data(name, 0, parent, NULL);
}
EXPORT_SYMBOL(proc_mkdir);

diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 80d9e24..e5d8f69 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -73,6 +73,8 @@ extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
extern struct proc_dir_entry *proc_symlink(const char *,
struct proc_dir_entry *, const char *);
extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
+extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
+ struct proc_dir_entry *, void *);
extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
struct proc_dir_entry *parent);

@@ -82,9 +84,6 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
return proc_create_data(name, mode, parent, proc_fops, NULL);
}

-extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
- struct proc_dir_entry *parent);
-
extern void proc_set_size(struct proc_dir_entry *, loff_t);
extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
#else
@@ -153,4 +152,10 @@ static inline void *PDE_DATA(const struct inode *inode)
return PROC_I(inode)->pde->data;
}

+static inline struct proc_dir_entry *proc_net_mkdir(
+ struct net *net, const char *name, struct proc_dir_entry *parent)
+{
+ return proc_mkdir_data(name, 0, parent, net);
+}
+
#endif /* _LINUX_PROC_FS_H */

2013-04-16 18:26:56

by David Howells

[permalink] [raw]
Subject: [PATCH 15/28] reiserfs: Don't access the proc_dir_entry in r_open(), r_start() r_show() [RFC]

Don't access the proc_dir_entry in ReiserFS's r_open(), r_start() r_show()
procfs interface functions.

ReiserFS stores the ->show() method pointer in PDE->data and the super_block
pointer in PDE->parent->data. This isn't changing.

Currently, ReiserFS passes the PDE pointer into seq_file::private from
r_open() so that r_start() and r_show() can then access it. Instead, use
seq_open_private() to allocate a two-pointer struct that's passed through
seq_file::private and put the ->show() method and the sb pointers in there.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
---

fs/reiserfs/procfs.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
index 274adea..33532f7 100644
--- a/fs/reiserfs/procfs.c
+++ b/fs/reiserfs/procfs.c
@@ -394,20 +394,24 @@ static int set_sb(struct super_block *sb, void *data)
return -ENOENT;
}

+struct reiserfs_seq_private {
+ struct super_block *sb;
+ int (*show) (struct seq_file *, struct super_block *);
+};
+
static void *r_start(struct seq_file *m, loff_t * pos)
{
- struct proc_dir_entry *de = m->private;
- struct super_block *s = de->parent->data;
+ struct reiserfs_seq_private *priv = m->private;
loff_t l = *pos;

if (l)
return NULL;

- if (IS_ERR(sget(&reiserfs_fs_type, test_sb, set_sb, 0, s)))
+ if (IS_ERR(sget(&reiserfs_fs_type, test_sb, set_sb, 0, priv->sb)))
return NULL;

- up_write(&s->s_umount);
- return s;
+ up_write(&priv->sb->s_umount);
+ return priv->sb;
}

static void *r_next(struct seq_file *m, void *v, loff_t * pos)
@@ -426,9 +430,8 @@ static void r_stop(struct seq_file *m, void *v)

static int r_show(struct seq_file *m, void *v)
{
- struct proc_dir_entry *de = m->private;
- int (*show) (struct seq_file *, struct super_block *) = de->data;
- return show(m, v);
+ struct reiserfs_seq_private *priv = m->private;
+ return priv->show(m, v);
}

static const struct seq_operations r_ops = {
@@ -440,11 +443,15 @@ static const struct seq_operations r_ops = {

static int r_open(struct inode *inode, struct file *file)
{
- int ret = seq_open(file, &r_ops);
+ struct reiserfs_seq_private *priv;
+ int ret = seq_open_private(file, &r_ops,
+ sizeof(struct reiserfs_seq_private));

if (!ret) {
struct seq_file *m = file->private_data;
- m->private = PDE(inode);
+ priv = m->private;
+ priv->sb = proc_get_parent_data(inode);
+ priv->show = PDE_DATA(inode);
}
return ret;
}
@@ -453,7 +460,7 @@ static const struct file_operations r_file_operations = {
.open = r_open,
.read = seq_read,
.llseek = seq_lseek,
- .release = seq_release,
+ .release = seq_release_private,
.owner = THIS_MODULE,
};

@@ -479,9 +486,8 @@ int reiserfs_proc_info_init(struct super_block *sb)
*s = '!';

spin_lock_init(&__PINFO(sb).lock);
- REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root);
+ REISERFS_SB(sb)->procdir = proc_mkdir_data(b, 0, proc_info_root, sb);
if (REISERFS_SB(sb)->procdir) {
- REISERFS_SB(sb)->procdir->data = sb;
add_file(sb, "version", show_version);
add_file(sb, "super", show_super);
add_file(sb, "per-level", show_per_level);

2013-04-16 18:27:04

by David Howells

[permalink] [raw]
Subject: [PATCH 17/28] drm: Constify drm_proc_list[] [RFC]

Constify drm_proc_list[] and related pointers.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
---

drivers/gpu/drm/drm_proc.c | 6 +++---
include/drm/drmP.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_proc.c b/drivers/gpu/drm/drm_proc.c
index e064318..aead653 100644
--- a/drivers/gpu/drm/drm_proc.c
+++ b/drivers/gpu/drm/drm_proc.c
@@ -49,7 +49,7 @@
/**
* Proc file list.
*/
-static struct drm_info_list drm_proc_list[] = {
+static const struct drm_info_list drm_proc_list[] = {
{"name", drm_name_info, 0},
{"vm", drm_vm_info, 0},
{"clients", drm_clients_info, 0},
@@ -89,7 +89,7 @@ static const struct file_operations drm_proc_fops = {
* Create a given set of proc files represented by an array of
* gdm_proc_lists in the given root directory.
*/
-static int drm_proc_create_files(struct drm_info_list *files, int count,
+static int drm_proc_create_files(const struct drm_info_list *files, int count,
struct proc_dir_entry *root, struct drm_minor *minor)
{
struct drm_device *dev = minor->dev;
@@ -172,7 +172,7 @@ int drm_proc_init(struct drm_minor *minor, int minor_id,
return 0;
}

-static int drm_proc_remove_files(struct drm_info_list *files, int count,
+static int drm_proc_remove_files(const struct drm_info_list *files, int count,
struct drm_minor *minor)
{
struct list_head *pos, *q;
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 2d94d74..af53320 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1022,7 +1022,7 @@ struct drm_info_list {
struct drm_info_node {
struct list_head list;
struct drm_minor *minor;
- struct drm_info_list *info_ent;
+ const struct drm_info_list *info_ent;
struct dentry *dent;
};

2013-04-16 18:27:09

by David Howells

[permalink] [raw]
Subject: [PATCH 19/28] drm: proc: Use remove_proc_subtree() [RFC]

Use remove_proc_subtree() rather than remove_proc_entry() to remove a
minor-specific drm proc directory and all its children.

Things could theoretically be improved by storing the drm_minor pointer in the
minor-specific dir proc_dir_entry struct data and then scrapping the list of
proc files - but that's shared with the debugfs interface where you can't do
that, so I don't see an easy way of doing it.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
---

drivers/gpu/drm/drm_proc.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/drm_proc.c b/drivers/gpu/drm/drm_proc.c
index 0646a46..d7f2324 100644
--- a/drivers/gpu/drm/drm_proc.c
+++ b/drivers/gpu/drm/drm_proc.c
@@ -95,7 +95,7 @@ static int drm_proc_create_files(const struct drm_info_list *files, int count,
struct drm_device *dev = minor->dev;
struct proc_dir_entry *ent;
struct drm_info_node *tmp;
- int i, ret;
+ int i;

for (i = 0; i < count; i++) {
u32 features = files[i].driver_features;
@@ -105,10 +105,9 @@ static int drm_proc_create_files(const struct drm_info_list *files, int count,
continue;

tmp = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
- if (tmp == NULL) {
- ret = -1;
- goto fail;
- }
+ if (!tmp)
+ return -1;
+
tmp->minor = minor;
tmp->info_ent = &files[i];
list_add(&tmp->list, &minor->proc_nodes.list);
@@ -120,16 +119,10 @@ static int drm_proc_create_files(const struct drm_info_list *files, int count,
minor->index, files[i].name);
list_del(&tmp->list);
kfree(tmp);
- ret = -1;
- goto fail;
+ return -1;
}
}
return 0;
-
-fail:
- for (i = 0; i < count; i++)
- remove_proc_entry(drm_proc_list[i].name, minor->proc_root);
- return ret;
}

/**
@@ -160,7 +153,7 @@ int drm_proc_init(struct drm_minor *minor, struct proc_dir_entry *root)
ret = drm_proc_create_files(drm_proc_list, DRM_PROC_ENTRIES,
minor->proc_root, minor);
if (ret) {
- remove_proc_entry(name, root);
+ remove_proc_subtree(name, root);
minor->proc_root = NULL;
DRM_ERROR("Failed to create core drm proc files\n");
return ret;
@@ -210,8 +203,7 @@ int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root)
drm_proc_remove_files(drm_proc_list, DRM_PROC_ENTRIES, minor);

sprintf(name, "%d", minor->index);
- remove_proc_entry(name, root);
-
+ remove_proc_subtree(name, root);
return 0;
}

2013-04-16 18:27:18

by David Howells

[permalink] [raw]
Subject: [PATCH 09/28] proc: Move some bits from linux/proc_fs.h to linux/{of.h, signal.h, tty.h} [RFC]

Move some bits from linux/proc_fs.h to linux/of.h, signal.h and tty.h.

Also move proc_tty_init() and proc_device_tree_init() to fs/proc/internal.h as
they're internal to procfs.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
cc: [email protected]
cc: Greg Kroah-Hartman <[email protected]>
cc: Jri Slaby <[email protected]>
---

fs/proc/internal.h | 16 ++++++++++++++++
include/linux/of.h | 10 ++++++++++
include/linux/proc_fs.h | 37 -------------------------------------
include/linux/signal.h | 5 +++++
include/linux/tty.h | 7 +++++++
5 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 32d8f51..c529b5f 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -198,3 +198,19 @@ extern const struct inode_operations proc_ns_dir_inode_operations;
extern const struct file_operations proc_ns_dir_operations;

extern int proc_setup_self(struct super_block *);
+
+/*
+ * proc_devtree.c
+ */
+#ifdef CONFIG_PROC_DEVICETREE
+extern void proc_device_tree_init(void);
+#endif /* CONFIG_PROC_DEVICETREE */
+
+/*
+ * proc_tty.c
+ */
+#ifdef CONFIG_TTY
+extern void proc_tty_init(void);
+#else
+static inline void proc_tty_init(void) {}
+#endif
diff --git a/include/linux/of.h b/include/linux/of.h
index a0f1292..2d25ff8 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -540,4 +540,14 @@ static inline int of_property_read_u32(const struct device_node *np,
return of_property_read_u32_array(np, propname, out_value, 1);
}

+#if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE)
+extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
+extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
+extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
+ struct property *prop);
+extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
+ struct property *newprop,
+ struct property *oldprop);
+#endif
+
#endif /* _LINUX_OF_H */
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 3377224..80d9e24 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -70,36 +70,6 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);

-
-/*
- * proc_tty.c
- */
-struct tty_driver;
-#ifdef CONFIG_TTY
-extern void proc_tty_init(void);
-#else
-static inline void proc_tty_init(void)
-{ }
-#endif
-extern void proc_tty_register_driver(struct tty_driver *driver);
-extern void proc_tty_unregister_driver(struct tty_driver *driver);
-
-/*
- * proc_devtree.c
- */
-#ifdef CONFIG_PROC_DEVICETREE
-struct device_node;
-struct property;
-extern void proc_device_tree_init(void);
-extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
-extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
-extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
- struct property *prop);
-extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
- struct property *newprop,
- struct property *oldprop);
-#endif /* CONFIG_PROC_DEVICETREE */
-
extern struct proc_dir_entry *proc_symlink(const char *,
struct proc_dir_entry *, const char *);
extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
@@ -143,10 +113,6 @@ static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}

-struct tty_driver;
-static inline void proc_tty_register_driver(struct tty_driver *driver) {};
-static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
-
#endif /* CONFIG_PROC_FS */


@@ -187,7 +153,4 @@ static inline void *PDE_DATA(const struct inode *inode)
return PROC_I(inode)->pde->data;
}

-#include <linux/signal.h>
-
-void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
#endif /* _LINUX_PROC_FS_H */
diff --git a/include/linux/signal.h b/include/linux/signal.h
index a2dcb94..1135e36 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -434,4 +434,9 @@ void signals_init(void);
int restore_altstack(const stack_t __user *);
int __save_altstack(stack_t __user *, unsigned long);

+#ifdef CONFIG_PROC_FS
+struct seq_file;
+extern void render_sigset_t(struct seq_file *, const char *, sigset_t *);
+#endif
+
#endif /* _LINUX_SIGNAL_H */
diff --git a/include/linux/tty.h b/include/linux/tty.h
index c75d886..e34605b 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -658,5 +658,12 @@ do { \
finish_wait(&wq, &__wait); \
} while (0)

+#ifdef CONFIG_PROC_FS
+extern void proc_tty_register_driver(struct tty_driver *);
+extern void proc_tty_unregister_driver(struct tty_driver *);
+#else
+static inline void proc_tty_register_driver(struct tty_driver *) {}
+static inline void proc_tty_unregister_driver(struct tty_driver *) {}
+#endif

#endif

2013-04-16 18:27:26

by David Howells

[permalink] [raw]
Subject: [PATCH 20/28] hostap: proc: Use remove_proc_subtree() [RFC]

Use remove_proc_subtree() rather than remove_proc_entry() to remove a
device-specific proc directory and all its children.

Signed-off-by: David Howells <[email protected]>
cc: Jouni Malinen <[email protected]>
cc: Johannes Berg <[email protected]>
cc: [email protected]
cc: [email protected]
---

drivers/net/wireless/hostap/hostap_proc.c | 20 +-------------------
1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/drivers/net/wireless/hostap/hostap_proc.c b/drivers/net/wireless/hostap/hostap_proc.c
index 89292cf..7491dab 100644
--- a/drivers/net/wireless/hostap/hostap_proc.c
+++ b/drivers/net/wireless/hostap/hostap_proc.c
@@ -496,25 +496,7 @@ void hostap_init_proc(local_info_t *local)

void hostap_remove_proc(local_info_t *local)
{
- if (local->proc != NULL) {
-#ifndef PRISM2_NO_STATION_MODES
- remove_proc_entry("scan_results", local->proc);
-#endif /* PRISM2_NO_STATION_MODES */
-#ifdef PRISM2_IO_DEBUG
- remove_proc_entry("io_debug", local->proc);
-#endif /* PRISM2_IO_DEBUG */
- remove_proc_entry("pda", local->proc);
- remove_proc_entry("aux_dump", local->proc);
- remove_proc_entry("wds", local->proc);
- remove_proc_entry("stats", local->proc);
- remove_proc_entry("bss_list", local->proc);
- remove_proc_entry("crypt", local->proc);
-#ifndef PRISM2_NO_PROCFS_DEBUG
- remove_proc_entry("debug", local->proc);
-#endif /* PRISM2_NO_PROCFS_DEBUG */
- if (hostap_proc != NULL)
- remove_proc_entry(local->proc->name, hostap_proc);
- }
+ remove_proc_subtree(local->ddev->name, hostap_proc);
}


2013-04-16 18:27:37

by David Howells

[permalink] [raw]
Subject: [PATCH 24/28] proc: Supply an accessor to get the name in a proc_dir_entry struct [RFC]

Supply an accessor to get access to the name in a proc_dir_entry struct, just
returning a const pointer to it.

This is only needed by the xt_hashlimit netfilter module as that appears to
use the name in the pde to save a label in the xt_hashlimit_htable struct -
which will be a problem if CONFIG_PROC_FS=n.

Signed-off-by: David Howells <[email protected]>
cc: Harald Welte <[email protected]>
cc: Jan Engelhardt <[email protected]>
cc: [email protected]
---

fs/proc/generic.c | 6 ++++++
include/linux/proc_fs.h | 1 +
net/netfilter/xt_hashlimit.c | 2 +-
3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 75e08d3..2c6d6be 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -624,3 +624,9 @@ void *proc_get_parent_data(const struct inode *inode)
return de->parent->data;
}
EXPORT_SYMBOL_GPL(proc_get_parent_data);
+
+const char *get_proc_name(const struct proc_dir_entry *de)
+{
+ return de->name;
+}
+EXPORT_SYMBOL_GPL(get_proc_name);
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 12694ef..718e966 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -87,6 +87,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 *);
+extern const char *get_proc_name(const struct proc_dir_entry *);
#else

static inline void proc_flush_task(struct task_struct *task)
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index ebfad03..d2fd53b 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -344,7 +344,7 @@ static struct xt_hashlimit_htable *htable_find_get(struct net *net,
struct xt_hashlimit_htable *hinfo;

hlist_for_each_entry(hinfo, &hashlimit_net->htables, node) {
- if (!strcmp(name, hinfo->pde->name) &&
+ if (!strcmp(name, get_proc_name(hinfo->pde)) &&
hinfo->family == family) {
hinfo->use++;
return hinfo;

2013-04-16 18:27:31

by David Howells

[permalink] [raw]
Subject: [PATCH 23/28] ppc: Clean up scanlog [RFC]

Clean up the pseries scanlog driver's use of procfs:

(1) Don't need to save the proc_dir_entry pointer as we have the filename to
remove with.

(2) Save the scan log buffer pointer in a static variable (there is only one
of it) and don't save it in the PDE (which doesn't have a destructor).

Signed-off-by: David Howells <[email protected]>
cc: Benjamin Herrenschmidt <[email protected]>
cc: Paul Mackerras <[email protected]>
cc: [email protected]
---

arch/powerpc/platforms/pseries/scanlog.c | 29 +++++++++++------------------
1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/scanlog.c b/arch/powerpc/platforms/pseries/scanlog.c
index cc220d2..b502ab6 100644
--- a/arch/powerpc/platforms/pseries/scanlog.c
+++ b/arch/powerpc/platforms/pseries/scanlog.c
@@ -41,12 +41,12 @@


static unsigned int ibm_scan_log_dump; /* RTAS token */
-static struct proc_dir_entry *proc_ppc64_scan_log_dump; /* The proc file */
+static unsigned int *scanlog_buffer; /* The data buffer */

static ssize_t scanlog_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
- unsigned int *data = PDE_DATA(file_inode(file));
+ unsigned int *data = scanlog_buffer;
int status;
unsigned long len, off;
unsigned int wait_time;
@@ -134,7 +134,7 @@ static ssize_t scanlog_write(struct file * file, const char __user * buf,

static int scanlog_open(struct inode * inode, struct file * file)
{
- unsigned int *data = PDE_DATA(file_inode(file));
+ unsigned int *data = scanlog_buffer;

if (data[0] != 0) {
/* This imperfect test stops a second copy of the
@@ -150,10 +150,9 @@ static int scanlog_open(struct inode * inode, struct file * file)

static int scanlog_release(struct inode * inode, struct file * file)
{
- unsigned int *data = PDE_DATA(file_inode(file));
+ unsigned int *data = scanlog_buffer;

data[0] = 0;
-
return 0;
}

@@ -169,7 +168,6 @@ const struct file_operations scanlog_fops = {
static int __init scanlog_init(void)
{
struct proc_dir_entry *ent;
- void *data;
int err = -ENOMEM;

ibm_scan_log_dump = rtas_token("ibm,scan-log-dump");
@@ -177,29 +175,24 @@ static int __init scanlog_init(void)
return -ENODEV;

/* Ideally we could allocate a buffer < 4G */
- data = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
- if (!data)
+ scanlog_buffer = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
+ if (!scanlog_buffer)
goto err;

- ent = proc_create_data("powerpc/rtas/scan-log-dump", S_IRUSR, NULL,
- &scanlog_fops, data);
+ ent = proc_create("powerpc/rtas/scan-log-dump", S_IRUSR, NULL,
+ &scanlog_fops);
if (!ent)
goto err;
-
- proc_ppc64_scan_log_dump = ent;
-
return 0;
err:
- kfree(data);
+ kfree(scanlog_buffer);
return err;
}

static void __exit scanlog_cleanup(void)
{
- if (proc_ppc64_scan_log_dump) {
- kfree(proc_ppc64_scan_log_dump->data);
- remove_proc_entry("scan-log-dump", proc_ppc64_scan_log_dump->parent);
- }
+ remove_proc_entry("powerpc/rtas/scan-log-dump", NULL);
+ kfree(scanlog_buffer);
}

module_init(scanlog_init);

2013-04-16 18:27:42

by David Howells

[permalink] [raw]
Subject: [PATCH 25/28] proc: Supply an accessor to get the process ID associated with some proc files [RFC]

Supply an accessor to get the process ID associated with some proc files and
directories (get_proc_pid()).

Signed-off-by: David Howells <[email protected]>
cc: Tejun Heo <[email protected]>
cc: Li Zefan <[email protected]>
cc: [email protected]
cc: [email protected]
---

fs/proc/base.c | 5 +++++
include/linux/proc_fs.h | 2 ++
kernel/cgroup.c | 3 +--
kernel/cpuset.c | 3 +--
4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index f2637c9..9ea16c8 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -157,6 +157,11 @@ static unsigned int pid_entry_count_dirs(const struct pid_entry *entries,
return count;
}

+struct pid *get_proc_pid(const struct inode *inode)
+{
+ return PROC_I(inode)->pid;
+}
+
static int get_task_root(struct task_struct *task, struct path *root)
{
int result = -ENOENT;
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 718e966..7abc72a 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -88,6 +88,7 @@ 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 *);
extern const char *get_proc_name(const struct proc_dir_entry *);
+extern struct pid *get_proc_pid(const struct inode *);
#else

static inline void proc_flush_task(struct task_struct *task)
@@ -113,6 +114,7 @@ static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
umode_t mode, struct proc_dir_entry *parent) { return NULL; }
static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
+static inline struct pid *get_proc_pid(const struct inode *inode) { return NULL; }

#endif /* CONFIG_PROC_FS */

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index a32f943..021548a 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4823,8 +4823,7 @@ out:

static int cgroup_open(struct inode *inode, struct file *file)
{
- struct pid *pid = PROC_I(inode)->pid;
- return single_open(file, proc_cgroup_show, pid);
+ return single_open(file, proc_cgroup_show, get_proc_pid(inode));
}

const struct file_operations proc_cgroup_operations = {
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 4f9dfe4..0ec6edd 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -2703,8 +2703,7 @@ out:

static int cpuset_open(struct inode *inode, struct file *file)
{
- struct pid *pid = PROC_I(inode)->pid;
- return single_open(file, proc_cpuset_show, pid);
+ return single_open(file, proc_cpuset_show, get_proc_pid(inode));
}

const struct file_operations proc_cpuset_operations = {

2013-04-16 18:27:48

by David Howells

[permalink] [raw]
Subject: [PATCH 28/28] proc: Move non-public stuff from linux/proc_fs.h to fs/proc/internal.h [RFC]

Move non-public declarations and definitions from linux/proc_fs.h to
fs/proc/internal.h.

Signed-off-by: David Howells <[email protected]>
---

fs/proc/internal.h | 307 ++++++++++++++++++++++++++++++-----------------
fs/proc/kcore.c | 1
include/linux/proc_fs.h | 151 ++++++-----------------
3 files changed, 236 insertions(+), 223 deletions(-)

diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 86a2406..04255b6 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -1,4 +1,4 @@
-/* internal.h: internal procfs definitions
+/* Internal procfs definitions
*
* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
* Written by David Howells ([email protected])
@@ -9,81 +9,66 @@
* 2 of the License, or (at your option) any later version.
*/

-#include <linux/sched.h>
#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
+#include <linux/spinlock.h>
+#include <linux/atomic.h>
#include <linux/binfmts.h>
-struct ctl_table_header;
-struct mempolicy;

-extern struct proc_dir_entry proc_root;
-extern void proc_self_init(void);
-#ifdef CONFIG_PROC_SYSCTL
-extern int proc_sys_init(void);
-extern void sysctl_head_put(struct ctl_table_header *head);
-#else
-static inline void proc_sys_init(void) { }
-static inline void sysctl_head_put(struct ctl_table_header *head) { }
-#endif
-#ifdef CONFIG_NET
-extern int proc_net_init(void);
-#else
-static inline int proc_net_init(void) { return 0; }
-#endif
+struct ctl_table_header;
+struct mempolicy;

-struct vmalloc_info {
- unsigned long used;
- unsigned long largest_chunk;
+/*
+ * This is not completely implemented yet. The idea is to
+ * create an in-memory tree (like the actual /proc filesystem
+ * tree) of these proc_dir_entries, so that we can dynamically
+ * add new files to /proc.
+ *
+ * The "next" pointer creates a linked list of one /proc directory,
+ * while parent/subdir create the directory structure (every
+ * /proc file has a parent, but "subdir" is NULL for all
+ * non-directory entries).
+ */
+struct proc_dir_entry {
+ unsigned int low_ino;
+ umode_t mode;
+ nlink_t nlink;
+ kuid_t uid;
+ kgid_t gid;
+ loff_t size;
+ const struct inode_operations *proc_iops;
+ const struct file_operations *proc_fops;
+ struct proc_dir_entry *next, *parent, *subdir;
+ void *data;
+ atomic_t count; /* use count */
+ atomic_t in_use; /* number of callers into module in progress; */
+ /* negative -> it's going away RSN */
+ struct completion *pde_unload_completion;
+ struct list_head pde_openers; /* who did ->open, but not ->release */
+ spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
+ u8 namelen;
+ char name[];
};

-#ifdef CONFIG_MMU
-#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
-extern void get_vmalloc_info(struct vmalloc_info *vmi);
-#else
-
-#define VMALLOC_TOTAL 0UL
-#define get_vmalloc_info(vmi) \
-do { \
- (vmi)->used = 0; \
- (vmi)->largest_chunk = 0; \
-} while(0)
-#endif
-
-extern int proc_tid_stat(struct seq_file *m, struct pid_namespace *ns,
- struct pid *pid, struct task_struct *task);
-extern int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
- struct pid *pid, struct task_struct *task);
-extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
- struct pid *pid, struct task_struct *task);
-extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
- struct pid *pid, struct task_struct *task);
-extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
-
-extern const struct file_operations proc_tid_children_operations;
-extern const struct file_operations proc_pid_maps_operations;
-extern const struct file_operations proc_tid_maps_operations;
-extern const struct file_operations proc_pid_numa_maps_operations;
-extern const struct file_operations proc_tid_numa_maps_operations;
-extern const struct file_operations proc_pid_smaps_operations;
-extern const struct file_operations proc_tid_smaps_operations;
-extern const struct file_operations proc_clear_refs_operations;
-extern const struct file_operations proc_pagemap_operations;
-extern const struct file_operations proc_net_operations;
-extern const struct inode_operations proc_net_inode_operations;
-extern const struct inode_operations proc_pid_link_inode_operations;
+union proc_op {
+ int (*proc_get_link)(struct dentry *, struct path *);
+ int (*proc_read)(struct task_struct *task, char *page);
+ int (*proc_show)(struct seq_file *m,
+ struct pid_namespace *ns, struct pid *pid,
+ struct task_struct *task);
+};

-struct proc_maps_private {
+struct proc_inode {
struct pid *pid;
- struct task_struct *task;
-#ifdef CONFIG_MMU
- struct vm_area_struct *tail_vma;
-#endif
-#ifdef CONFIG_NUMA
- struct mempolicy *task_mempolicy;
-#endif
+ int fd;
+ union proc_op op;
+ struct proc_dir_entry *pde;
+ struct ctl_table_header *sysctl;
+ struct ctl_table *sysctl_entry;
+ struct proc_ns ns;
+ struct inode vfs_inode;
};

-void proc_init_inodecache(void);
-
/*
* General functions
*/
@@ -150,79 +135,142 @@ out:
}

/*
- * base.c
+ * Offset of the first process in the /proc root directory..
*/
-extern int pid_delete_dentry(const struct dentry *);
+#define FIRST_PROCESS_ENTRY 256

-struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *ino,
- struct dentry *dentry);
-int proc_readdir_de(struct proc_dir_entry *de, struct file *filp, void *dirent,
- filldir_t filldir);
+/* Worst case buffer size needed for holding an integer. */
+#define PROC_NUMBUF 13

-struct pde_opener {
- struct file *file;
- struct list_head lh;
- int closing;
- struct completion *c;
-};
+/*
+ * array.c
+ */
+extern const struct file_operations proc_tid_children_operations;
+
+extern int proc_tid_stat(struct seq_file *, struct pid_namespace *,
+ struct pid *, struct task_struct *);
+extern int proc_tgid_stat(struct seq_file *, struct pid_namespace *,
+ struct pid *, struct task_struct *);
+extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
+ struct pid *, struct task_struct *);
+extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
+ struct pid *, struct task_struct *);
+
+/*
+ * base.c
+ */
+extern const struct dentry_operations pid_dentry_operations;
+extern int pid_getattr(struct vfsmount *, struct dentry *, struct kstat *);
+extern int proc_setattr(struct dentry *, struct iattr *);
+extern struct inode *proc_pid_make_inode(struct super_block *, struct task_struct *);
+extern int pid_revalidate(struct dentry *, unsigned int);
+extern int pid_delete_dentry(const struct dentry *);
+extern int proc_pid_readdir(struct file *, void *, filldir_t);
+extern struct dentry *proc_pid_lookup(struct inode *, struct dentry *, unsigned int);
+extern loff_t mem_lseek(struct file *, loff_t, int);

-void proc_entry_rundown(struct proc_dir_entry *);
+/* Lookups */
+typedef struct dentry *instantiate_t(struct inode *, struct dentry *,
+ struct task_struct *, const void *);
+extern int proc_fill_cache(struct file *, void *, filldir_t, const char *, int,
+ instantiate_t, struct task_struct *, const void *);

+/*
+ * generic.c
+ */
extern spinlock_t proc_subdir_lock;

-struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int);
-int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
-unsigned long task_vsize(struct mm_struct *);
-unsigned long task_statm(struct mm_struct *,
- unsigned long *, unsigned long *, unsigned long *, unsigned long *);
-void task_mem(struct seq_file *, struct mm_struct *);
+extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
+extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
+ struct dentry *);
+extern int proc_readdir(struct file *, void *, filldir_t);
+extern int proc_readdir_de(struct proc_dir_entry *, struct file *, void *, filldir_t);

static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
{
atomic_inc(&pde->count);
return pde;
}
-void pde_put(struct proc_dir_entry *pde);
+extern void pde_put(struct proc_dir_entry *);
+
+/*
+ * inode.c
+ */
+struct pde_opener {
+ struct file *file;
+ struct list_head lh;
+ int closing;
+ struct completion *c;
+};

-int proc_fill_super(struct super_block *);
-struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
-int proc_remount(struct super_block *sb, int *flags, char *data);
+extern const struct inode_operations proc_pid_link_inode_operations;
+
+extern void proc_init_inodecache(void);
+extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
+extern int proc_fill_super(struct super_block *);
+extern void proc_entry_rundown(struct proc_dir_entry *);

/*
- * These are generic /proc routines that use the internal
- * "struct proc_dir_entry" tree to traverse the filesystem.
- *
- * The /proc root directory has extended versions to take care
- * of the /proc/<pid> subdirectories.
+ * mmu.c
*/
-int proc_readdir(struct file *, void *, filldir_t);
-struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
+struct vmalloc_info {
+ unsigned long used;
+ unsigned long largest_chunk;
+};

+#ifdef CONFIG_MMU
+#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
+extern void get_vmalloc_info(struct vmalloc_info *);

+#else
+#define VMALLOC_TOTAL 0UL
+static inline void get_vmalloc_info(struct vmalloc_info *vmi)
+{
+ vmi->used = 0;
+ vmi->largest_chunk = 0;
+}
+#endif

-/* Lookups */
-typedef struct dentry *instantiate_t(struct inode *, struct dentry *,
- struct task_struct *, const void *);
-int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
- const char *name, int len,
- instantiate_t instantiate, struct task_struct *task, const void *ptr);
-int pid_revalidate(struct dentry *dentry, unsigned int flags);
-struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *task);
-extern const struct dentry_operations pid_dentry_operations;
-int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
-int proc_setattr(struct dentry *dentry, struct iattr *attr);
+/*
+ * proc_devtree.c
+ */
+#ifdef CONFIG_PROC_DEVICETREE
+extern void proc_device_tree_init(void);
+#endif

+/*
+ * proc_namespaces.c
+ */
extern const struct inode_operations proc_ns_dir_inode_operations;
extern const struct file_operations proc_ns_dir_operations;

+/*
+ * proc_net.c
+ */
+extern const struct file_operations proc_net_operations;
+extern const struct inode_operations proc_net_inode_operations;
+
+#ifdef CONFIG_NET
+extern int proc_net_init(void);
+#else
+static inline int proc_net_init(void) { return 0; }
+#endif
+
+/*
+ * proc_self.c
+ */
extern int proc_setup_self(struct super_block *);

/*
- * proc_devtree.c
+ * proc_sysctl.c
*/
-#ifdef CONFIG_PROC_DEVICETREE
-extern void proc_device_tree_init(void);
-#endif /* CONFIG_PROC_DEVICETREE */
+#ifdef CONFIG_PROC_SYSCTL
+extern int proc_sys_init(void);
+extern void sysctl_head_put(struct ctl_table_header *);
+#else
+static inline void proc_sys_init(void) { }
+static inline void sysctl_head_put(struct ctl_table_header *head) { }
+#endif

/*
* proc_tty.c
@@ -232,3 +280,40 @@ extern void proc_tty_init(void);
#else
static inline void proc_tty_init(void) {}
#endif
+
+/*
+ * root.c
+ */
+extern struct proc_dir_entry proc_root;
+
+extern void proc_self_init(void);
+extern int proc_remount(struct super_block *, int *, char *);
+
+/*
+ * task_[no]mmu.c
+ */
+struct proc_maps_private {
+ struct pid *pid;
+ struct task_struct *task;
+#ifdef CONFIG_MMU
+ struct vm_area_struct *tail_vma;
+#endif
+#ifdef CONFIG_NUMA
+ struct mempolicy *task_mempolicy;
+#endif
+};
+
+extern const struct file_operations proc_pid_maps_operations;
+extern const struct file_operations proc_tid_maps_operations;
+extern const struct file_operations proc_pid_numa_maps_operations;
+extern const struct file_operations proc_tid_numa_maps_operations;
+extern const struct file_operations proc_pid_smaps_operations;
+extern const struct file_operations proc_tid_smaps_operations;
+extern const struct file_operations proc_clear_refs_operations;
+extern const struct file_operations proc_pagemap_operations;
+
+extern unsigned long task_vsize(struct mm_struct *);
+extern unsigned long task_statm(struct mm_struct *,
+ unsigned long *, unsigned long *,
+ unsigned long *, unsigned long *);
+extern void task_mem(struct seq_file *, struct mm_struct *);
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 8e6ce83..13cf87c 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -28,6 +28,7 @@
#include <linux/ioport.h>
#include <linux/memory.h>
#include <asm/sections.h>
+#include "internal.h"

#define CORE_STR "CORE"

diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 96ede28..05740da 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -1,149 +1,69 @@
-#ifndef _LINUX_PROC_FS_H
-#define _LINUX_PROC_FS_H
-
-#include <linux/slab.h>
-#include <linux/fs.h>
-#include <linux/spinlock.h>
-#include <linux/magic.h>
-#include <linux/atomic.h>
-#include <linux/proc_ns.h>
-
-struct net;
-struct completion;
-struct mm_struct;
-
/*
* The proc filesystem constants/structures
*/
+#ifndef _LINUX_PROC_FS_H
+#define _LINUX_PROC_FS_H

-/*
- * Offset of the first process in the /proc root directory..
- */
-#define FIRST_PROCESS_ENTRY 256
-
-/* Worst case buffer size needed for holding an integer. */
-#define PROC_NUMBUF 13
-
-/*
- * This is not completely implemented yet. The idea is to
- * create an in-memory tree (like the actual /proc filesystem
- * tree) of these proc_dir_entries, so that we can dynamically
- * add new files to /proc.
- *
- * The "next" pointer creates a linked list of one /proc directory,
- * while parent/subdir create the directory structure (every
- * /proc file has a parent, but "subdir" is NULL for all
- * non-directory entries).
- */
+#include <linux/types.h>
+#include <linux/fs.h>

-struct proc_dir_entry {
- unsigned int low_ino;
- umode_t mode;
- nlink_t nlink;
- kuid_t uid;
- kgid_t gid;
- loff_t size;
- const struct inode_operations *proc_iops;
- const struct file_operations *proc_fops;
- struct proc_dir_entry *next, *parent, *subdir;
- void *data;
- atomic_t count; /* use count */
- atomic_t in_use; /* number of callers into module in progress; */
- /* negative -> it's going away RSN */
- struct completion *pde_unload_completion;
- struct list_head pde_openers; /* who did ->open, but not ->release */
- spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
- u8 namelen;
- char name[];
-};
+struct proc_dir_entry;

#ifdef CONFIG_PROC_FS

extern void proc_root_init(void);
-
-void proc_flush_task(struct task_struct *task);
-
-struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
- struct proc_dir_entry *parent,
- const struct file_operations *proc_fops,
- void *data);
-extern void proc_remove(struct proc_dir_entry *);
-extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
-extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
+extern void proc_flush_task(struct task_struct *);

extern struct proc_dir_entry *proc_symlink(const char *,
struct proc_dir_entry *, const char *);
-extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
+extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
struct proc_dir_entry *, void *);
-extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
- struct proc_dir_entry *parent);
-
-static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
- struct proc_dir_entry *parent, const struct file_operations *proc_fops)
-{
- return proc_create_data(name, mode, parent, proc_fops, NULL);
-}
+extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
+ struct proc_dir_entry *);

+extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
+ struct proc_dir_entry *,
+ const struct file_operations *,
+ void *);
+
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 *PDE_DATA(const struct inode *);
-extern void *proc_get_parent_data(const struct inode *);
-extern const char *get_proc_name(const struct proc_dir_entry *);
extern struct pid *get_proc_pid(const struct inode *);
-#else
-
-static inline void proc_flush_task(struct task_struct *task)
-{
-}
+extern const char *get_proc_name(const struct proc_dir_entry *);
+extern void *proc_get_parent_data(const struct inode *);

-#define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
+extern void proc_remove(struct proc_dir_entry *);
+extern void remove_proc_entry(const char *, struct proc_dir_entry *);
+extern int remove_proc_subtree(const char *, struct proc_dir_entry *);

-static inline struct proc_dir_entry *proc_create_data(const char *name,
- umode_t mode, struct proc_dir_entry *parent,
- const struct file_operations *proc_fops, void *data)
-{
- return NULL;
-}
-static inline void proc_remove(struct proc_dir_entry *de) {}
-#define remove_proc_entry(name, parent) do {} while (0)
-#define remove_proc_subtree(name, parent) do {} while (0)
+#else /* CONFIG_PROC_FS */

static inline struct proc_dir_entry *proc_symlink(const char *name,
- struct proc_dir_entry *parent,const char *dest) {return NULL;}
+ struct proc_dir_entry *parent,const char *dest) { return NULL;}
static inline struct proc_dir_entry *proc_mkdir(const char *name,
struct proc_dir_entry *parent) {return NULL;}
static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
umode_t mode, struct proc_dir_entry *parent) { return NULL; }
+
static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
static inline void *PDE_DATA(const struct inode *inode) { return NULL; }
static inline struct pid *get_proc_pid(const struct inode *inode) { return NULL; }
+extern const char *get_proc_name(const struct proc_dir_entry *de) { return ""; }
+extern void *proc_get_parent_data(const struct inode *) { return NULL; }

-#endif /* CONFIG_PROC_FS */
+static inline struct proc_dir_entry *proc_create_data(const char *name,
+ umode_t mode, struct proc_dir_entry *parent,
+ const struct file_operations *proc_fops, void *data) { return NULL; }
+static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}

+static inline void proc_remove(struct proc_dir_entry *de) {}
+static inline void remove_proc_entry(const char *name, struct proc_dir_entry *parent) {}
+static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }

-union proc_op {
- int (*proc_get_link)(struct dentry *, struct path *);
- int (*proc_read)(struct task_struct *task, char *page);
- int (*proc_show)(struct seq_file *m,
- struct pid_namespace *ns, struct pid *pid,
- struct task_struct *task);
-};
-
-struct ctl_table_header;
-struct ctl_table;
-
-struct proc_inode {
- struct pid *pid;
- int fd;
- union proc_op op;
- struct proc_dir_entry *pde;
- struct ctl_table_header *sysctl;
- struct ctl_table *sysctl_entry;
- struct proc_ns ns;
- struct inode vfs_inode;
-};
+#endif /* CONFIG_PROC_FS */

static inline struct proc_dir_entry *proc_net_mkdir(
struct net *net, const char *name, struct proc_dir_entry *parent)
@@ -151,4 +71,11 @@ static inline struct proc_dir_entry *proc_net_mkdir(
return proc_mkdir_data(name, 0, parent, net);
}

+static inline struct proc_dir_entry *proc_create(
+ const char *name, umode_t mode, struct proc_dir_entry *parent,
+ const struct file_operations *proc_fops)
+{
+ return proc_create_data(name, mode, parent, proc_fops, NULL);
+}
+
#endif /* _LINUX_PROC_FS_H */

2013-04-16 18:27:54

by David Howells

[permalink] [raw]
Subject: [PATCH 26/28] proc: Supply a function to remove a proc entry by PDE [RFC]

Supply a function (proc_remove()) to remove a proc entry (and any subtree
rooted there) by proc_dir_entry pointer rather than by name and (optionally)
root dir entry pointer. This allows us to eliminate all remaining pde->name
accesses outside of procfs.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
---

drivers/acpi/sbs.c | 21 ++++-----------------
drivers/char/ipmi/ipmi_msghandler.c | 2 +-
drivers/misc/sgi-gru/gruprocfs.c | 2 +-
drivers/of/base.c | 11 +----------
drivers/pci/proc.c | 12 +++---------
fs/proc/generic.c | 7 +++++++
fs/proc/vmcore.c | 2 +-
include/linux/proc_fs.h | 2 ++
kernel/irq/proc.c | 6 +-----
net/8021q/vlanproc.c | 9 ++-------
net/core/pktgen.c | 6 ++----
net/ipv4/netfilter/ipt_CLUSTERIP.c | 4 ++--
net/ipv6/proc.c | 3 +--
net/netfilter/xt_hashlimit.c | 4 ++--
sound/core/info.c | 19 +++++--------------
15 files changed, 35 insertions(+), 75 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index a296e08..b6241ee 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -521,19 +521,6 @@ acpi_sbs_add_fs(struct proc_dir_entry **dir,
return 0;
}

-static void
-acpi_sbs_remove_fs(struct proc_dir_entry **dir,
- struct proc_dir_entry *parent_dir)
-{
- if (*dir) {
- remove_proc_entry(ACPI_SBS_FILE_INFO, *dir);
- remove_proc_entry(ACPI_SBS_FILE_STATE, *dir);
- remove_proc_entry(ACPI_SBS_FILE_ALARM, *dir);
- remove_proc_entry((*dir)->name, parent_dir);
- *dir = NULL;
- }
-}
-
/* Smart Battery Interface */
static struct proc_dir_entry *acpi_battery_dir = NULL;

@@ -836,8 +823,8 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
power_supply_unregister(&battery->bat);
}
#ifdef CONFIG_ACPI_PROCFS_POWER
- if (battery->proc_entry)
- acpi_sbs_remove_fs(&battery->proc_entry, acpi_battery_dir);
+ proc_remove(battery->proc_entry);
+ battery->proc_entry = NULL;
#endif
}

@@ -873,8 +860,8 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
if (sbs->charger.dev)
power_supply_unregister(&sbs->charger);
#ifdef CONFIG_ACPI_PROCFS_POWER
- if (sbs->charger_entry)
- acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir);
+ proc_remove(sbs->charger_entry);
+ sbs->charger_entry = NULL;
#endif
}

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 1420bbb..4d439d2 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -4541,7 +4541,7 @@ static void __exit cleanup_ipmi(void)
del_timer_sync(&ipmi_timer);

#ifdef CONFIG_PROC_FS
- remove_proc_entry(proc_ipmi_root->name, NULL);
+ proc_remove(proc_ipmi_root);
#endif /* CONFIG_PROC_FS */

driver_unregister(&ipmidriver.driver);
diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
index 950dbe9..797d796 100644
--- a/drivers/misc/sgi-gru/gruprocfs.c
+++ b/drivers/misc/sgi-gru/gruprocfs.c
@@ -355,7 +355,7 @@ static void delete_proc_files(void)
for (p = proc_files; p->name; p++)
if (p->entry)
remove_proc_entry(p->name, proc_gru);
- remove_proc_entry("gru", proc_gru->parent);
+ proc_remove(proc_gru);
}
}

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 321d3ef..9c70436 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1452,16 +1452,7 @@ int of_attach_node(struct device_node *np)
#ifdef CONFIG_PROC_DEVICETREE
static void of_remove_proc_dt_entry(struct device_node *dn)
{
- struct device_node *parent = dn->parent;
- struct property *prop = dn->properties;
-
- while (prop) {
- remove_proc_entry(prop->name, dn->pde);
- prop = prop->next;
- }
-
- if (dn->pde)
- remove_proc_entry(dn->pde->name, parent->pde);
+ proc_remove(dn->pde);
}
#else
static void of_remove_proc_dt_entry(struct device_node *dn)
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 7cde7c1..0812608 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -427,20 +427,14 @@ int pci_proc_attach_device(struct pci_dev *dev)

int pci_proc_detach_device(struct pci_dev *dev)
{
- struct proc_dir_entry *e;
-
- if ((e = dev->procent)) {
- remove_proc_entry(e->name, dev->bus->procdir);
- dev->procent = NULL;
- }
+ proc_remove(dev->procent);
+ dev->procent = NULL;
return 0;
}

int pci_proc_detach_bus(struct pci_bus* bus)
{
- struct proc_dir_entry *de = bus->procdir;
- if (de)
- remove_proc_entry(de->name, proc_bus_pci_dir);
+ proc_remove(bus->procdir);
return 0;
}

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 2c6d6be..4b48033 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -630,3 +630,10 @@ const char *get_proc_name(const struct proc_dir_entry *de)
return de->name;
}
EXPORT_SYMBOL_GPL(get_proc_name);
+
+void proc_remove(struct proc_dir_entry *de)
+{
+ if (de)
+ remove_proc_subtree(de->name, de->parent);
+}
+EXPORT_SYMBOL(proc_remove);
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 38edddc..17f7e08 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -699,7 +699,7 @@ void vmcore_cleanup(void)
struct list_head *pos, *next;

if (proc_vmcore) {
- remove_proc_entry(proc_vmcore->name, proc_vmcore->parent);
+ proc_remove(proc_vmcore);
proc_vmcore = NULL;
}

diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 7abc72a..b8949b1 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -67,6 +67,7 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
struct proc_dir_entry *parent,
const struct file_operations *proc_fops,
void *data);
+extern void proc_remove(struct proc_dir_entry *);
extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);

@@ -103,6 +104,7 @@ static inline struct proc_dir_entry *proc_create_data(const char *name,
{
return NULL;
}
+static inline void proc_remove(struct proc_dir_entry *de) {}
#define remove_proc_entry(name, parent) do {} while (0)
#define remove_proc_subtree(name, parent) do {} while (0)

diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
index d59ae37..19ed5c4 100644
--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -366,11 +366,7 @@ void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)

void unregister_handler_proc(unsigned int irq, struct irqaction *action)
{
- if (action->dir) {
- struct irq_desc *desc = irq_to_desc(irq);
-
- remove_proc_entry(action->dir->name, desc->dir);
- }
+ proc_remove(action->dir);
}

static void register_default_affinity_proc(void)
diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
index 959ddbb..1d0e8921 100644
--- a/net/8021q/vlanproc.c
+++ b/net/8021q/vlanproc.c
@@ -184,14 +184,9 @@ int vlan_proc_add_dev(struct net_device *vlandev)
*/
int vlan_proc_rem_dev(struct net_device *vlandev)
{
- struct vlan_net *vn = net_generic(dev_net(vlandev), vlan_net_id);
-
/** NOTE: This will consume the memory pointed to by dent, it seems. */
- if (vlan_dev_priv(vlandev)->dent) {
- remove_proc_entry(vlan_dev_priv(vlandev)->dent->name,
- vn->proc_vlan_dir);
- vlan_dev_priv(vlandev)->dent = NULL;
- }
+ proc_remove(vlan_dev_priv(vlandev)->dent);
+ vlan_dev_priv(vlandev)->dent = NULL;
return 0;
}

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index f6af4fe..6c41e97 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1904,7 +1904,7 @@ static void pktgen_change_name(const struct pktgen_net *pn, struct net_device *d
if (pkt_dev->odev != dev)
continue;

- remove_proc_entry(pkt_dev->entry->name, pn->proc_dir);
+ proc_remove(pkt_dev->entry);

pkt_dev->entry = proc_create_data(dev->name, 0600,
pn->proc_dir,
@@ -3576,8 +3576,6 @@ static void _rem_dev_from_if_list(struct pktgen_thread *t,
static int pktgen_remove_device(struct pktgen_thread *t,
struct pktgen_dev *pkt_dev)
{
- struct pktgen_net *pn = t->net;
-
pr_debug("remove_device pkt_dev=%p\n", pkt_dev);

if (pkt_dev->running) {
@@ -3597,7 +3595,7 @@ static int pktgen_remove_device(struct pktgen_thread *t,
_rem_dev_from_if_list(t, pkt_dev);

if (pkt_dev->entry)
- remove_proc_entry(pkt_dev->entry->name, pn->proc_dir);
+ proc_remove(pkt_dev->entry);

#ifdef CONFIG_XFRM
free_SAs(pkt_dev);
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index e4738fe..0b732ef 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -105,7 +105,7 @@ clusterip_config_entry_put(struct clusterip_config *c)
* functions are also incrementing the refcount on their own,
* so it's safe to remove the entry even if it's in use. */
#ifdef CONFIG_PROC_FS
- remove_proc_entry(c->pde->name, c->pde->parent);
+ proc_remove(c->pde);
#endif
return;
}
@@ -736,7 +736,7 @@ static void __exit clusterip_tg_exit(void)
{
pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION);
#ifdef CONFIG_PROC_FS
- remove_proc_entry(clusterip_procdir->name, clusterip_procdir->parent);
+ proc_remove(clusterip_procdir);
#endif
nf_unregister_hook(&cip_arp_ops);
xt_unregister_target(&clusterip_tg_reg);
diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
index 7ea6e18..537d9ee 100644
--- a/net/ipv6/proc.c
+++ b/net/ipv6/proc.c
@@ -287,8 +287,7 @@ int snmp6_unregister_dev(struct inet6_dev *idev)
return -ENOENT;
if (!idev->stats.proc_dir_entry)
return -EINVAL;
- remove_proc_entry(idev->stats.proc_dir_entry->name,
- net->mib.proc_net_devsnmp6);
+ proc_remove(idev->stats.proc_dir_entry);
idev->stats.proc_dir_entry = NULL;
return 0;
}
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index d2fd53b..40002ef 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -330,7 +330,7 @@ static void htable_destroy(struct xt_hashlimit_htable *hinfo)
parent = hashlimit_net->ip6t_hashlimit;

if(parent != NULL)
- remove_proc_entry(hinfo->pde->name, parent);
+ proc_remove(hinfo->pde);

htable_selective_cleanup(hinfo, select_all);
vfree(hinfo);
@@ -887,7 +887,7 @@ static void __net_exit hashlimit_proc_net_exit(struct net *net)
pde = hashlimit_net->ip6t_hashlimit;

hlist_for_each_entry(hinfo, &hashlimit_net->htables, node)
- remove_proc_entry(hinfo->pde->name, pde);
+ proc_remove(hinfo->pde);

hashlimit_net->ipt_hashlimit = NULL;
hashlimit_net->ip6t_hashlimit = NULL;
diff --git a/sound/core/info.c b/sound/core/info.c
index c7f41c3..3c9bd6b 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -153,13 +153,6 @@ EXPORT_SYMBOL(snd_seq_root);
struct snd_info_entry *snd_oss_root;
#endif

-static void snd_remove_proc_entry(struct proc_dir_entry *parent,
- struct proc_dir_entry *de)
-{
- if (de)
- remove_proc_entry(de->name, parent);
-}
-
static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
{
struct snd_info_private_data *data;
@@ -580,7 +573,7 @@ int __exit snd_info_done(void)
#ifdef CONFIG_SND_OSSEMUL
snd_info_free_entry(snd_oss_root);
#endif
- snd_remove_proc_entry(NULL, snd_proc_root);
+ proc_remove(snd_proc_root);
}
return 0;
}
@@ -642,7 +635,7 @@ void snd_info_card_id_change(struct snd_card *card)
{
mutex_lock(&info_mutex);
if (card->proc_root_link) {
- snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
+ proc_remove(card->proc_root_link);
card->proc_root_link = NULL;
}
if (strcmp(card->id, card->proc_root->name))
@@ -661,10 +654,8 @@ void snd_info_card_disconnect(struct snd_card *card)
if (!card)
return;
mutex_lock(&info_mutex);
- if (card->proc_root_link) {
- snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
- card->proc_root_link = NULL;
- }
+ proc_remove(card->proc_root_link);
+ card->proc_root_link = NULL;
if (card->proc_root)
snd_info_disconnect(card->proc_root);
mutex_unlock(&info_mutex);
@@ -856,7 +847,7 @@ static void snd_info_disconnect(struct snd_info_entry *entry)
list_del_init(&entry->list);
root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
snd_BUG_ON(!root);
- snd_remove_proc_entry(root, entry->p);
+ proc_remove(entry->p);
entry->p = NULL;
}

2013-04-16 18:28:35

by David Howells

[permalink] [raw]
Subject: [PATCH 27/28] proc: Make the PROC_I() and PDE() macros internal to procfs [RFC]

Make the PROC_I() and PDE() macros internal to procfs. This means making
PDE_DATA() out of line. This could be made more optimal by storing
PDE()->data into inode->i_private.

Also provide a __PDE_DATA() that is inline and internal to procfs.

Signed-off-by: David Howells <[email protected]>
---

fs/proc/generic.c | 8 +++++++-
fs/proc/internal.h | 18 ++++++++++++++++++
fs/proc/proc_devtree.c | 2 +-
include/linux/proc_fs.h | 17 ++---------------
4 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 4b48033..d95abfd 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -165,7 +165,7 @@ void proc_free_inum(unsigned int inum)

static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)
{
- nd_set_link(nd, PDE_DATA(dentry->d_inode));
+ nd_set_link(nd, __PDE_DATA(dentry->d_inode));
return NULL;
}

@@ -637,3 +637,9 @@ void proc_remove(struct proc_dir_entry *de)
remove_proc_subtree(de->name, de->parent);
}
EXPORT_SYMBOL(proc_remove);
+
+void *PDE_DATA(const struct inode *inode)
+{
+ return __PDE_DATA(inode);
+}
+EXPORT_SYMBOL(PDE_DATA);
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index c529b5f..86a2406 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -84,6 +84,24 @@ struct proc_maps_private {

void proc_init_inodecache(void);

+/*
+ * General functions
+ */
+static inline struct proc_inode *PROC_I(const struct inode *inode)
+{
+ return container_of(inode, struct proc_inode, vfs_inode);
+}
+
+static inline struct proc_dir_entry *PDE(const struct inode *inode)
+{
+ return PROC_I(inode)->pde;
+}
+
+static inline void *__PDE_DATA(const struct inode *inode)
+{
+ return PDE(inode)->data;
+}
+
static inline struct pid *proc_pid(struct inode *inode)
{
return PROC_I(inode)->pid;
diff --git a/fs/proc/proc_devtree.c b/fs/proc/proc_devtree.c
index e0043c7..505afc9 100644
--- a/fs/proc/proc_devtree.c
+++ b/fs/proc/proc_devtree.c
@@ -41,7 +41,7 @@ static int property_proc_show(struct seq_file *m, void *v)

static int property_proc_open(struct inode *inode, struct file *file)
{
- return single_open(file, property_proc_show, PDE_DATA(inode));
+ return single_open(file, property_proc_show, __PDE_DATA(inode));
}

static const struct file_operations property_proc_fops = {
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index b8949b1..96ede28 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -87,6 +87,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 *PDE_DATA(const struct inode *);
extern void *proc_get_parent_data(const struct inode *);
extern const char *get_proc_name(const struct proc_dir_entry *);
extern struct pid *get_proc_pid(const struct inode *);
@@ -116,6 +117,7 @@ static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
umode_t mode, struct proc_dir_entry *parent) { return NULL; }
static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
+static inline void *PDE_DATA(const struct inode *inode) { return NULL; }
static inline struct pid *get_proc_pid(const struct inode *inode) { return NULL; }

#endif /* CONFIG_PROC_FS */
@@ -143,21 +145,6 @@ struct proc_inode {
struct inode vfs_inode;
};

-static inline struct proc_inode *PROC_I(const struct inode *inode)
-{
- return container_of(inode, struct proc_inode, vfs_inode);
-}
-
-static inline struct proc_dir_entry *PDE(const struct inode *inode)
-{
- return PROC_I(inode)->pde;
-}
-
-static inline void *PDE_DATA(const struct inode *inode)
-{
- return PROC_I(inode)->pde->data;
-}
-
static inline struct proc_dir_entry *proc_net_mkdir(
struct net *net, const char *name, struct proc_dir_entry *parent)
{

2013-04-16 18:29:15

by David Howells

[permalink] [raw]
Subject: [PATCH 22/28] ppc: Clean up rtas_flash driver somewhat [RFC]

Clean up some of the problems with the rtas_flash driver:

(1) It shouldn't fiddle with the internals of the procfs filesystem (altering
pde->count).

(2) If pid namespaces are in effect, then you can get multiple inodes
connected to a single pde, thereby rendering the pde->count > 2 test
useless.

(3) The pde->count fudging doesn't work for forked, dup'd or cloned file
descriptors, so add static mutexes and use them to wrap access to the
driver through read, write and release methods.

(4) The driver can only handle one device, so allocate most of the data
previously attached to the pde->data as static variables instead (though
allocate the validation data buffer with kmalloc).

(5) We don't need to save the pde pointers as long as we have the filenames
available for removal.

(6) Don't try to multiplex what the update file read method does based on the
filename. Instead provide separate file ops and split the function.

Whilst we're at it, tabulate the procfile information and loop through it when
creating or destroying them rather than manually coding each one.

Signed-off-by: David Howells <[email protected]>
cc: Benjamin Herrenschmidt <[email protected]>
cc: Paul Mackerras <[email protected]>
cc: Anton Blanchard <[email protected]>
cc: [email protected]
---

arch/powerpc/kernel/rtas_flash.c | 446 +++++++++++++++++---------------------
1 file changed, 200 insertions(+), 246 deletions(-)

diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
index c642f01..8196bfb 100644
--- a/arch/powerpc/kernel/rtas_flash.c
+++ b/arch/powerpc/kernel/rtas_flash.c
@@ -102,9 +102,10 @@ static struct kmem_cache *flash_block_cache = NULL;

#define FLASH_BLOCK_LIST_VERSION (1UL)

-/* Local copy of the flash block list.
- * We only allow one open of the flash proc file and create this
- * list as we go. The rtas_firmware_flash_list varable will be
+/*
+ * Local copy of the flash block list.
+ *
+ * The rtas_firmware_flash_list varable will be
* set once the data is fully read.
*
* For convenience as we build the list we use virtual addrs,
@@ -125,23 +126,23 @@ struct rtas_update_flash_t
struct rtas_manage_flash_t
{
int status; /* Returned status */
- unsigned int op; /* Reject or commit image */
};

/* Status int must be first member of struct */
struct rtas_validate_flash_t
{
int status; /* Returned status */
- char buf[VALIDATE_BUF_SIZE]; /* Candidate image buffer */
+ char *buf; /* Candidate image buffer */
unsigned int buf_size; /* Size of image buf */
unsigned int update_results; /* Update results token */
};

-static DEFINE_SPINLOCK(flash_file_open_lock);
-static struct proc_dir_entry *firmware_flash_pde;
-static struct proc_dir_entry *firmware_update_pde;
-static struct proc_dir_entry *validate_pde;
-static struct proc_dir_entry *manage_pde;
+static struct rtas_update_flash_t rtas_update_flash_data;
+static struct rtas_manage_flash_t rtas_manage_flash_data;
+static struct rtas_validate_flash_t rtas_validate_flash_data;
+static DEFINE_MUTEX(rtas_update_flash_mutex);
+static DEFINE_MUTEX(rtas_manage_flash_mutex);
+static DEFINE_MUTEX(rtas_validate_flash_mutex);

/* Do simple sanity checks on the flash image. */
static int flash_list_valid(struct flash_block_list *flist)
@@ -191,10 +192,10 @@ static void free_flash_list(struct flash_block_list *f)

static int rtas_flash_release(struct inode *inode, struct file *file)
{
- struct proc_dir_entry *dp = PDE(file_inode(file));
- struct rtas_update_flash_t *uf;
-
- uf = (struct rtas_update_flash_t *) dp->data;
+ struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
+
+ mutex_lock(&rtas_update_flash_mutex);
+
if (uf->flist) {
/* File was opened in write mode for a new flash attempt */
/* Clear saved list */
@@ -214,13 +215,14 @@ static int rtas_flash_release(struct inode *inode, struct file *file)
uf->flist = NULL;
}

- atomic_dec(&dp->count);
+ mutex_unlock(&rtas_update_flash_mutex);
return 0;
}

-static void get_flash_status_msg(int status, char *buf)
+static size_t get_flash_status_msg(int status, char *buf)
{
- char *msg;
+ const char *msg;
+ size_t len;

switch (status) {
case FLASH_AUTH:
@@ -242,34 +244,51 @@ static void get_flash_status_msg(int status, char *buf)
msg = "ready: firmware image ready for flash on reboot\n";
break;
default:
- sprintf(buf, "error: unexpected status value %d\n", status);
- return;
+ return sprintf(buf, "error: unexpected status value %d\n",
+ status);
}

- strcpy(buf, msg);
+ len = strlen(msg);
+ memcpy(buf, msg, len + 1);
+ return len;
}

/* Reading the proc file will show status (not the firmware contents) */
-static ssize_t rtas_flash_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
+static ssize_t rtas_flash_read_msg(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
{
- struct proc_dir_entry *dp = PDE(file_inode(file));
- struct rtas_update_flash_t *uf;
+ struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
char msg[RTAS_MSG_MAXLEN];
+ size_t len;
+ int status;

- uf = dp->data;
+ mutex_lock(&rtas_update_flash_mutex);
+ status = uf->status;
+ mutex_unlock(&rtas_update_flash_mutex);

- if (!strcmp(dp->name, FIRMWARE_FLASH_NAME)) {
- get_flash_status_msg(uf->status, msg);
- } else { /* FIRMWARE_UPDATE_NAME */
- sprintf(msg, "%d\n", uf->status);
- }
+ /* Read as text message */
+ len = get_flash_status_msg(uf->status, msg);
+ return simple_read_from_buffer(buf, count, ppos, msg, len);
+}
+
+static ssize_t rtas_flash_read_num(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
+ char msg[RTAS_MSG_MAXLEN];
+ int status;

+ mutex_lock(&rtas_update_flash_mutex);
+ status = uf->status;
+ mutex_unlock(&rtas_update_flash_mutex);
+
+ /* Read as number */
+ sprintf(msg, "%d\n", status);
return simple_read_from_buffer(buf, count, ppos, msg, strlen(msg));
}

/* constructor for flash_block_cache */
-void rtas_block_ctor(void *ptr)
+static void rtas_block_ctor(void *ptr)
{
memset(ptr, 0, RTAS_BLK_SIZE);
}
@@ -282,16 +301,15 @@ void rtas_block_ctor(void *ptr)
static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
size_t count, loff_t *off)
{
- struct proc_dir_entry *dp = PDE(file_inode(file));
- struct rtas_update_flash_t *uf;
+ struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
char *p;
- int next_free;
+ int next_free, rc;
struct flash_block_list *fl;

- uf = (struct rtas_update_flash_t *) dp->data;
+ mutex_lock(&rtas_update_flash_mutex);

if (uf->status == FLASH_AUTH || count == 0)
- return count; /* discard data */
+ goto out; /* discard data */

/* In the case that the image is not ready for flashing, the memory
* allocated for the block list will be freed upon the release of the
@@ -300,7 +318,7 @@ static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
if (uf->flist == NULL) {
uf->flist = kmem_cache_alloc(flash_block_cache, GFP_KERNEL);
if (!uf->flist)
- return -ENOMEM;
+ goto nomem;
}

fl = uf->flist;
@@ -311,7 +329,7 @@ static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
/* Need to allocate another block_list */
fl->next = kmem_cache_alloc(flash_block_cache, GFP_KERNEL);
if (!fl->next)
- return -ENOMEM;
+ goto nomem;
fl = fl->next;
next_free = 0;
}
@@ -320,52 +338,37 @@ static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
count = RTAS_BLK_SIZE;
p = kmem_cache_alloc(flash_block_cache, GFP_KERNEL);
if (!p)
- return -ENOMEM;
+ goto nomem;

if(copy_from_user(p, buffer, count)) {
kmem_cache_free(flash_block_cache, p);
- return -EFAULT;
+ rc = -EFAULT;
+ goto error;
}
fl->blocks[next_free].data = p;
fl->blocks[next_free].length = count;
fl->num_blocks++;
-
+out:
+ mutex_lock(&rtas_update_flash_mutex);
return count;
-}
-
-static int rtas_excl_open(struct inode *inode, struct file *file)
-{
- struct proc_dir_entry *dp = PDE(inode);
-
- /* Enforce exclusive open with use count of PDE */
- spin_lock(&flash_file_open_lock);
- if (atomic_read(&dp->count) > 2) {
- spin_unlock(&flash_file_open_lock);
- return -EBUSY;
- }
-
- atomic_inc(&dp->count);
- spin_unlock(&flash_file_open_lock);
-
- return 0;
-}
-
-static int rtas_excl_release(struct inode *inode, struct file *file)
-{
- struct proc_dir_entry *dp = PDE(inode);

- atomic_dec(&dp->count);
-
- return 0;
+nomem:
+ rc = -ENOMEM;
+error:
+ mutex_lock(&rtas_update_flash_mutex);
+ return rc;
}

-static void manage_flash(struct rtas_manage_flash_t *args_buf)
+/*
+ * Flash management routines.
+ */
+static void manage_flash(struct rtas_manage_flash_t *args_buf, unsigned int op)
{
s32 rc;

do {
- rc = rtas_call(rtas_token("ibm,manage-flash-image"), 1,
- 1, NULL, args_buf->op);
+ rc = rtas_call(rtas_token("ibm,manage-flash-image"), 1, 1,
+ NULL, op);
} while (rtas_busy_delay(rc));

args_buf->status = rc;
@@ -374,40 +377,38 @@ static void manage_flash(struct rtas_manage_flash_t *args_buf)
static ssize_t manage_flash_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
- struct proc_dir_entry *dp = PDE(file_inode(file));
- struct rtas_manage_flash_t *args_buf;
+ struct rtas_manage_flash_t *const args_buf = &rtas_manage_flash_data;
char msg[RTAS_MSG_MAXLEN];
- int msglen;
+ int msglen, status;

- args_buf = dp->data;
- if (args_buf == NULL)
- return 0;
-
- msglen = sprintf(msg, "%d\n", args_buf->status);
+ mutex_lock(&rtas_manage_flash_mutex);
+ status = args_buf->status;
+ mutex_unlock(&rtas_manage_flash_mutex);

+ msglen = sprintf(msg, "%d\n", status);
return simple_read_from_buffer(buf, count, ppos, msg, msglen);
}

static ssize_t manage_flash_write(struct file *file, const char __user *buf,
size_t count, loff_t *off)
{
- struct proc_dir_entry *dp = PDE(file_inode(file));
- struct rtas_manage_flash_t *args_buf;
- const char reject_str[] = "0";
- const char commit_str[] = "1";
+ struct rtas_manage_flash_t *const args_buf = &rtas_manage_flash_data;
+ static const char reject_str[] = "0";
+ static const char commit_str[] = "1";
char stkbuf[10];
- int op;
+ int op, rc;
+
+ mutex_lock(&rtas_manage_flash_mutex);

- args_buf = (struct rtas_manage_flash_t *) dp->data;
if ((args_buf->status == MANAGE_AUTH) || (count == 0))
- return count;
+ goto out;

op = -1;
if (buf) {
if (count > 9) count = 9;
- if (copy_from_user (stkbuf, buf, count)) {
- return -EFAULT;
- }
+ rc = -EFAULT;
+ if (copy_from_user (stkbuf, buf, count))
+ goto error;
if (strncmp(stkbuf, reject_str, strlen(reject_str)) == 0)
op = RTAS_REJECT_TMP_IMG;
else if (strncmp(stkbuf, commit_str, strlen(commit_str)) == 0)
@@ -417,12 +418,19 @@ static ssize_t manage_flash_write(struct file *file, const char __user *buf,
if (op == -1) /* buf is empty, or contains invalid string */
return -EINVAL;

- args_buf->op = op;
- manage_flash(args_buf);
-
+ manage_flash(args_buf, op);
+out:
+ mutex_unlock(&rtas_manage_flash_mutex);
return count;
+
+error:
+ mutex_unlock(&rtas_manage_flash_mutex);
+ return rc;
}

+/*
+ * Validation routines.
+ */
static void validate_flash(struct rtas_validate_flash_t *args_buf)
{
int token = rtas_token("ibm,validate-flash-image");
@@ -462,14 +470,14 @@ static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf,
static ssize_t validate_flash_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
- struct proc_dir_entry *dp = PDE(file_inode(file));
- struct rtas_validate_flash_t *args_buf;
+ struct rtas_validate_flash_t *const args_buf =
+ &rtas_validate_flash_data;
char msg[RTAS_MSG_MAXLEN];
int msglen;

- args_buf = dp->data;
-
+ mutex_lock(&rtas_validate_flash_mutex);
msglen = get_validate_flash_msg(args_buf, msg);
+ mutex_unlock(&rtas_validate_flash_mutex);

return simple_read_from_buffer(buf, count, ppos, msg, msglen);
}
@@ -477,24 +485,18 @@ static ssize_t validate_flash_read(struct file *file, char __user *buf,
static ssize_t validate_flash_write(struct file *file, const char __user *buf,
size_t count, loff_t *off)
{
- struct proc_dir_entry *dp = PDE(file_inode(file));
- struct rtas_validate_flash_t *args_buf;
+ struct rtas_validate_flash_t *const args_buf =
+ &rtas_validate_flash_data;
int rc;

- args_buf = (struct rtas_validate_flash_t *) dp->data;
-
- if (dp->data == NULL) {
- dp->data = kmalloc(sizeof(struct rtas_validate_flash_t),
- GFP_KERNEL);
- if (dp->data == NULL)
- return -ENOMEM;
- }
+ mutex_lock(&rtas_validate_flash_mutex);

/* We are only interested in the first 4K of the
* candidate image */
if ((*off >= VALIDATE_BUF_SIZE) ||
(args_buf->status == VALIDATE_AUTH)) {
*off += count;
+ mutex_unlock(&rtas_validate_flash_mutex);
return count;
}

@@ -517,31 +519,29 @@ static ssize_t validate_flash_write(struct file *file, const char __user *buf,
*off += count;
rc = count;
done:
- if (rc < 0) {
- kfree(dp->data);
- dp->data = NULL;
- }
+ mutex_unlock(&rtas_validate_flash_mutex);
return rc;
}

static int validate_flash_release(struct inode *inode, struct file *file)
{
- struct proc_dir_entry *dp = PDE(file_inode(file));
- struct rtas_validate_flash_t *args_buf;
+ struct rtas_validate_flash_t *const args_buf =
+ &rtas_validate_flash_data;

- args_buf = (struct rtas_validate_flash_t *) dp->data;
+ mutex_lock(&rtas_validate_flash_mutex);

if (args_buf->status == VALIDATE_READY) {
args_buf->buf_size = VALIDATE_BUF_SIZE;
validate_flash(args_buf);
}

- /* The matching atomic_inc was in rtas_excl_open() */
- atomic_dec(&dp->count);
-
+ mutex_unlock(&rtas_validate_flash_mutex);
return 0;
}

+/*
+ * On-reboot flash update applicator.
+ */
static void rtas_flash_firmware(int reboot_type)
{
unsigned long image_size;
@@ -634,75 +634,57 @@ static void rtas_flash_firmware(int reboot_type)
spin_unlock(&rtas_data_buf_lock);
}

-static void remove_flash_pde(struct proc_dir_entry *dp)
-{
- if (dp) {
- kfree(dp->data);
- remove_proc_entry(dp->name, dp->parent);
- }
-}
-
-static int initialize_flash_pde_data(const char *rtas_call_name,
- size_t buf_size,
- struct proc_dir_entry *dp)
-{
+/*
+ * Manifest of proc files to create
+ */
+struct rtas_flash_file {
+ const char *filename;
+ const char *rtas_call_name;
int *status;
- int token;
-
- dp->data = kzalloc(buf_size, GFP_KERNEL);
- if (dp->data == NULL)
- return -ENOMEM;
-
- /*
- * This code assumes that the status int is the first member of the
- * struct
- */
- status = (int *) dp->data;
- token = rtas_token(rtas_call_name);
- if (token == RTAS_UNKNOWN_SERVICE)
- *status = FLASH_AUTH;
- else
- *status = FLASH_NO_OP;
-
- return 0;
-}
-
-static struct proc_dir_entry *create_flash_pde(const char *filename,
- const struct file_operations *fops)
-{
- return proc_create(filename, S_IRUSR | S_IWUSR, NULL, fops);
-}
-
-static const struct file_operations rtas_flash_operations = {
- .owner = THIS_MODULE,
- .read = rtas_flash_read,
- .write = rtas_flash_write,
- .open = rtas_excl_open,
- .release = rtas_flash_release,
- .llseek = default_llseek,
+ const struct file_operations fops;
};

-static const struct file_operations manage_flash_operations = {
- .owner = THIS_MODULE,
- .read = manage_flash_read,
- .write = manage_flash_write,
- .open = rtas_excl_open,
- .release = rtas_excl_release,
- .llseek = default_llseek,
-};
-
-static const struct file_operations validate_flash_operations = {
- .owner = THIS_MODULE,
- .read = validate_flash_read,
- .write = validate_flash_write,
- .open = rtas_excl_open,
- .release = validate_flash_release,
- .llseek = default_llseek,
+static const struct rtas_flash_file rtas_flash_files[] = {
+ {
+ .filename = "powerpc/rtas/" FIRMWARE_FLASH_NAME,
+ .rtas_call_name = "ibm,update-flash-64-and-reboot",
+ .status = &rtas_update_flash_data.status,
+ .fops.read = rtas_flash_read_msg,
+ .fops.write = rtas_flash_write,
+ .fops.release = rtas_flash_release,
+ .fops.llseek = default_llseek,
+ },
+ {
+ .filename = "powerpc/rtas/" FIRMWARE_UPDATE_NAME,
+ .rtas_call_name = "ibm,update-flash-64-and-reboot",
+ .status = &rtas_update_flash_data.status,
+ .fops.read = rtas_flash_read_num,
+ .fops.write = rtas_flash_write,
+ .fops.release = rtas_flash_release,
+ .fops.llseek = default_llseek,
+ },
+ {
+ .filename = "powerpc/rtas/" VALIDATE_FLASH_NAME,
+ .rtas_call_name = "ibm,validate-flash-image",
+ .status = &rtas_validate_flash_data.status,
+ .fops.read = manage_flash_read,
+ .fops.write = manage_flash_write,
+ .fops.llseek = default_llseek,
+ },
+ {
+ .filename = "powerpc/rtas/" MANAGE_FLASH_NAME,
+ .rtas_call_name = "ibm,manage-flash-image",
+ .status = &rtas_manage_flash_data.status,
+ .fops.read = validate_flash_read,
+ .fops.write = validate_flash_write,
+ .fops.release = validate_flash_release,
+ .fops.llseek = default_llseek,
+ }
};

static int __init rtas_flash_init(void)
{
- int rc;
+ int i;

if (rtas_token("ibm,update-flash-64-and-reboot") ==
RTAS_UNKNOWN_SERVICE) {
@@ -710,93 +692,65 @@ static int __init rtas_flash_init(void)
return 1;
}

- firmware_flash_pde = create_flash_pde("powerpc/rtas/"
- FIRMWARE_FLASH_NAME,
- &rtas_flash_operations);
- if (firmware_flash_pde == NULL) {
- rc = -ENOMEM;
- goto cleanup;
- }
+ rtas_validate_flash_data.buf = kzalloc(VALIDATE_BUF_SIZE, GFP_KERNEL);
+ if (!rtas_validate_flash_data.buf)
+ return -ENOMEM;

- rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot",
- sizeof(struct rtas_update_flash_t),
- firmware_flash_pde);
- if (rc != 0)
- goto cleanup;
-
- firmware_update_pde = create_flash_pde("powerpc/rtas/"
- FIRMWARE_UPDATE_NAME,
- &rtas_flash_operations);
- if (firmware_update_pde == NULL) {
- rc = -ENOMEM;
- goto cleanup;
+ flash_block_cache = kmem_cache_create("rtas_flash_cache",
+ RTAS_BLK_SIZE, RTAS_BLK_SIZE, 0,
+ rtas_block_ctor);
+ if (!flash_block_cache) {
+ printk(KERN_ERR "%s: failed to create block cache\n",
+ __func__);
+ goto enomem_buf;
}

- rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot",
- sizeof(struct rtas_update_flash_t),
- firmware_update_pde);
- if (rc != 0)
- goto cleanup;
-
- validate_pde = create_flash_pde("powerpc/rtas/" VALIDATE_FLASH_NAME,
- &validate_flash_operations);
- if (validate_pde == NULL) {
- rc = -ENOMEM;
- goto cleanup;
- }
+ for (i = 0; i < ARRAY_SIZE(rtas_flash_files); i++) {
+ const struct rtas_flash_file *f = &rtas_flash_files[i];
+ int token;

- rc = initialize_flash_pde_data("ibm,validate-flash-image",
- sizeof(struct rtas_validate_flash_t),
- validate_pde);
- if (rc != 0)
- goto cleanup;
-
- manage_pde = create_flash_pde("powerpc/rtas/" MANAGE_FLASH_NAME,
- &manage_flash_operations);
- if (manage_pde == NULL) {
- rc = -ENOMEM;
- goto cleanup;
- }
+ if (!proc_create(f->filename, S_IRUSR | S_IWUSR, NULL, &f->fops))
+ goto enomem;

- rc = initialize_flash_pde_data("ibm,manage-flash-image",
- sizeof(struct rtas_manage_flash_t),
- manage_pde);
- if (rc != 0)
- goto cleanup;
+ /*
+ * This code assumes that the status int is the first member of the
+ * struct
+ */
+ token = rtas_token(f->rtas_call_name);
+ if (token == RTAS_UNKNOWN_SERVICE)
+ *f->status = FLASH_AUTH;
+ else
+ *f->status = FLASH_NO_OP;
+ }

rtas_flash_term_hook = rtas_flash_firmware;
-
- flash_block_cache = kmem_cache_create("rtas_flash_cache",
- RTAS_BLK_SIZE, RTAS_BLK_SIZE, 0,
- rtas_block_ctor);
- if (!flash_block_cache) {
- printk(KERN_ERR "%s: failed to create block cache\n",
- __func__);
- rc = -ENOMEM;
- goto cleanup;
- }
return 0;

-cleanup:
- remove_flash_pde(firmware_flash_pde);
- remove_flash_pde(firmware_update_pde);
- remove_flash_pde(validate_pde);
- remove_flash_pde(manage_pde);
+enomem:
+ while (--i >= 0) {
+ const struct rtas_flash_file *f = &rtas_flash_files[i];
+ remove_proc_entry(f->filename, NULL);
+ }

- return rc;
+ kmem_cache_destroy(flash_block_cache);
+enomem_buf:
+ kfree(rtas_validate_flash_data.buf);
+ return -ENOMEM;
}

static void __exit rtas_flash_cleanup(void)
{
+ int i;
+
rtas_flash_term_hook = NULL;

- if (flash_block_cache)
- kmem_cache_destroy(flash_block_cache);
+ for (i = 0; i < ARRAY_SIZE(rtas_flash_files); i++) {
+ const struct rtas_flash_file *f = &rtas_flash_files[i];
+ remove_proc_entry(f->filename, NULL);
+ }

- remove_flash_pde(firmware_flash_pde);
- remove_flash_pde(firmware_update_pde);
- remove_flash_pde(validate_pde);
- remove_flash_pde(manage_pde);
+ kmem_cache_destroy(flash_block_cache);
+ kfree(rtas_validate_flash_data.buf);
}

module_init(rtas_flash_init);

2013-04-16 18:29:43

by David Howells

[permalink] [raw]
Subject: [PATCH 21/28] dgrp: Clean up the use of procfs [RFC]

Clean up the use of procfs by the dgrp driver:

(1) Use remove_proc_subtree() for the mass slaughter of a subdir full of proc
files rather than doing it manually.

(2) When creating files, only call ID_TO_CHAR() once to generate the name.

Signed-off-by : David Howells <[email protected]>
cc: Bill Pemberton <[email protected]>
cc: Tommi Rantala <[email protected]>
cc: [email protected]
---

drivers/staging/dgrp/dgrp_specproc.c | 82 ++++++++++++----------------------
1 file changed, 28 insertions(+), 54 deletions(-)

diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c
index 205d80e..e3c16a9 100644
--- a/drivers/staging/dgrp/dgrp_specproc.c
+++ b/drivers/staging/dgrp/dgrp_specproc.c
@@ -45,13 +45,8 @@

#include "dgrp_common.h"

-static struct proc_dir_entry *dgrp_proc_dir_entry;
-
static int dgrp_add_id(long id);
static int dgrp_remove_nd(struct nd_struct *nd);
-static struct proc_dir_entry *add_proc_file(struct nd_struct *node,
- struct proc_dir_entry *root,
- const struct file_operations *fops);

/* File operation declarations */
static int parse_write_config(char *);
@@ -94,51 +89,23 @@ static struct proc_dir_entry *mon_entry_pointer;
static struct proc_dir_entry *dpa_entry_pointer;
static struct proc_dir_entry *ports_entry_pointer;

-static void remove_files(struct nd_struct *nd)
-{
- char buf[3];
- ID_TO_CHAR(nd->nd_ID, buf);
- dgrp_remove_node_class_sysfs_files(nd);
- if (nd->nd_net_de)
- remove_proc_entry(buf, net_entry_pointer);
- if (nd->nd_mon_de)
- remove_proc_entry(buf, mon_entry_pointer);
- if (nd->nd_dpa_de)
- remove_proc_entry(buf, dpa_entry_pointer);
- if (nd->nd_ports_de)
- remove_proc_entry(buf, ports_entry_pointer);
-}
-
void dgrp_unregister_proc(void)
{
+ struct nd_struct *nd;
+
net_entry_pointer = NULL;
mon_entry_pointer = NULL;
dpa_entry_pointer = NULL;
ports_entry_pointer = NULL;

- if (dgrp_proc_dir_entry) {
- struct nd_struct *nd;
- list_for_each_entry(nd, &nd_struct_list, list)
- remove_files(nd);
- remove_proc_entry("dgrp/config", NULL);
- remove_proc_entry("dgrp/info", NULL);
- remove_proc_entry("dgrp/nodeinfo", NULL);
- remove_proc_entry("dgrp/net", NULL);
- remove_proc_entry("dgrp/mon", NULL);
- remove_proc_entry("dgrp/dpa", NULL);
- remove_proc_entry("dgrp/ports", NULL);
- remove_proc_entry("dgrp", NULL);
- dgrp_proc_dir_entry = NULL;
- }
+ list_for_each_entry(nd, &nd_struct_list, list)
+ dgrp_remove_node_class_sysfs_files(nd);
+ remove_proc_subtree("dgrp", NULL);
}

void dgrp_register_proc(void)
{
- /*
- * Register /proc/dgrp
- */
- dgrp_proc_dir_entry = proc_mkdir("dgrp", NULL);
- if (!dgrp_proc_dir_entry)
+ if (!proc_mkdir("dgrp", NULL))
return;
proc_create("dgrp/config", 0644, NULL, &config_proc_file_ops);
proc_create("dgrp/info", 0644, NULL, &info_proc_file_ops);
@@ -455,6 +422,14 @@ static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file)
return seq_open(file, &nodeinfo_ops);
}

+static struct proc_dir_entry *add_proc_file(struct nd_struct *nd,
+ const char *name,
+ struct proc_dir_entry *root,
+ const struct file_operations *fops)
+{
+ return proc_create_data(name, 0600, root, fops, nd);
+}
+
/**
* dgrp_add_id() -- creates new nd struct and adds it to list
* @id: id of device to add
@@ -462,6 +437,7 @@ static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file)
static int dgrp_add_id(long id)
{
struct nd_struct *nd;
+ char name[3];
int ret;
int i;

@@ -496,11 +472,11 @@ static int dgrp_add_id(long id)
goto error_out;

dgrp_create_node_class_sysfs_files(nd);
- nd->nd_net_de = add_proc_file(nd, net_entry_pointer, &dgrp_net_ops);
- nd->nd_mon_de = add_proc_file(nd, mon_entry_pointer, &dgrp_mon_ops);
- nd->nd_dpa_de = add_proc_file(nd, dpa_entry_pointer, &dgrp_dpa_ops);
- nd->nd_ports_de = add_proc_file(nd, ports_entry_pointer,
- &dgrp_ports_ops);
+ ID_TO_CHAR(nd->nd_ID, name);
+ add_proc_file(nd, name, net_entry_pointer, &dgrp_net_ops);
+ add_proc_file(nd, name, mon_entry_pointer, &dgrp_mon_ops);
+ add_proc_file(nd, name, dpa_entry_pointer, &dgrp_dpa_ops);
+ add_proc_file(nd, name, ports_entry_pointer, &dgrp_ports_ops);
return 0;

/* FIXME this guy should free the tty driver stored in nd and destroy
@@ -513,13 +489,20 @@ error_out:

static int dgrp_remove_nd(struct nd_struct *nd)
{
+ char name[3];
int ret;

/* Check to see if the selected structure is in use */
if (nd->nd_tty_ref_cnt)
return -EBUSY;

- remove_files(nd);
+
+ dgrp_remove_node_class_sysfs_files(nd);
+ ID_TO_CHAR(nd->nd_ID, name);
+ remove_proc_entry(name, net_entry_pointer);
+ remove_proc_entry(name, mon_entry_pointer);
+ remove_proc_entry(name, dpa_entry_pointer);
+ remove_proc_entry(name, ports_entry_pointer);

dgrp_tty_uninit(nd);

@@ -530,12 +513,3 @@ static int dgrp_remove_nd(struct nd_struct *nd)
kfree(nd);
return 0;
}
-
-static struct proc_dir_entry *add_proc_file(struct nd_struct *node,
- struct proc_dir_entry *root,
- const struct file_operations *fops)
-{
- char buf[3];
- ID_TO_CHAR(node->nd_ID, buf);
- return proc_create_data(buf, 0600, root, fops, node);
-}

2013-04-16 18:30:44

by David Howells

[permalink] [raw]
Subject: [PATCH 16/28] zoran: Don't print proc_dir_entry data in debug [RFC]

Don't print proc_dir_entry data in debug as we're soon to have no direct
access to the contents of the PDE. Print what was put in there instead.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
cc: [email protected]
---

drivers/media/pci/zoran/zoran_procfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/zoran/zoran_procfs.c b/drivers/media/pci/zoran/zoran_procfs.c
index 07a104d..f7ceee0 100644
--- a/drivers/media/pci/zoran/zoran_procfs.c
+++ b/drivers/media/pci/zoran/zoran_procfs.c
@@ -201,7 +201,7 @@ zoran_proc_init (struct zoran *zr)
dprintk(2,
KERN_INFO
"%s: procfs entry /proc/%s allocated. data=%p\n",
- ZR_DEVNAME(zr), name, zr->zoran_proc->data);
+ ZR_DEVNAME(zr), name, zr);
} else {
dprintk(1, KERN_ERR "%s: Unable to initialise /proc/%s\n",
ZR_DEVNAME(zr), name);

2013-04-16 18:31:01

by David Howells

[permalink] [raw]
Subject: [PATCH 18/28] drm: proc: Use minor->index to label things, not PDE->name [RFC]

Use minor->index to label things, not the name field from the proc_dir_entry
of the /proc/dwm/<minor>/ directory.

Also, use "%u" not "%d" to render the value and use a 12-byte buffer in which
to render the integer, not a 16-byte buffer. The longest string an unsigned
int can give you is 10 chars (4294967295) plus a NUL, so round up to 12 as the
stack is likely to be 4- or 8-byte aligned.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
---

drivers/gpu/drm/drm_proc.c | 13 +++++--------
drivers/gpu/drm/drm_stub.c | 2 +-
include/drm/drmP.h | 3 +--
3 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/drm_proc.c b/drivers/gpu/drm/drm_proc.c
index aead653..0646a46 100644
--- a/drivers/gpu/drm/drm_proc.c
+++ b/drivers/gpu/drm/drm_proc.c
@@ -116,14 +116,13 @@ static int drm_proc_create_files(const struct drm_info_list *files, int count,
ent = proc_create_data(files[i].name, S_IRUGO, root,
&drm_proc_fops, tmp);
if (!ent) {
- DRM_ERROR("Cannot create /proc/dri/%s/%s\n",
- root->name, files[i].name);
+ DRM_ERROR("Cannot create /proc/dri/%u/%s\n",
+ minor->index, files[i].name);
list_del(&tmp->list);
kfree(tmp);
ret = -1;
goto fail;
}
-
}
return 0;

@@ -137,7 +136,6 @@ fail:
* Initialize the DRI proc filesystem for a device
*
* \param dev DRM device
- * \param minor device minor number
* \param root DRI proc dir entry.
* \param dev_root resulting DRI device proc dir entry.
* \return root entry pointer on success, or NULL on failure.
@@ -146,14 +144,13 @@ fail:
* "/proc/dri/%minor%/", and each entry in proc_list as
* "/proc/dri/%minor%/%name%".
*/
-int drm_proc_init(struct drm_minor *minor, int minor_id,
- struct proc_dir_entry *root)
+int drm_proc_init(struct drm_minor *minor, struct proc_dir_entry *root)
{
- char name[64];
+ char name[12];
int ret;

INIT_LIST_HEAD(&minor->proc_nodes.list);
- sprintf(name, "%d", minor_id);
+ sprintf(name, "%u", minor->index);
minor->proc_root = proc_mkdir(name, root);
if (!minor->proc_root) {
DRM_ERROR("Cannot create /proc/dri/%s\n", name);
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index 7d30802..16f3ec5 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -352,7 +352,7 @@ int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
idr_replace(&drm_minors_idr, new_minor, minor_id);

if (type == DRM_MINOR_LEGACY) {
- ret = drm_proc_init(new_minor, minor_id, drm_proc_root);
+ ret = drm_proc_init(new_minor, drm_proc_root);
if (ret) {
DRM_ERROR("DRM: Failed to initialize /proc/dri.\n");
goto err_mem;
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index af53320..60c33f1 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1546,8 +1546,7 @@ extern struct idr drm_minors_idr;
extern struct drm_local_map *drm_getsarea(struct drm_device *dev);

/* Proc support (drm_proc.h) */
-extern int drm_proc_init(struct drm_minor *minor, int minor_id,
- struct proc_dir_entry *root);
+extern int drm_proc_init(struct drm_minor *minor, struct proc_dir_entry *root);
extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);

/* Debugfs support */

2013-04-16 18:31:39

by David Howells

[permalink] [raw]
Subject: [PATCH 13/28] airo: Use remove_proc_subtree() [RFC]

Use remove_proc_subtree() to remove the airo device subdir and all its
children instead of doing it manually.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
---

drivers/net/wireless/airo.c | 49 +++++++++++--------------------------------
1 file changed, 13 insertions(+), 36 deletions(-)

diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 21d0233..6125adb 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -4506,98 +4506,75 @@ static int setup_proc_entry( struct net_device *dev,
apriv->proc_entry = proc_mkdir_mode(apriv->proc_name, airo_perm,
airo_entry);
if (!apriv->proc_entry)
- goto fail;
+ return -ENOMEM;
proc_set_user(apriv->proc_entry, proc_kuid, proc_kgid);

/* Setup the StatsDelta */
entry = proc_create_data("StatsDelta", S_IRUGO & proc_perm,
apriv->proc_entry, &proc_statsdelta_ops, dev);
if (!entry)
- goto fail_stats_delta;
+ goto fail;
proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the Stats */
entry = proc_create_data("Stats", S_IRUGO & proc_perm,
apriv->proc_entry, &proc_stats_ops, dev);
if (!entry)
- goto fail_stats;
+ goto fail;
proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the Status */
entry = proc_create_data("Status", S_IRUGO & proc_perm,
apriv->proc_entry, &proc_status_ops, dev);
if (!entry)
- goto fail_status;
+ goto fail;
proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the Config */
entry = proc_create_data("Config", proc_perm,
apriv->proc_entry, &proc_config_ops, dev);
if (!entry)
- goto fail_config;
+ goto fail;
proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the SSID */
entry = proc_create_data("SSID", proc_perm,
apriv->proc_entry, &proc_SSID_ops, dev);
if (!entry)
- goto fail_ssid;
+ goto fail;
proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the APList */
entry = proc_create_data("APList", proc_perm,
apriv->proc_entry, &proc_APList_ops, dev);
if (!entry)
- goto fail_aplist;
+ goto fail;
proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the BSSList */
entry = proc_create_data("BSSList", proc_perm,
apriv->proc_entry, &proc_BSSList_ops, dev);
if (!entry)
- goto fail_bsslist;
+ goto fail;
proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the WepKey */
entry = proc_create_data("WepKey", proc_perm,
apriv->proc_entry, &proc_wepkey_ops, dev);
if (!entry)
- goto fail_wepkey;
+ goto fail;
proc_set_user(entry, proc_kuid, proc_kgid);
return 0;

-fail_wepkey:
- remove_proc_entry("BSSList", apriv->proc_entry);
-fail_bsslist:
- remove_proc_entry("APList", apriv->proc_entry);
-fail_aplist:
- remove_proc_entry("SSID", apriv->proc_entry);
-fail_ssid:
- remove_proc_entry("Config", apriv->proc_entry);
-fail_config:
- remove_proc_entry("Status", apriv->proc_entry);
-fail_status:
- remove_proc_entry("Stats", apriv->proc_entry);
-fail_stats:
- remove_proc_entry("StatsDelta", apriv->proc_entry);
-fail_stats_delta:
- remove_proc_entry(apriv->proc_name, airo_entry);
fail:
+ remove_proc_subtree(apriv->proc_name, airo_entry);
return -ENOMEM;
}

static int takedown_proc_entry( struct net_device *dev,
- struct airo_info *apriv ) {
- if ( !apriv->proc_entry->namelen ) return 0;
- remove_proc_entry("Stats",apriv->proc_entry);
- remove_proc_entry("StatsDelta",apriv->proc_entry);
- remove_proc_entry("Status",apriv->proc_entry);
- remove_proc_entry("Config",apriv->proc_entry);
- remove_proc_entry("SSID",apriv->proc_entry);
- remove_proc_entry("APList",apriv->proc_entry);
- remove_proc_entry("BSSList",apriv->proc_entry);
- remove_proc_entry("WepKey",apriv->proc_entry);
- remove_proc_entry(apriv->proc_name,airo_entry);
+ struct airo_info *apriv )
+{
+ remove_proc_subtree(apriv->proc_name, airo_entry);
return 0;
}

2013-04-16 18:31:37

by David Howells

[permalink] [raw]
Subject: [PATCH 14/28] proc: Supply an accessor for getting the data from a PDE's parent [RFC]

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 <[email protected]>
cc: Jerry Chuang <[email protected]>
cc: Mauro Carvalho Chehab <[email protected]>
cc: Maxim Mikityanskiy <[email protected]>
cc: YAMANE Toshiaki <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
---

drivers/scsi/megaraid.c | 2 +-
drivers/staging/rtl8187se/r8180_core.c | 2 +-
drivers/staging/rtl8192u/r8192U_core.c | 2 +-
fs/proc/generic.c | 7 +++++++
include/linux/proc_fs.h | 1 +
5 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index ef3384d..7373255 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -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);
diff --git a/drivers/staging/rtl8187se/r8180_core.c b/drivers/staging/rtl8187se/r8180_core.c
index ab469ce..f7c1d99 100644
--- a/drivers/staging/rtl8187se/r8180_core.c
+++ b/drivers/staging/rtl8187se/r8180_core.c
@@ -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);
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 27ba2a3..1459233 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -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);
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 4074da5..75e08d3 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -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);
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index e5d8f69..12694ef 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -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)

2013-04-16 18:32:50

by David Howells

[permalink] [raw]
Subject: [PATCH 12/28] rtl8192u: Don't need to save device proc dir PDE [RFC]

Don't need to save the PDE of a directory created under /proc/net/rtl8192/ as
we can use proc subtree deletion to get rid of it and all its children.

Signed-off-by: David Howells <[email protected]>
cc: Jerry Chuang <[email protected]>
cc: Mauro Carvalho Chehab <[email protected]>
cc: [email protected]
cc: [email protected]
---

drivers/staging/rtl8192u/r8192U.h | 1 -
drivers/staging/rtl8192u/r8192U_core.c | 18 ++++++------------
2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
index e538e02..bedeb33 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -946,7 +946,6 @@ typedef struct r8192_priv {
/*stats*/
struct Stats stats;
struct iw_statistics wstats;
- struct proc_dir_entry *dir_dev;

/*RX stuff*/
// u32 *rxring;
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index d81d7d5..27ba2a3 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -669,20 +669,19 @@ static const struct rtl8192_proc_file rtl8192_proc_files[] = {
void rtl8192_proc_init_one(struct net_device *dev)
{
const struct rtl8192_proc_file *f;
- struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+ struct proc_dir_entry *dir;

if (rtl8192_proc) {
- priv->dir_dev = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
- if (!priv->dir_dev) {
+ dir = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
+ if (!dir) {
RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
dev->name);
return;
}

for (f = rtl8192_proc_files; f->name[0]; f++) {
- if (!proc_create_data(f->name, S_IFREG | S_IRUGO,
- priv->dir_dev,
- rtl8192_proc_fops, f->show)) {
+ if (!proc_create_data(f->name, S_IFREG | S_IRUGO, dir,
+ &rtl8192_proc_fops, f->show)) {
RT_TRACE(COMP_ERR, "Unable to initialize "
"/proc/net/rtl8192/%s/%s\n",
dev->name, f->name);
@@ -694,12 +693,7 @@ void rtl8192_proc_init_one(struct net_device *dev)

void rtl8192_proc_remove_one(struct net_device *dev)
{
- struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
-
- if (priv->dir_dev) {
- remove_proc_subtree(dev->name, rtl8192_proc);
- priv->dir_dev = NULL;
- }
+ remove_proc_subtree(dev->name, rtl8192_proc);
}

/****************************************************************************

2013-04-16 18:26:44

by David Howells

[permalink] [raw]
Subject: [PATCH 11/28] rtl8187se: Use a dir under /proc/net/r8180/ [RFC]

Create a dir under /proc/net/r8180/ named for the device and create that
device's files under there. This means that there won't be a problem for
multiple devices in the system (if such is possible) and it means we don't
need to save the 'device directory' PDE any more as we can just do a proc
subtree removal.

Signed-off-by: David Howells <[email protected]>
cc: Maxim Mikityanskiy <[email protected]>
cc: YAMANE Toshiaki <[email protected]>
cc: [email protected]
cc: [email protected]
---

drivers/staging/rtl8187se/r8180.h | 1 -
drivers/staging/rtl8187se/r8180_core.c | 26 ++++++++------------------
2 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/rtl8187se/r8180.h b/drivers/staging/rtl8187se/r8180.h
index 70ea414..edacc80 100644
--- a/drivers/staging/rtl8187se/r8180.h
+++ b/drivers/staging/rtl8187se/r8180.h
@@ -372,7 +372,6 @@ typedef struct r8180_priv
struct Stats stats;
struct _link_detect_t link_detect; //YJ,add,080828
struct iw_statistics wstats;
- struct proc_dir_entry *dir_dev;

/*RX stuff*/
u32 *rxring;
diff --git a/drivers/staging/rtl8187se/r8180_core.c b/drivers/staging/rtl8187se/r8180_core.c
index 448da77..ab469ce 100644
--- a/drivers/staging/rtl8187se/r8180_core.c
+++ b/drivers/staging/rtl8187se/r8180_core.c
@@ -288,14 +288,7 @@ void rtl8180_proc_module_remove(void)

void rtl8180_proc_remove_one(struct net_device *dev)
{
- struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
- if (priv->dir_dev) {
- remove_proc_entry("stats-hw", priv->dir_dev);
- remove_proc_entry("stats-tx", priv->dir_dev);
- remove_proc_entry("stats-rx", priv->dir_dev);
- remove_proc_entry("registers", priv->dir_dev);
- priv->dir_dev = NULL;
- }
+ remove_proc_subtree(dev->name, rtl8180_proc);
}

/*
@@ -335,22 +328,19 @@ static const struct rtl8180_proc_file rtl8180_proc_files[] = {
void rtl8180_proc_init_one(struct net_device *dev)
{
const struct rtl8180_proc_file *f;
- struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
+ struct proc_dir_entry *dir;

- priv->dir_dev = rtl8180_proc;
- if (!priv->dir_dev) {
- DMESGE("Unable to initialize /proc/net/r8180/%s\n",
- dev->name);
+ dir = proc_mkdir_data(dev->name, 0, rtl8180_proc, dev);
+ if (!dir) {
+ DMESGE("Unable to initialize /proc/net/r8180/%s\n", dev->name);
return;
}
- priv->dir_dev->data = dev;

for (f = rtl8180_proc_files; f->name[0]; f++) {
- if (!proc_create_data(f->name, S_IFREG | S_IRUGO,
- priv->dir_dev,
+ if (!proc_create_data(f->name, S_IFREG | S_IRUGO, dir,
&rtl8180_proc_fops, f->show)) {
- DMESGE("Unable to initialize /proc/net/r8180/%s\n",
- f->name);
+ DMESGE("Unable to initialize /proc/net/r8180/%s/%s\n",
+ dev->name, f->name);
return;
}
}

2013-04-16 18:26:28

by David Howells

[permalink] [raw]
Subject: [PATCH 07/28] proc: Split the namespace stuff out into linux/proc_ns.h [RFC]

Split the proc namespace stuff out into linux/proc_ns.h.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
cc: Serge E. Hallyn <[email protected]>
cc: Eric W. Biederman <[email protected]>
---

fs/namespace.c | 6 ++--
fs/proc/inode.c | 8 ++---
fs/proc/namespaces.c | 17 +++++++----
include/linux/proc_fs.h | 68 +-----------------------------------------
include/linux/proc_ns.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++
init/version.c | 2 +
ipc/msgutil.c | 2 +
ipc/namespace.c | 2 +
kernel/nsproxy.c | 6 ++--
kernel/pid.c | 1 +
kernel/pid_namespace.c | 2 +
kernel/user.c | 2 +
kernel/user_namespace.c | 2 +
kernel/utsname.c | 2 +
net/core/net_namespace.c | 7 ++--
15 files changed, 109 insertions(+), 92 deletions(-)
create mode 100644 include/linux/proc_ns.h

diff --git a/fs/namespace.c b/fs/namespace.c
index ed0708f..0f0cf93 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -21,7 +21,7 @@
#include <linux/fs_struct.h> /* get_fs_root et.al. */
#include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */
#include <linux/uaccess.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
#include "pnode.h"
#include "internal.h"

@@ -1350,13 +1350,13 @@ static bool mnt_ns_loop(struct path *path)
* mount namespace loop?
*/
struct inode *inode = path->dentry->d_inode;
- struct proc_inode *ei;
+ struct proc_ns *ei;
struct mnt_namespace *mnt_ns;

if (!proc_ns_inode(inode))
return false;

- ei = PROC_I(inode);
+ ei = get_proc_ns(inode);
if (ei->ns_ops != &mntns_operations)
return false;

diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index bd2f764..073aea6 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -51,8 +51,8 @@ static void proc_evict_inode(struct inode *inode)
sysctl_head_put(head);
}
/* Release any associated namespace */
- ns_ops = PROC_I(inode)->ns_ops;
- ns = PROC_I(inode)->ns;
+ ns_ops = PROC_I(inode)->ns.ns_ops;
+ ns = PROC_I(inode)->ns.ns;
if (ns_ops && ns)
ns_ops->put(ns);
}
@@ -73,8 +73,8 @@ static struct inode *proc_alloc_inode(struct super_block *sb)
ei->pde = NULL;
ei->sysctl = NULL;
ei->sysctl_entry = NULL;
- ei->ns = NULL;
- ei->ns_ops = NULL;
+ ei->ns.ns = NULL;
+ ei->ns.ns_ops = NULL;
inode = &ei->vfs_inode;
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
return inode;
diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c
index 66b51c0..54bdc67 100644
--- a/fs/proc/namespaces.c
+++ b/fs/proc/namespaces.c
@@ -51,7 +51,7 @@ static int ns_delete_dentry(const struct dentry *dentry)
static char *ns_dname(struct dentry *dentry, char *buffer, int buflen)
{
struct inode *inode = dentry->d_inode;
- const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops;
+ const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns.ns_ops;

return dynamic_dname(dentry, buffer, buflen, "%s:[%lu]",
ns_ops->name, inode->i_ino);
@@ -95,8 +95,8 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb,
inode->i_op = &ns_inode_operations;
inode->i_mode = S_IFREG | S_IRUGO;
inode->i_fop = &ns_file_operations;
- ei->ns_ops = ns_ops;
- ei->ns = ns;
+ ei->ns.ns_ops = ns_ops;
+ ei->ns.ns = ns;
unlock_new_inode(inode);
} else {
ns_ops->put(ns);
@@ -128,7 +128,7 @@ static void *proc_ns_follow_link(struct dentry *dentry, struct nameidata *nd)
if (!ptrace_may_access(task, PTRACE_MODE_READ))
goto out_put_task;

- ns_path.dentry = proc_ns_get_dentry(sb, task, ei->ns_ops);
+ ns_path.dentry = proc_ns_get_dentry(sb, task, ei->ns.ns_ops);
if (IS_ERR(ns_path.dentry)) {
error = ERR_CAST(ns_path.dentry);
goto out_put_task;
@@ -148,7 +148,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
{
struct inode *inode = dentry->d_inode;
struct proc_inode *ei = PROC_I(inode);
- const struct proc_ns_operations *ns_ops = ei->ns_ops;
+ const struct proc_ns_operations *ns_ops = ei->ns.ns_ops;
struct task_struct *task;
void *ns;
char name[50];
@@ -202,7 +202,7 @@ static struct dentry *proc_ns_instantiate(struct inode *dir,
ei = PROC_I(inode);
inode->i_mode = S_IFLNK|S_IRWXUGO;
inode->i_op = &proc_ns_link_inode_operations;
- ei->ns_ops = ns_ops;
+ ei->ns.ns_ops = ns_ops;

d_set_d_op(dentry, &pid_dentry_operations);
d_add(dentry, inode);
@@ -337,6 +337,11 @@ out_invalid:
return ERR_PTR(-EINVAL);
}

+struct proc_ns *get_proc_ns(struct inode *inode)
+{
+ return &PROC_I(inode)->ns;
+}
+
bool proc_ns_inode(struct inode *inode)
{
return inode->i_fop == &ns_file_operations;
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 28a4d7e..8f7d8f2 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -6,6 +6,7 @@
#include <linux/spinlock.h>
#include <linux/magic.h>
#include <linux/atomic.h>
+#include <linux/proc_ns.h>

struct net;
struct completion;
@@ -24,18 +25,6 @@ struct mm_struct;
#define PROC_NUMBUF 13

/*
- * We always define these enumerators
- */
-
-enum {
- PROC_ROOT_INO = 1,
- PROC_IPC_INIT_INO = 0xEFFFFFFFU,
- PROC_UTS_INIT_INO = 0xEFFFFFFEU,
- PROC_USER_INIT_INO = 0xEFFFFFFDU,
- PROC_PID_INIT_INO = 0xEFFFFFFCU,
-};
-
-/*
* This is not completely implemented yet. The idea is to
* create an in-memory tree (like the actual /proc filesystem
* tree) of these proc_dir_entries, so that we can dynamically
@@ -81,10 +70,6 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);

-struct pid_namespace;
-
-extern int pid_ns_prepare_proc(struct pid_namespace *ns);
-extern void pid_ns_release_proc(struct pid_namespace *ns);

/*
* proc_tty.c
@@ -132,12 +117,6 @@ extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,

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 struct file *proc_ns_fget(int fd);
-extern bool proc_ns_inode(struct inode *inode);
-
-extern int proc_alloc_inum(unsigned int *pino);
-extern void proc_free_inum(unsigned int inum);
#else

static inline void proc_flush_task(struct task_struct *task)
@@ -168,50 +147,8 @@ struct tty_driver;
static inline void proc_tty_register_driver(struct tty_driver *driver) {};
static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};

-static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
-{
- return 0;
-}
-
-static inline void pid_ns_release_proc(struct pid_namespace *ns)
-{
-}
-
-static inline struct file *proc_ns_fget(int fd)
-{
- return ERR_PTR(-EINVAL);
-}
-
-static inline bool proc_ns_inode(struct inode *inode)
-{
- return false;
-}
-
-static inline int proc_alloc_inum(unsigned int *inum)
-{
- *inum = 1;
- return 0;
-}
-static inline void proc_free_inum(unsigned int inum)
-{
-}
#endif /* CONFIG_PROC_FS */

-struct nsproxy;
-struct proc_ns_operations {
- const char *name;
- int type;
- void *(*get)(struct task_struct *task);
- void (*put)(void *ns);
- int (*install)(struct nsproxy *nsproxy, void *ns);
- unsigned int (*inum)(void *ns);
-};
-extern const struct proc_ns_operations netns_operations;
-extern const struct proc_ns_operations utsns_operations;
-extern const struct proc_ns_operations ipcns_operations;
-extern const struct proc_ns_operations pidns_operations;
-extern const struct proc_ns_operations userns_operations;
-extern const struct proc_ns_operations mntns_operations;

union proc_op {
int (*proc_get_link)(struct dentry *, struct path *);
@@ -231,8 +168,7 @@ struct proc_inode {
struct proc_dir_entry *pde;
struct ctl_table_header *sysctl;
struct ctl_table *sysctl_entry;
- void *ns;
- const struct proc_ns_operations *ns_ops;
+ struct proc_ns ns;
struct inode vfs_inode;
};

diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
new file mode 100644
index 0000000..34a1e10
--- /dev/null
+++ b/include/linux/proc_ns.h
@@ -0,0 +1,74 @@
+/*
+ * procfs namespace bits
+ */
+#ifndef _LINUX_PROC_NS_H
+#define _LINUX_PROC_NS_H
+
+struct pid_namespace;
+struct nsproxy;
+
+struct proc_ns_operations {
+ const char *name;
+ int type;
+ void *(*get)(struct task_struct *task);
+ void (*put)(void *ns);
+ int (*install)(struct nsproxy *nsproxy, void *ns);
+ unsigned int (*inum)(void *ns);
+};
+
+struct proc_ns {
+ void *ns;
+ const struct proc_ns_operations *ns_ops;
+};
+
+extern const struct proc_ns_operations netns_operations;
+extern const struct proc_ns_operations utsns_operations;
+extern const struct proc_ns_operations ipcns_operations;
+extern const struct proc_ns_operations pidns_operations;
+extern const struct proc_ns_operations userns_operations;
+extern const struct proc_ns_operations mntns_operations;
+
+/*
+ * We always define these enumerators
+ */
+enum {
+ PROC_ROOT_INO = 1,
+ PROC_IPC_INIT_INO = 0xEFFFFFFFU,
+ PROC_UTS_INIT_INO = 0xEFFFFFFEU,
+ PROC_USER_INIT_INO = 0xEFFFFFFDU,
+ PROC_PID_INIT_INO = 0xEFFFFFFCU,
+};
+
+#ifdef CONFIG_PROC_FS
+
+extern int pid_ns_prepare_proc(struct pid_namespace *ns);
+extern void pid_ns_release_proc(struct pid_namespace *ns);
+extern struct file *proc_ns_fget(int fd);
+extern struct proc_ns *get_proc_ns(struct inode *);
+extern int proc_alloc_inum(unsigned int *pino);
+extern void proc_free_inum(unsigned int inum);
+extern bool proc_ns_inode(struct inode *inode);
+
+#else /* CONFIG_PROC_FS */
+
+static inline int pid_ns_prepare_proc(struct pid_namespace *ns) { return 0; }
+static inline void pid_ns_release_proc(struct pid_namespace *ns) {}
+
+static inline struct file *proc_ns_fget(int fd)
+{
+ return ERR_PTR(-EINVAL);
+}
+
+static inline struct proc_ns *get_proc_ns(struct inode *inode) { return NULL; }
+
+static inline int proc_alloc_inum(unsigned int *inum)
+{
+ *inum = 1;
+ return 0;
+}
+static inline void proc_free_inum(unsigned int inum) {}
+static inline bool proc_ns_inode(struct inode *inode) { return false; }
+
+#endif /* CONFIG_PROC_FS */
+
+#endif /* _LINUX_PROC_NS_H */
diff --git a/init/version.c b/init/version.c
index 58170f1..1a4718e 100644
--- a/init/version.c
+++ b/init/version.c
@@ -12,7 +12,7 @@
#include <linux/utsname.h>
#include <generated/utsrelease.h>
#include <linux/version.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>

#ifndef CONFIG_KALLSYMS
#define version(a) Version_ ## a
diff --git a/ipc/msgutil.c b/ipc/msgutil.c
index 5df8e4b..8f02017 100644
--- a/ipc/msgutil.c
+++ b/ipc/msgutil.c
@@ -16,7 +16,7 @@
#include <linux/msg.h>
#include <linux/ipc_namespace.h>
#include <linux/utsname.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
#include <asm/uaccess.h>

#include "util.h"
diff --git a/ipc/namespace.c b/ipc/namespace.c
index 7c1fa45..7ee61bf 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -12,7 +12,7 @@
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/user_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>

#include "util.h"

diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index afc0456..364ceab 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -22,7 +22,7 @@
#include <linux/pid_namespace.h>
#include <net/net_namespace.h>
#include <linux/ipc_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
#include <linux/file.h>
#include <linux/syscalls.h>

@@ -241,7 +241,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
const struct proc_ns_operations *ops;
struct task_struct *tsk = current;
struct nsproxy *new_nsproxy;
- struct proc_inode *ei;
+ struct proc_ns *ei;
struct file *file;
int err;

@@ -250,7 +250,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
return PTR_ERR(file);

err = -EINVAL;
- ei = PROC_I(file_inode(file));
+ ei = get_proc_ns(file_inode(file));
ops = ei->ns_ops;
if (nstype && (ops->type != nstype))
goto out;
diff --git a/kernel/pid.c b/kernel/pid.c
index 047dc62..686255e 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -36,6 +36,7 @@
#include <linux/pid_namespace.h>
#include <linux/init_task.h>
#include <linux/syscalls.h>
+#include <linux/proc_ns.h>
#include <linux/proc_fs.h>

#define pid_hashfn(nr, ns) \
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index c1c3dc1..4af28a8 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -15,7 +15,7 @@
#include <linux/err.h>
#include <linux/acct.h>
#include <linux/slab.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
#include <linux/reboot.h>
#include <linux/export.h>

diff --git a/kernel/user.c b/kernel/user.c
index e81978e..5bbb919 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -16,7 +16,7 @@
#include <linux/interrupt.h>
#include <linux/export.h>
#include <linux/user_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>

/*
* userns count is 1 for root user, 1 for init_uts_ns,
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index b14f4d3..51855f5 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -9,7 +9,7 @@
#include <linux/nsproxy.h>
#include <linux/slab.h>
#include <linux/user_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
#include <linux/highuid.h>
#include <linux/cred.h>
#include <linux/securebits.h>
diff --git a/kernel/utsname.c b/kernel/utsname.c
index a47fc5d..2fc8576 100644
--- a/kernel/utsname.c
+++ b/kernel/utsname.c
@@ -15,7 +15,7 @@
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/user_namespace.h>
-#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>

static struct uts_namespace *create_uts_ns(void)
{
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 80e271d..f9765203 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -10,7 +10,8 @@
#include <linux/idr.h>
#include <linux/rculist.h>
#include <linux/nsproxy.h>
-#include <linux/proc_fs.h>
+#include <linux/fs.h>
+#include <linux/proc_ns.h>
#include <linux/file.h>
#include <linux/export.h>
#include <linux/user_namespace.h>
@@ -336,7 +337,7 @@ EXPORT_SYMBOL_GPL(__put_net);

struct net *get_net_ns_by_fd(int fd)
{
- struct proc_inode *ei;
+ struct proc_ns *ei;
struct file *file;
struct net *net;

@@ -344,7 +345,7 @@ struct net *get_net_ns_by_fd(int fd)
if (IS_ERR(file))
return ERR_CAST(file);

- ei = PROC_I(file_inode(file));
+ ei = get_proc_ns(file_inode(file));
if (ei->ns_ops == &netns_operations)
net = get_net(ei->ns);
else

2013-04-16 18:26:25

by David Howells

[permalink] [raw]
Subject: [PATCH 06/28] proc: Move proc_fd() to fs/proc/fd.h [RFC]

Move proc_fd() to fs/proc/fd.h.

Signed-off-by: David Howells <[email protected]>
---

fs/proc/fd.h | 5 +++++
fs/proc/internal.h | 5 -----
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/proc/fd.h b/fs/proc/fd.h
index cbb1d47..7c047f2 100644
--- a/fs/proc/fd.h
+++ b/fs/proc/fd.h
@@ -11,4 +11,9 @@ extern const struct inode_operations proc_fdinfo_inode_operations;

extern int proc_fd_permission(struct inode *inode, int mask);

+static inline int proc_fd(struct inode *inode)
+{
+ return PROC_I(inode)->fd;
+}
+
#endif /* __PROCFS_FD_H__ */
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index aaf2dd8..32d8f51 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -94,11 +94,6 @@ static inline struct task_struct *get_proc_task(struct inode *inode)
return get_pid_task(proc_pid(inode), PIDTYPE_PID);
}

-static inline int proc_fd(struct inode *inode)
-{
- return PROC_I(inode)->fd;
-}
-
static inline int task_dumpable(struct task_struct *task)
{
int dumpable = 0;

2013-04-16 18:34:10

by David Howells

[permalink] [raw]
Subject: [PATCH 04/28] proc: Supply PDE attribute setting accessor functions [RFC]

Supply accessor functions to set attributes in proc_dir_entry structs.

The following are supplied: proc_set_size() and proc_set_user().

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
---

arch/powerpc/kernel/proc_powerpc.c | 2 +-
arch/powerpc/platforms/pseries/reconfig.c | 2 +-
drivers/media/pci/ttpci/av7110_ir.c | 2 +-
drivers/net/irda/vlsi_ir.c | 2 +-
drivers/net/wireless/airo.c | 34 +++++++++--------------------
drivers/pci/proc.c | 2 +-
fs/proc/generic.c | 13 +++++++++++
include/linux/proc_fs.h | 5 ++++
kernel/configs.c | 2 +-
kernel/profile.c | 2 +-
net/netfilter/xt_recent.c | 3 +--
sound/core/info.c | 2 +-
12 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/arch/powerpc/kernel/proc_powerpc.c b/arch/powerpc/kernel/proc_powerpc.c
index 41d8ee9..feb8580 100644
--- a/arch/powerpc/kernel/proc_powerpc.c
+++ b/arch/powerpc/kernel/proc_powerpc.c
@@ -83,7 +83,7 @@ static int __init proc_ppc64_init(void)
&page_map_fops, vdso_data);
if (!pde)
return 1;
- pde->size = PAGE_SIZE;
+ proc_set_size(pde, PAGE_SIZE);

return 0;
}
diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
index d6491bd..f93cdf5 100644
--- a/arch/powerpc/platforms/pseries/reconfig.c
+++ b/arch/powerpc/platforms/pseries/reconfig.c
@@ -452,7 +452,7 @@ static int proc_ppc64_create_ofdt(void)

ent = proc_create("powerpc/ofdt", S_IWUSR, NULL, &ofdt_fops);
if (ent)
- ent->size = 0;
+ proc_set_size(ent, 0);

return 0;
}
diff --git a/drivers/media/pci/ttpci/av7110_ir.c b/drivers/media/pci/ttpci/av7110_ir.c
index eb82286..0e763a7 100644
--- a/drivers/media/pci/ttpci/av7110_ir.c
+++ b/drivers/media/pci/ttpci/av7110_ir.c
@@ -375,7 +375,7 @@ int av7110_ir_init(struct av7110 *av7110)
if (av_cnt == 1) {
e = proc_create("av7110_ir", S_IWUSR, NULL, &av7110_ir_proc_fops);
if (e)
- e->size = 4 + 256 * sizeof(u16);
+ proc_set_size(e, 4 + 256 * sizeof(u16));
}

tasklet_init(&av7110->ir.ir_tasklet, av7110_emit_key, (unsigned long) &av7110->ir);
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index e22cd4e..5f47584 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -1678,7 +1678,7 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
IRDA_WARNING("%s: failed to create proc entry\n",
__func__);
} else {
- ent->size = 0;
+ proc_set_size(ent, 0);
}
idev->proc_entry = ent;
}
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 66e398d..21d0233 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -4507,73 +4507,63 @@ static int setup_proc_entry( struct net_device *dev,
airo_entry);
if (!apriv->proc_entry)
goto fail;
- apriv->proc_entry->uid = proc_kuid;
- apriv->proc_entry->gid = proc_kgid;
+ proc_set_user(apriv->proc_entry, proc_kuid, proc_kgid);

/* Setup the StatsDelta */
entry = proc_create_data("StatsDelta", S_IRUGO & proc_perm,
apriv->proc_entry, &proc_statsdelta_ops, dev);
if (!entry)
goto fail_stats_delta;
- entry->uid = proc_kuid;
- entry->gid = proc_kgid;
+ proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the Stats */
entry = proc_create_data("Stats", S_IRUGO & proc_perm,
apriv->proc_entry, &proc_stats_ops, dev);
if (!entry)
goto fail_stats;
- entry->uid = proc_kuid;
- entry->gid = proc_kgid;
+ proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the Status */
entry = proc_create_data("Status", S_IRUGO & proc_perm,
apriv->proc_entry, &proc_status_ops, dev);
if (!entry)
goto fail_status;
- entry->uid = proc_kuid;
- entry->gid = proc_kgid;
+ proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the Config */
entry = proc_create_data("Config", proc_perm,
apriv->proc_entry, &proc_config_ops, dev);
if (!entry)
goto fail_config;
- entry->uid = proc_kuid;
- entry->gid = proc_kgid;
+ proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the SSID */
entry = proc_create_data("SSID", proc_perm,
apriv->proc_entry, &proc_SSID_ops, dev);
if (!entry)
goto fail_ssid;
- entry->uid = proc_kuid;
- entry->gid = proc_kgid;
+ proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the APList */
entry = proc_create_data("APList", proc_perm,
apriv->proc_entry, &proc_APList_ops, dev);
if (!entry)
goto fail_aplist;
- entry->uid = proc_kuid;
- entry->gid = proc_kgid;
+ proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the BSSList */
entry = proc_create_data("BSSList", proc_perm,
apriv->proc_entry, &proc_BSSList_ops, dev);
if (!entry)
goto fail_bsslist;
- entry->uid = proc_kuid;
- entry->gid = proc_kgid;
+ proc_set_user(entry, proc_kuid, proc_kgid);

/* Setup the WepKey */
entry = proc_create_data("WepKey", proc_perm,
apriv->proc_entry, &proc_wepkey_ops, dev);
if (!entry)
goto fail_wepkey;
- entry->uid = proc_kuid;
- entry->gid = proc_kgid;
-
+ proc_set_user(entry, proc_kuid, proc_kgid);
return 0;

fail_wepkey:
@@ -5695,10 +5685,8 @@ static int __init airo_init_module( void )

airo_entry = proc_mkdir_mode("driver/aironet", airo_perm, NULL);

- if (airo_entry) {
- airo_entry->uid = proc_kuid;
- airo_entry->gid = proc_kgid;
- }
+ if (airo_entry)
+ proc_set_user(airo_entry, proc_kuid, proc_kgid);

for (i = 0; i < 4 && io[i] && irq[i]; i++) {
airo_print_info("", "Trying to configure ISA adapter at irq=%d "
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 12e4fb5..7cde7c1 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -419,7 +419,7 @@ int pci_proc_attach_device(struct pci_dev *dev)
&proc_bus_pci_operations, dev);
if (!e)
return -ENOMEM;
- e->size = dev->cfg_size;
+ proc_set_size(e, dev->cfg_size);
dev->procent = e;

return 0;
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 1c07cad..5f6f6c3 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -498,6 +498,19 @@ out:
return NULL;
}
EXPORT_SYMBOL(proc_create_data);
+
+void proc_set_size(struct proc_dir_entry *de, loff_t size)
+{
+ de->size = size;
+}
+EXPORT_SYMBOL(proc_set_size);
+
+void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid)
+{
+ de->uid = uid;
+ de->gid = gid;
+}
+EXPORT_SYMBOL(proc_set_user);

static void free_proc_entry(struct proc_dir_entry *de)
{
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 805edac..28a4d7e 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -130,6 +130,9 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
struct proc_dir_entry *parent);

+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 struct file *proc_ns_fget(int fd);
extern bool proc_ns_inode(struct inode *inode);

@@ -158,6 +161,8 @@ static inline struct proc_dir_entry *proc_mkdir(const char *name,
struct proc_dir_entry *parent) {return NULL;}
static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
umode_t mode, struct proc_dir_entry *parent) { return NULL; }
+static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
+static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}

struct tty_driver;
static inline void proc_tty_register_driver(struct tty_driver *driver) {};
diff --git a/kernel/configs.c b/kernel/configs.c
index 42e8fa0..c18b1f1 100644
--- a/kernel/configs.c
+++ b/kernel/configs.c
@@ -79,7 +79,7 @@ static int __init ikconfig_init(void)
if (!entry)
return -ENOMEM;

- entry->size = kernel_config_data_size;
+ proc_set_size(entry, kernel_config_data_size);

return 0;
}
diff --git a/kernel/profile.c b/kernel/profile.c
index 524ce5e..0bf4007 100644
--- a/kernel/profile.c
+++ b/kernel/profile.c
@@ -600,7 +600,7 @@ int __ref create_proc_profile(void) /* false positive from hotcpu_notifier */
NULL, &proc_profile_operations);
if (!entry)
return 0;
- entry->size = (1+prof_len) * sizeof(atomic_t);
+ proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
hotcpu_notifier(profile_cpu_callback, 0);
return 0;
}
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 3db2d38..1e657cf 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -401,8 +401,7 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
ret = -ENOMEM;
goto out;
}
- pde->uid = uid;
- pde->gid = gid;
+ proc_set_user(pde, uid, gid);
#endif
spin_lock_bh(&recent_lock);
list_add_tail(&t->list, &recent_net->tables);
diff --git a/sound/core/info.c b/sound/core/info.c
index 3aa8864..c7f41c3 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -970,7 +970,7 @@ int snd_info_register(struct snd_info_entry * entry)
mutex_unlock(&info_mutex);
return -ENOMEM;
}
- p->size = entry->size;
+ proc_set_size(p, entry->size);
}
entry->p = p;
if (entry->parent)

2013-04-16 18:35:13

by David Howells

[permalink] [raw]
Subject: [PATCH 03/28] proc: Split kcore bits from linux/procfs.h into linux/kcore.h [RFC]

Split kcore bits from linux/procfs.h into linux/kcore.h.

Signed-off-by: David Howells <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
cc: [email protected]
---

arch/mips/mm/init.c | 1 +
arch/score/mm/init.c | 2 +-
arch/x86/mm/init_64.c | 1 +
fs/proc/kcore.c | 1 +
fs/proc/vmcore.c | 3 ++-
include/linux/kcore.h | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/proc_fs.h | 31 -------------------------------
7 files changed, 44 insertions(+), 33 deletions(-)
create mode 100644 include/linux/kcore.h

diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 6792925..60547b7 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -29,6 +29,7 @@
#include <linux/pfn.h>
#include <linux/hardirq.h>
#include <linux/gfp.h>
+#include <linux/kcore.h>

#include <asm/asm-offsets.h>
#include <asm/bootinfo.h>
diff --git a/arch/score/mm/init.c b/arch/score/mm/init.c
index cee6bce..8b6f796 100644
--- a/arch/score/mm/init.c
+++ b/arch/score/mm/init.c
@@ -31,7 +31,7 @@
#include <linux/mm.h>
#include <linux/mman.h>
#include <linux/pagemap.h>
-#include <linux/proc_fs.h>
+#include <linux/kcore.h>
#include <linux/sched.h>
#include <linux/initrd.h>

diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 474e28f..24ceda0 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -32,6 +32,7 @@
#include <linux/memory_hotplug.h>
#include <linux/nmi.h>
#include <linux/gfp.h>
+#include <linux/kcore.h>

#include <asm/processor.h>
#include <asm/bios_ebda.h>
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index eda6f01..8e6ce83 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -11,6 +11,7 @@

#include <linux/mm.h>
#include <linux/proc_fs.h>
+#include <linux/kcore.h>
#include <linux/user.h>
#include <linux/capability.h>
#include <linux/elf.h>
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index b870f74..38edddc 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -8,7 +8,7 @@
*/

#include <linux/mm.h>
-#include <linux/proc_fs.h>
+#include <linux/kcore.h>
#include <linux/user.h>
#include <linux/elf.h>
#include <linux/elfcore.h>
@@ -22,6 +22,7 @@
#include <linux/list.h>
#include <asm/uaccess.h>
#include <asm/io.h>
+#include "internal.h"

/* List representing chunks of contiguous memory areas and their offsets in
* vmcore file.
diff --git a/include/linux/kcore.h b/include/linux/kcore.h
new file mode 100644
index 0000000..d927622
--- /dev/null
+++ b/include/linux/kcore.h
@@ -0,0 +1,38 @@
+/*
+ * /proc/kcore definitions
+ */
+#ifndef _LINUX_KCORE_H
+#define _LINUX_KCORE_H
+
+enum kcore_type {
+ KCORE_TEXT,
+ KCORE_VMALLOC,
+ KCORE_RAM,
+ KCORE_VMEMMAP,
+ KCORE_OTHER,
+};
+
+struct kcore_list {
+ struct list_head list;
+ unsigned long addr;
+ size_t size;
+ int type;
+};
+
+struct vmcore {
+ struct list_head list;
+ unsigned long long paddr;
+ unsigned long long size;
+ loff_t offset;
+};
+
+#ifdef CONFIG_PROC_KCORE
+extern void kclist_add(struct kcore_list *, void *, size_t, int type);
+#else
+static inline
+void kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
+{
+}
+#endif
+
+#endif /* _LINUX_KCORE_H */
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index f5105f4..805edac 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -68,28 +68,6 @@ struct proc_dir_entry {
char name[];
};

-enum kcore_type {
- KCORE_TEXT,
- KCORE_VMALLOC,
- KCORE_RAM,
- KCORE_VMEMMAP,
- KCORE_OTHER,
-};
-
-struct kcore_list {
- struct list_head list;
- unsigned long addr;
- size_t size;
- int type;
-};
-
-struct vmcore {
- struct list_head list;
- unsigned long long paddr;
- unsigned long long size;
- loff_t offset;
-};
-
#ifdef CONFIG_PROC_FS

extern void proc_root_init(void);
@@ -214,15 +192,6 @@ static inline void proc_free_inum(unsigned int inum)
}
#endif /* CONFIG_PROC_FS */

-#if !defined(CONFIG_PROC_KCORE)
-static inline void
-kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
-{
-}
-#else
-extern void kclist_add(struct kcore_list *, void *, size_t, int type);
-#endif
-
struct nsproxy;
struct proc_ns_operations {
const char *name;

2013-04-16 21:32:34

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH 16/28] zoran: Don't print proc_dir_entry data in debug [RFC]

Em 16-04-2013 15:26, David Howells escreveu:
> Don't print proc_dir_entry data in debug as we're soon to have no direct
> access to the contents of the PDE. Print what was put in there instead.

Let me just apply this simple one, as it doesn't depend on the rest of the
patches in this series.

>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> ---
>
> drivers/media/pci/zoran/zoran_procfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/pci/zoran/zoran_procfs.c b/drivers/media/pci/zoran/zoran_procfs.c
> index 07a104d..f7ceee0 100644
> --- a/drivers/media/pci/zoran/zoran_procfs.c
> +++ b/drivers/media/pci/zoran/zoran_procfs.c
> @@ -201,7 +201,7 @@ zoran_proc_init (struct zoran *zr)
> dprintk(2,
> KERN_INFO
> "%s: procfs entry /proc/%s allocated. data=%p\n",
> - ZR_DEVNAME(zr), name, zr->zoran_proc->data);
> + ZR_DEVNAME(zr), name, zr);

It is just a debug message, so changing it looks fine.

> } else {
> dprintk(1, KERN_ERR "%s: Unable to initialise /proc/%s\n",
> ZR_DEVNAME(zr), name);
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2013-04-16 21:37:38

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH 03/28] proc: Split kcore bits from linux/procfs.h into linux/kcore.h [RFC]

On Tue, Apr 16, 2013 at 11:26 AM, David Howells <[email protected]> wrote:
> Split kcore bits from linux/procfs.h into linux/kcore.h.
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]

I have no seen any issue in this change. but why? Is there any
motivation rather than cleanup?

2013-04-16 21:37:58

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH 04/28] proc: Supply PDE attribute setting accessor functions [RFC]

Em 16-04-2013 15:26, David Howells escreveu:
> Supply accessor functions to set attributes in proc_dir_entry structs.
>
> The following are supplied: proc_set_size() and proc_set_user().
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> ---
>
> arch/powerpc/kernel/proc_powerpc.c | 2 +-
> arch/powerpc/platforms/pseries/reconfig.c | 2 +-
> drivers/media/pci/ttpci/av7110_ir.c | 2 +-

Weird that av7110 IR uses /proc... Well, this is an old, obsolete driver for
hardware that is not sold anymore for a long time... So, be it.

Acked-by: Mauro Carvalho Chehab <[email protected]>

> drivers/net/irda/vlsi_ir.c | 2 +-
> drivers/net/wireless/airo.c | 34 +++++++++--------------------
> drivers/pci/proc.c | 2 +-
> fs/proc/generic.c | 13 +++++++++++
> include/linux/proc_fs.h | 5 ++++
> kernel/configs.c | 2 +-
> kernel/profile.c | 2 +-
> net/netfilter/xt_recent.c | 3 +--
> sound/core/info.c | 2 +-
> 12 files changed, 38 insertions(+), 33 deletions(-)
>
> diff --git a/arch/powerpc/kernel/proc_powerpc.c b/arch/powerpc/kernel/proc_powerpc.c
> index 41d8ee9..feb8580 100644
> --- a/arch/powerpc/kernel/proc_powerpc.c
> +++ b/arch/powerpc/kernel/proc_powerpc.c
> @@ -83,7 +83,7 @@ static int __init proc_ppc64_init(void)
> &page_map_fops, vdso_data);
> if (!pde)
> return 1;
> - pde->size = PAGE_SIZE;
> + proc_set_size(pde, PAGE_SIZE);
>
> return 0;
> }
> diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
> index d6491bd..f93cdf5 100644
> --- a/arch/powerpc/platforms/pseries/reconfig.c
> +++ b/arch/powerpc/platforms/pseries/reconfig.c
> @@ -452,7 +452,7 @@ static int proc_ppc64_create_ofdt(void)
>
> ent = proc_create("powerpc/ofdt", S_IWUSR, NULL, &ofdt_fops);
> if (ent)
> - ent->size = 0;
> + proc_set_size(ent, 0);
>
> return 0;
> }
> diff --git a/drivers/media/pci/ttpci/av7110_ir.c b/drivers/media/pci/ttpci/av7110_ir.c
> index eb82286..0e763a7 100644
> --- a/drivers/media/pci/ttpci/av7110_ir.c
> +++ b/drivers/media/pci/ttpci/av7110_ir.c
> @@ -375,7 +375,7 @@ int av7110_ir_init(struct av7110 *av7110)
> if (av_cnt == 1) {
> e = proc_create("av7110_ir", S_IWUSR, NULL, &av7110_ir_proc_fops);
> if (e)
> - e->size = 4 + 256 * sizeof(u16);
> + proc_set_size(e, 4 + 256 * sizeof(u16));
> }
>
> tasklet_init(&av7110->ir.ir_tasklet, av7110_emit_key, (unsigned long) &av7110->ir);
> diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
> index e22cd4e..5f47584 100644
> --- a/drivers/net/irda/vlsi_ir.c
> +++ b/drivers/net/irda/vlsi_ir.c
> @@ -1678,7 +1678,7 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> IRDA_WARNING("%s: failed to create proc entry\n",
> __func__);
> } else {
> - ent->size = 0;
> + proc_set_size(ent, 0);
> }
> idev->proc_entry = ent;
> }
> diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
> index 66e398d..21d0233 100644
> --- a/drivers/net/wireless/airo.c
> +++ b/drivers/net/wireless/airo.c
> @@ -4507,73 +4507,63 @@ static int setup_proc_entry( struct net_device *dev,
> airo_entry);
> if (!apriv->proc_entry)
> goto fail;
> - apriv->proc_entry->uid = proc_kuid;
> - apriv->proc_entry->gid = proc_kgid;
> + proc_set_user(apriv->proc_entry, proc_kuid, proc_kgid);
>
> /* Setup the StatsDelta */
> entry = proc_create_data("StatsDelta", S_IRUGO & proc_perm,
> apriv->proc_entry, &proc_statsdelta_ops, dev);
> if (!entry)
> goto fail_stats_delta;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Stats */
> entry = proc_create_data("Stats", S_IRUGO & proc_perm,
> apriv->proc_entry, &proc_stats_ops, dev);
> if (!entry)
> goto fail_stats;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Status */
> entry = proc_create_data("Status", S_IRUGO & proc_perm,
> apriv->proc_entry, &proc_status_ops, dev);
> if (!entry)
> goto fail_status;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Config */
> entry = proc_create_data("Config", proc_perm,
> apriv->proc_entry, &proc_config_ops, dev);
> if (!entry)
> goto fail_config;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the SSID */
> entry = proc_create_data("SSID", proc_perm,
> apriv->proc_entry, &proc_SSID_ops, dev);
> if (!entry)
> goto fail_ssid;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the APList */
> entry = proc_create_data("APList", proc_perm,
> apriv->proc_entry, &proc_APList_ops, dev);
> if (!entry)
> goto fail_aplist;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the BSSList */
> entry = proc_create_data("BSSList", proc_perm,
> apriv->proc_entry, &proc_BSSList_ops, dev);
> if (!entry)
> goto fail_bsslist;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the WepKey */
> entry = proc_create_data("WepKey", proc_perm,
> apriv->proc_entry, &proc_wepkey_ops, dev);
> if (!entry)
> goto fail_wepkey;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> -
> + proc_set_user(entry, proc_kuid, proc_kgid);
> return 0;
>
> fail_wepkey:
> @@ -5695,10 +5685,8 @@ static int __init airo_init_module( void )
>
> airo_entry = proc_mkdir_mode("driver/aironet", airo_perm, NULL);
>
> - if (airo_entry) {
> - airo_entry->uid = proc_kuid;
> - airo_entry->gid = proc_kgid;
> - }
> + if (airo_entry)
> + proc_set_user(airo_entry, proc_kuid, proc_kgid);
>
> for (i = 0; i < 4 && io[i] && irq[i]; i++) {
> airo_print_info("", "Trying to configure ISA adapter at irq=%d "
> diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
> index 12e4fb5..7cde7c1 100644
> --- a/drivers/pci/proc.c
> +++ b/drivers/pci/proc.c
> @@ -419,7 +419,7 @@ int pci_proc_attach_device(struct pci_dev *dev)
> &proc_bus_pci_operations, dev);
> if (!e)
> return -ENOMEM;
> - e->size = dev->cfg_size;
> + proc_set_size(e, dev->cfg_size);
> dev->procent = e;
>
> return 0;
> diff --git a/fs/proc/generic.c b/fs/proc/generic.c
> index 1c07cad..5f6f6c3 100644
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -498,6 +498,19 @@ out:
> return NULL;
> }
> EXPORT_SYMBOL(proc_create_data);
> +
> +void proc_set_size(struct proc_dir_entry *de, loff_t size)
> +{
> + de->size = size;
> +}
> +EXPORT_SYMBOL(proc_set_size);
> +
> +void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid)
> +{
> + de->uid = uid;
> + de->gid = gid;
> +}
> +EXPORT_SYMBOL(proc_set_user);
>
> static void free_proc_entry(struct proc_dir_entry *de)
> {
> diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
> index 805edac..28a4d7e 100644
> --- a/include/linux/proc_fs.h
> +++ b/include/linux/proc_fs.h
> @@ -130,6 +130,9 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
> extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
> struct proc_dir_entry *parent);
>
> +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 struct file *proc_ns_fget(int fd);
> extern bool proc_ns_inode(struct inode *inode);
>
> @@ -158,6 +161,8 @@ static inline struct proc_dir_entry *proc_mkdir(const char *name,
> struct proc_dir_entry *parent) {return NULL;}
> static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
> umode_t mode, struct proc_dir_entry *parent) { return NULL; }
> +static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
> +static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
>
> struct tty_driver;
> static inline void proc_tty_register_driver(struct tty_driver *driver) {};
> diff --git a/kernel/configs.c b/kernel/configs.c
> index 42e8fa0..c18b1f1 100644
> --- a/kernel/configs.c
> +++ b/kernel/configs.c
> @@ -79,7 +79,7 @@ static int __init ikconfig_init(void)
> if (!entry)
> return -ENOMEM;
>
> - entry->size = kernel_config_data_size;
> + proc_set_size(entry, kernel_config_data_size);
>
> return 0;
> }
> diff --git a/kernel/profile.c b/kernel/profile.c
> index 524ce5e..0bf4007 100644
> --- a/kernel/profile.c
> +++ b/kernel/profile.c
> @@ -600,7 +600,7 @@ int __ref create_proc_profile(void) /* false positive from hotcpu_notifier */
> NULL, &proc_profile_operations);
> if (!entry)
> return 0;
> - entry->size = (1+prof_len) * sizeof(atomic_t);
> + proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
> hotcpu_notifier(profile_cpu_callback, 0);
> return 0;
> }
> diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
> index 3db2d38..1e657cf 100644
> --- a/net/netfilter/xt_recent.c
> +++ b/net/netfilter/xt_recent.c
> @@ -401,8 +401,7 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
> ret = -ENOMEM;
> goto out;
> }
> - pde->uid = uid;
> - pde->gid = gid;
> + proc_set_user(pde, uid, gid);
> #endif
> spin_lock_bh(&recent_lock);
> list_add_tail(&t->list, &recent_net->tables);
> diff --git a/sound/core/info.c b/sound/core/info.c
> index 3aa8864..c7f41c3 100644
> --- a/sound/core/info.c
> +++ b/sound/core/info.c
> @@ -970,7 +970,7 @@ int snd_info_register(struct snd_info_entry * entry)
> mutex_unlock(&info_mutex);
> return -ENOMEM;
> }
> - p->size = entry->size;
> + proc_set_size(p, entry->size);
> }
> entry->p = p;
> if (entry->parent)
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2013-04-16 21:40:24

by Mauro Carvalho Chehab

[permalink] [raw]
Subject: Re: [PATCH 10/28] proc: Add proc_mkdir_data() [RFC]

Em 16-04-2013 15:26, David Howells escreveu:
> Add proc_mkdir_data() to allow procfs directories to be created that are
> annotated at the time of creation with private data rather than doing this
> post-creation. This means no access is then required to the proc_dir_entry
> struct to set this.
>
> Signed-off-by: David Howells <[email protected]>
> cc: Neela Syam Kolli <[email protected]>
> cc: Jerry Chuang <[email protected]>
> cc: Mauro Carvalho Chehab <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> ---
>
> drivers/message/i2o/i2o_proc.c | 8 ++------
> drivers/scsi/megaraid.c | 4 ++--
> drivers/staging/rtl8192u/r8192U_core.c | 3 +--

For the three patches that touch rtl8192u (patches 10, 12 and 14):

Acked-by: Mauro Carvalho Chehab <[email protected]>

> fs/proc/generic.c | 30 ++++++++++++------------------
> include/linux/proc_fs.h | 11 ++++++++---
> 5 files changed, 25 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
> index 70a840f..b7d87cd 100644
> --- a/drivers/message/i2o/i2o_proc.c
> +++ b/drivers/message/i2o/i2o_proc.c
> @@ -1913,14 +1913,12 @@ static void i2o_proc_device_add(struct proc_dir_entry *dir,
>
> osm_debug("adding device /proc/i2o/%s/%s\n", dev->iop->name, buff);
>
> - devdir = proc_mkdir(buff, dir);
> + devdir = proc_mkdir_data(buff, 0, dir, dev);
> if (!devdir) {
> osm_warn("Could not allocate procdir!\n");
> return;
> }
>
> - devdir->data = dev;
> -
> i2o_proc_create_entries(devdir, generic_dev_entries, dev);
>
> /* Inform core that we want updates about this device's status */
> @@ -1954,12 +1952,10 @@ static int i2o_proc_iop_add(struct proc_dir_entry *dir,
>
> osm_debug("adding IOP /proc/i2o/%s\n", c->name);
>
> - iopdir = proc_mkdir(c->name, dir);
> + iopdir = proc_mkdir_data(c->name, 0, dir, c);
> if (!iopdir)
> return -1;
>
> - iopdir->data = c;
> -
> i2o_proc_create_entries(iopdir, i2o_proc_generic_iop_entries, c);
>
> list_for_each_entry(dev, &c->devices, list)
> diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
> index a1c90bd..ef3384d 100644
> --- a/drivers/scsi/megaraid.c
> +++ b/drivers/scsi/megaraid.c
> @@ -2818,12 +2818,12 @@ mega_create_proc_entry(int index, struct proc_dir_entry *parent)
>
> sprintf(string, "hba%d", adapter->host->host_no);
>
> - dir = adapter->controller_proc_dir_entry = proc_mkdir(string, parent);
> + dir = adapter->controller_proc_dir_entry =
> + proc_mkdir_data(string, 0, parent, adapter);
> if(!dir) {
> printk(KERN_WARNING "\nmegaraid: proc_mkdir failed\n");
> return;
> }
> - dir->data = adapter;
>
> for (f = mega_proc_files; f->name; f++) {
> de = proc_create_data(f->name, S_IRUSR, dir, &mega_proc_fops,
> diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
> index 433c3df..d81d7d5 100644
> --- a/drivers/staging/rtl8192u/r8192U_core.c
> +++ b/drivers/staging/rtl8192u/r8192U_core.c
> @@ -672,13 +672,12 @@ void rtl8192_proc_init_one(struct net_device *dev)
> struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
>
> if (rtl8192_proc) {
> - priv->dir_dev = proc_mkdir(dev->name, rtl8192_proc);
> + priv->dir_dev = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
> if (!priv->dir_dev) {
> RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
> dev->name);
> return;
> }
> - priv->dir_dev->data = dev;
>
> for (f = rtl8192_proc_files; f->name[0]; f++) {
> if (!proc_create_data(f->name, S_IFREG | S_IRUGO,
> diff --git a/fs/proc/generic.c b/fs/proc/generic.c
> index 5f6f6c3..4074da5 100644
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -428,13 +428,17 @@ struct proc_dir_entry *proc_symlink(const char *name,
> }
> EXPORT_SYMBOL(proc_symlink);
>
> -struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
> - struct proc_dir_entry *parent)
> +struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
> + struct proc_dir_entry *parent, void *data)
> {
> struct proc_dir_entry *ent;
>
> + if (mode == 0)
> + mode = S_IRUGO | S_IXUGO;
> +
> ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
> if (ent) {
> + ent->data = data;
> if (proc_register(parent, ent) < 0) {
> kfree(ent);
> ent = NULL;
> @@ -442,29 +446,19 @@ struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
> }
> return ent;
> }
> -EXPORT_SYMBOL(proc_mkdir_mode);
> +EXPORT_SYMBOL_GPL(proc_mkdir_data);
>
> -struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
> - struct proc_dir_entry *parent)
> +struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
> + struct proc_dir_entry *parent)
> {
> - struct proc_dir_entry *ent;
> -
> - ent = __proc_create(&parent, name, S_IFDIR | S_IRUGO | S_IXUGO, 2);
> - if (ent) {
> - ent->data = net;
> - if (proc_register(parent, ent) < 0) {
> - kfree(ent);
> - ent = NULL;
> - }
> - }
> - return ent;
> + return proc_mkdir_data(name, mode, parent, NULL);
> }
> -EXPORT_SYMBOL_GPL(proc_net_mkdir);
> +EXPORT_SYMBOL(proc_mkdir_mode);
>
> struct proc_dir_entry *proc_mkdir(const char *name,
> struct proc_dir_entry *parent)
> {
> - return proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
> + return proc_mkdir_data(name, 0, parent, NULL);
> }
> EXPORT_SYMBOL(proc_mkdir);
>
> diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
> index 80d9e24..e5d8f69 100644
> --- a/include/linux/proc_fs.h
> +++ b/include/linux/proc_fs.h
> @@ -73,6 +73,8 @@ extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
> extern struct proc_dir_entry *proc_symlink(const char *,
> struct proc_dir_entry *, const char *);
> extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
> +extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
> + struct proc_dir_entry *, void *);
> extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
> struct proc_dir_entry *parent);
>
> @@ -82,9 +84,6 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
> return proc_create_data(name, mode, parent, proc_fops, NULL);
> }
>
> -extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
> - struct proc_dir_entry *parent);
> -
> extern void proc_set_size(struct proc_dir_entry *, loff_t);
> extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
> #else
> @@ -153,4 +152,10 @@ static inline void *PDE_DATA(const struct inode *inode)
> return PROC_I(inode)->pde->data;
> }
>
> +static inline struct proc_dir_entry *proc_net_mkdir(
> + struct net *net, const char *name, struct proc_dir_entry *parent)
> +{
> + return proc_mkdir_data(name, 0, parent, net);
> +}
> +
> #endif /* _LINUX_PROC_FS_H */
>

2013-04-16 22:07:51

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 03/28] proc: Split kcore bits from linux/procfs.h into linux/kcore.h [RFC]


KOSAKI Motohiro <[email protected]> wrote:

> I have no seen any issue in this change. but why? Is there any
> motivation rather than cleanup?

Stopping stuff mucking about with the internals of procfs incorrectly
(sometimes because the internals of procfs have changed, but the drivers
haven't).

David

2013-04-16 22:14:12

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH 03/28] proc: Split kcore bits from linux/procfs.h into linux/kcore.h [RFC]

On Tue, Apr 16, 2013 at 3:07 PM, David Howells <[email protected]> wrote:
>
> KOSAKI Motohiro <[email protected]> wrote:
>
>> I have no seen any issue in this change. but why? Is there any
>> motivation rather than cleanup?
>
> Stopping stuff mucking about with the internals of procfs incorrectly
> (sometimes because the internals of procfs have changed, but the drivers
> haven't).

OK, thank you for explanation.

Acked-by: KOSAKI Motohiro <[email protected]>

2013-04-16 22:37:11

by Harald Welte

[permalink] [raw]
Subject: Re: [PATCH 24/28] proc: Supply an accessor to get the name in a proc_dir_entry struct [RFC]

Hi David,

On Tue, Apr 16, 2013 at 07:27:25PM +0100, David Howells wrote:
> This is only needed by the xt_hashlimit netfilter module as that appears to
> use the name in the pde to save a label in the xt_hashlimit_htable struct -
> which will be a problem if CONFIG_PROC_FS=n.

I don't know the larger context of this patch (and am not follwing
filesystem related work in general), but at least from the xt_hashlimit
point of view this of course looks fine. We can always wrap direct
accesses to structure members behind an API call.

For consistency reasons 'proc_get_name()' might be a better name than
get_proc_name(), but that's probably a matter of taste.

Pleaes note that I'm only the original author but not the active
maintainer of the xt_hashlimit (formerly ipt_hashlimit) code.

Regards,
Harald
--
- Harald Welte <[email protected]> http://netfilter.org/
============================================================================
"Fragmentation is like classful addressing -- an interesting early
architectural error that shows how much experimentation was going
on while IP was being designed." -- Paul Vixie

2013-04-17 00:57:16

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 01/28] Include missing linux/slab.h inclusions [RFC]

On Tue, Apr 16, 2013 at 07:25:54PM +0100, David Howells wrote:
> Include missing linux/slab.h inclusions where the source file is currently
> expecting to get kmalloc() and co. through linux/proc_fs.h.
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> ---
>

Acked-by: Greg Kroah-Hartman <[email protected]>

2013-04-17 00:58:06

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 09/28] proc: Move some bits from linux/proc_fs.h to linux/{of.h, signal.h, tty.h} [RFC]

On Tue, Apr 16, 2013 at 07:26:26PM +0100, David Howells wrote:
> Move some bits from linux/proc_fs.h to linux/of.h, signal.h and tty.h.
>
> Also move proc_tty_init() and proc_device_tree_init() to fs/proc/internal.h as
> they're internal to procfs.
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: Greg Kroah-Hartman <[email protected]>
> cc: Jri Slaby <[email protected]>
> ---

Acked-by: Greg Kroah-Hartman <[email protected]>

2013-04-17 00:59:07

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 10/28] proc: Add proc_mkdir_data() [RFC]

On Tue, Apr 16, 2013 at 07:26:30PM +0100, David Howells wrote:
> Add proc_mkdir_data() to allow procfs directories to be created that are
> annotated at the time of creation with private data rather than doing this
> post-creation. This means no access is then required to the proc_dir_entry
> struct to set this.
>
> Signed-off-by: David Howells <[email protected]>
> cc: Neela Syam Kolli <[email protected]>
> cc: Jerry Chuang <[email protected]>
> cc: Mauro Carvalho Chehab <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> ---

Acked-by: Greg Kroah-Hartman <[email protected]>

2013-04-17 00:59:43

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 11/28] rtl8187se: Use a dir under /proc/net/r8180/ [RFC]

On Tue, Apr 16, 2013 at 07:26:35PM +0100, David Howells wrote:
> Create a dir under /proc/net/r8180/ named for the device and create that
> device's files under there. This means that there won't be a problem for
> multiple devices in the system (if such is possible) and it means we don't
> need to save the 'device directory' PDE any more as we can just do a proc
> subtree removal.
>
> Signed-off-by: David Howells <[email protected]>
> cc: Maxim Mikityanskiy <[email protected]>
> cc: YAMANE Toshiaki <[email protected]>
> cc: [email protected]
> cc: [email protected]

Acked-by: Greg Kroah-Hartman <[email protected]>

2013-04-17 01:00:38

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 12/28] rtl8192u: Don't need to save device proc dir PDE [RFC]

On Tue, Apr 16, 2013 at 07:26:39PM +0100, David Howells wrote:
> Don't need to save the PDE of a directory created under /proc/net/rtl8192/ as
> we can use proc subtree deletion to get rid of it and all its children.
>
> Signed-off-by: David Howells <[email protected]>
> cc: Jerry Chuang <[email protected]>
> cc: Mauro Carvalho Chehab <[email protected]>
> cc: [email protected]
> cc: [email protected]

Acked-by: Greg Kroah-Hartman <[email protected]>

2013-04-17 01:01:18

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 14/28] proc: Supply an accessor for getting the data from a PDE's parent [RFC]

On Tue, Apr 16, 2013 at 07:26:46PM +0100, David Howells wrote:
> 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 <[email protected]>
> cc: Jerry Chuang <[email protected]>
> cc: Mauro Carvalho Chehab <[email protected]>
> cc: Maxim Mikityanskiy <[email protected]>
> cc: YAMANE Toshiaki <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]

Acked-by: Greg Kroah-Hartman <[email protected]>

2013-04-17 01:02:29

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 21/28] dgrp: Clean up the use of procfs [RFC]

On Tue, Apr 16, 2013 at 07:27:13PM +0100, David Howells wrote:
> Clean up the use of procfs by the dgrp driver:
>
> (1) Use remove_proc_subtree() for the mass slaughter of a subdir full of proc
> files rather than doing it manually.
>
> (2) When creating files, only call ID_TO_CHAR() once to generate the name.
>
> Signed-off-by : David Howells <[email protected]>
> cc: Bill Pemberton <[email protected]>
> cc: Tommi Rantala <[email protected]>
> cc: [email protected]

Acked-by: Greg Kroah-Hartman <[email protected]>

2013-04-17 01:53:31

by Zefan Li

[permalink] [raw]
Subject: Re: [PATCH 25/28] proc: Supply an accessor to get the process ID associated with some proc files [RFC]

On 2013/4/17 2:27, David Howells wrote:
> Supply an accessor to get the process ID associated with some proc files and
> directories (get_proc_pid()).
>
> Signed-off-by: David Howells <[email protected]>
> cc: Tejun Heo <[email protected]>
> cc: Li Zefan <[email protected]>
> cc: [email protected]
> cc: [email protected]

Acked-by: Li Zefan <[email protected]>

2013-04-17 09:13:47

by Ralf Baechle

[permalink] [raw]
Subject: Re: [PATCH 03/28] proc: Split kcore bits from linux/procfs.h into linux/kcore.h [RFC]

On Tue, Apr 16, 2013 at 07:26:01PM +0100, David Howells wrote:

Acked-by: Ralf Baechle <[email protected]>

Ralf

2013-04-17 14:59:28

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 09/28] proc: Move some bits from linux/proc_fs.h to linux/{of.h, signal.h, tty.h} [RFC]

On Tue, 16 Apr 2013 19:26:26 +0100, David Howells <[email protected]> wrote:
> Move some bits from linux/proc_fs.h to linux/of.h, signal.h and tty.h.
>
> Also move proc_tty_init() and proc_device_tree_init() to fs/proc/internal.h as
> they're internal to procfs.
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: Greg Kroah-Hartman <[email protected]>
> cc: Jri Slaby <[email protected]>

Acked-by: Grant Likely <[email protected]>

> ---
>
> fs/proc/internal.h | 16 ++++++++++++++++
> include/linux/of.h | 10 ++++++++++
> include/linux/proc_fs.h | 37 -------------------------------------
> include/linux/signal.h | 5 +++++
> include/linux/tty.h | 7 +++++++
> 5 files changed, 38 insertions(+), 37 deletions(-)
>
> diff --git a/fs/proc/internal.h b/fs/proc/internal.h
> index 32d8f51..c529b5f 100644
> --- a/fs/proc/internal.h
> +++ b/fs/proc/internal.h
> @@ -198,3 +198,19 @@ extern const struct inode_operations proc_ns_dir_inode_operations;
> extern const struct file_operations proc_ns_dir_operations;
>
> extern int proc_setup_self(struct super_block *);
> +
> +/*
> + * proc_devtree.c
> + */
> +#ifdef CONFIG_PROC_DEVICETREE
> +extern void proc_device_tree_init(void);
> +#endif /* CONFIG_PROC_DEVICETREE */
> +
> +/*
> + * proc_tty.c
> + */
> +#ifdef CONFIG_TTY
> +extern void proc_tty_init(void);
> +#else
> +static inline void proc_tty_init(void) {}
> +#endif
> diff --git a/include/linux/of.h b/include/linux/of.h
> index a0f1292..2d25ff8 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -540,4 +540,14 @@ static inline int of_property_read_u32(const struct device_node *np,
> return of_property_read_u32_array(np, propname, out_value, 1);
> }
>
> +#if defined(CONFIG_PROC_FS) && defined(CONFIG_PROC_DEVICETREE)
> +extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
> +extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
> +extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
> + struct property *prop);
> +extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
> + struct property *newprop,
> + struct property *oldprop);
> +#endif
> +
> #endif /* _LINUX_OF_H */
> diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
> index 3377224..80d9e24 100644
> --- a/include/linux/proc_fs.h
> +++ b/include/linux/proc_fs.h
> @@ -70,36 +70,6 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
> extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
> extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
>
> -
> -/*
> - * proc_tty.c
> - */
> -struct tty_driver;
> -#ifdef CONFIG_TTY
> -extern void proc_tty_init(void);
> -#else
> -static inline void proc_tty_init(void)
> -{ }
> -#endif
> -extern void proc_tty_register_driver(struct tty_driver *driver);
> -extern void proc_tty_unregister_driver(struct tty_driver *driver);
> -
> -/*
> - * proc_devtree.c
> - */
> -#ifdef CONFIG_PROC_DEVICETREE
> -struct device_node;
> -struct property;
> -extern void proc_device_tree_init(void);
> -extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
> -extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
> -extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
> - struct property *prop);
> -extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
> - struct property *newprop,
> - struct property *oldprop);
> -#endif /* CONFIG_PROC_DEVICETREE */
> -
> extern struct proc_dir_entry *proc_symlink(const char *,
> struct proc_dir_entry *, const char *);
> extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
> @@ -143,10 +113,6 @@ static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
> static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
> static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
>
> -struct tty_driver;
> -static inline void proc_tty_register_driver(struct tty_driver *driver) {};
> -static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
> -
> #endif /* CONFIG_PROC_FS */
>
>
> @@ -187,7 +153,4 @@ static inline void *PDE_DATA(const struct inode *inode)
> return PROC_I(inode)->pde->data;
> }
>
> -#include <linux/signal.h>
> -
> -void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
> #endif /* _LINUX_PROC_FS_H */
> diff --git a/include/linux/signal.h b/include/linux/signal.h
> index a2dcb94..1135e36 100644
> --- a/include/linux/signal.h
> +++ b/include/linux/signal.h
> @@ -434,4 +434,9 @@ void signals_init(void);
> int restore_altstack(const stack_t __user *);
> int __save_altstack(stack_t __user *, unsigned long);
>
> +#ifdef CONFIG_PROC_FS
> +struct seq_file;
> +extern void render_sigset_t(struct seq_file *, const char *, sigset_t *);
> +#endif
> +
> #endif /* _LINUX_SIGNAL_H */
> diff --git a/include/linux/tty.h b/include/linux/tty.h
> index c75d886..e34605b 100644
> --- a/include/linux/tty.h
> +++ b/include/linux/tty.h
> @@ -658,5 +658,12 @@ do { \
> finish_wait(&wq, &__wait); \
> } while (0)
>
> +#ifdef CONFIG_PROC_FS
> +extern void proc_tty_register_driver(struct tty_driver *);
> +extern void proc_tty_unregister_driver(struct tty_driver *);
> +#else
> +static inline void proc_tty_register_driver(struct tty_driver *) {}
> +static inline void proc_tty_unregister_driver(struct tty_driver *) {}
> +#endif
>
> #endif
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

--
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

2013-04-17 15:03:11

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH 26/28] proc: Supply a function to remove a proc entry by PDE [RFC]

On Tue, 16 Apr 2013 19:27:34 +0100, David Howells <[email protected]> wrote:
> Supply a function (proc_remove()) to remove a proc entry (and any subtree
> rooted there) by proc_dir_entry pointer rather than by name and (optionally)
> root dir entry pointer. This allows us to eliminate all remaining pde->name
> accesses outside of procfs.
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]

Looks okay to me. For the OF portion:

Acked-by: Grant Likely <[email protected]>

> ---
>
> drivers/acpi/sbs.c | 21 ++++-----------------
> drivers/char/ipmi/ipmi_msghandler.c | 2 +-
> drivers/misc/sgi-gru/gruprocfs.c | 2 +-
> drivers/of/base.c | 11 +----------
> drivers/pci/proc.c | 12 +++---------
> fs/proc/generic.c | 7 +++++++
> fs/proc/vmcore.c | 2 +-
> include/linux/proc_fs.h | 2 ++
> kernel/irq/proc.c | 6 +-----
> net/8021q/vlanproc.c | 9 ++-------
> net/core/pktgen.c | 6 ++----
> net/ipv4/netfilter/ipt_CLUSTERIP.c | 4 ++--
> net/ipv6/proc.c | 3 +--
> net/netfilter/xt_hashlimit.c | 4 ++--
> sound/core/info.c | 19 +++++--------------
> 15 files changed, 35 insertions(+), 75 deletions(-)
>
> diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
> index a296e08..b6241ee 100644
> --- a/drivers/acpi/sbs.c
> +++ b/drivers/acpi/sbs.c
> @@ -521,19 +521,6 @@ acpi_sbs_add_fs(struct proc_dir_entry **dir,
> return 0;
> }
>
> -static void
> -acpi_sbs_remove_fs(struct proc_dir_entry **dir,
> - struct proc_dir_entry *parent_dir)
> -{
> - if (*dir) {
> - remove_proc_entry(ACPI_SBS_FILE_INFO, *dir);
> - remove_proc_entry(ACPI_SBS_FILE_STATE, *dir);
> - remove_proc_entry(ACPI_SBS_FILE_ALARM, *dir);
> - remove_proc_entry((*dir)->name, parent_dir);
> - *dir = NULL;
> - }
> -}
> -
> /* Smart Battery Interface */
> static struct proc_dir_entry *acpi_battery_dir = NULL;
>
> @@ -836,8 +823,8 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
> power_supply_unregister(&battery->bat);
> }
> #ifdef CONFIG_ACPI_PROCFS_POWER
> - if (battery->proc_entry)
> - acpi_sbs_remove_fs(&battery->proc_entry, acpi_battery_dir);
> + proc_remove(battery->proc_entry);
> + battery->proc_entry = NULL;
> #endif
> }
>
> @@ -873,8 +860,8 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
> if (sbs->charger.dev)
> power_supply_unregister(&sbs->charger);
> #ifdef CONFIG_ACPI_PROCFS_POWER
> - if (sbs->charger_entry)
> - acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir);
> + proc_remove(sbs->charger_entry);
> + sbs->charger_entry = NULL;
> #endif
> }
>
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index 1420bbb..4d439d2 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -4541,7 +4541,7 @@ static void __exit cleanup_ipmi(void)
> del_timer_sync(&ipmi_timer);
>
> #ifdef CONFIG_PROC_FS
> - remove_proc_entry(proc_ipmi_root->name, NULL);
> + proc_remove(proc_ipmi_root);
> #endif /* CONFIG_PROC_FS */
>
> driver_unregister(&ipmidriver.driver);
> diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
> index 950dbe9..797d796 100644
> --- a/drivers/misc/sgi-gru/gruprocfs.c
> +++ b/drivers/misc/sgi-gru/gruprocfs.c
> @@ -355,7 +355,7 @@ static void delete_proc_files(void)
> for (p = proc_files; p->name; p++)
> if (p->entry)
> remove_proc_entry(p->name, proc_gru);
> - remove_proc_entry("gru", proc_gru->parent);
> + proc_remove(proc_gru);
> }
> }
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 321d3ef..9c70436 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1452,16 +1452,7 @@ int of_attach_node(struct device_node *np)
> #ifdef CONFIG_PROC_DEVICETREE
> static void of_remove_proc_dt_entry(struct device_node *dn)
> {
> - struct device_node *parent = dn->parent;
> - struct property *prop = dn->properties;
> -
> - while (prop) {
> - remove_proc_entry(prop->name, dn->pde);
> - prop = prop->next;
> - }
> -
> - if (dn->pde)
> - remove_proc_entry(dn->pde->name, parent->pde);
> + proc_remove(dn->pde);
> }
> #else
> static void of_remove_proc_dt_entry(struct device_node *dn)
> diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
> index 7cde7c1..0812608 100644
> --- a/drivers/pci/proc.c
> +++ b/drivers/pci/proc.c
> @@ -427,20 +427,14 @@ int pci_proc_attach_device(struct pci_dev *dev)
>
> int pci_proc_detach_device(struct pci_dev *dev)
> {
> - struct proc_dir_entry *e;
> -
> - if ((e = dev->procent)) {
> - remove_proc_entry(e->name, dev->bus->procdir);
> - dev->procent = NULL;
> - }
> + proc_remove(dev->procent);
> + dev->procent = NULL;
> return 0;
> }
>
> int pci_proc_detach_bus(struct pci_bus* bus)
> {
> - struct proc_dir_entry *de = bus->procdir;
> - if (de)
> - remove_proc_entry(de->name, proc_bus_pci_dir);
> + proc_remove(bus->procdir);
> return 0;
> }
>
> diff --git a/fs/proc/generic.c b/fs/proc/generic.c
> index 2c6d6be..4b48033 100644
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -630,3 +630,10 @@ const char *get_proc_name(const struct proc_dir_entry *de)
> return de->name;
> }
> EXPORT_SYMBOL_GPL(get_proc_name);
> +
> +void proc_remove(struct proc_dir_entry *de)
> +{
> + if (de)
> + remove_proc_subtree(de->name, de->parent);
> +}
> +EXPORT_SYMBOL(proc_remove);
> diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
> index 38edddc..17f7e08 100644
> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -699,7 +699,7 @@ void vmcore_cleanup(void)
> struct list_head *pos, *next;
>
> if (proc_vmcore) {
> - remove_proc_entry(proc_vmcore->name, proc_vmcore->parent);
> + proc_remove(proc_vmcore);
> proc_vmcore = NULL;
> }
>
> diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
> index 7abc72a..b8949b1 100644
> --- a/include/linux/proc_fs.h
> +++ b/include/linux/proc_fs.h
> @@ -67,6 +67,7 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
> struct proc_dir_entry *parent,
> const struct file_operations *proc_fops,
> void *data);
> +extern void proc_remove(struct proc_dir_entry *);
> extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
> extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
>
> @@ -103,6 +104,7 @@ static inline struct proc_dir_entry *proc_create_data(const char *name,
> {
> return NULL;
> }
> +static inline void proc_remove(struct proc_dir_entry *de) {}
> #define remove_proc_entry(name, parent) do {} while (0)
> #define remove_proc_subtree(name, parent) do {} while (0)
>
> diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
> index d59ae37..19ed5c4 100644
> --- a/kernel/irq/proc.c
> +++ b/kernel/irq/proc.c
> @@ -366,11 +366,7 @@ void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
>
> void unregister_handler_proc(unsigned int irq, struct irqaction *action)
> {
> - if (action->dir) {
> - struct irq_desc *desc = irq_to_desc(irq);
> -
> - remove_proc_entry(action->dir->name, desc->dir);
> - }
> + proc_remove(action->dir);
> }
>
> static void register_default_affinity_proc(void)
> diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
> index 959ddbb..1d0e8921 100644
> --- a/net/8021q/vlanproc.c
> +++ b/net/8021q/vlanproc.c
> @@ -184,14 +184,9 @@ int vlan_proc_add_dev(struct net_device *vlandev)
> */
> int vlan_proc_rem_dev(struct net_device *vlandev)
> {
> - struct vlan_net *vn = net_generic(dev_net(vlandev), vlan_net_id);
> -
> /** NOTE: This will consume the memory pointed to by dent, it seems. */
> - if (vlan_dev_priv(vlandev)->dent) {
> - remove_proc_entry(vlan_dev_priv(vlandev)->dent->name,
> - vn->proc_vlan_dir);
> - vlan_dev_priv(vlandev)->dent = NULL;
> - }
> + proc_remove(vlan_dev_priv(vlandev)->dent);
> + vlan_dev_priv(vlandev)->dent = NULL;
> return 0;
> }
>
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index f6af4fe..6c41e97 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -1904,7 +1904,7 @@ static void pktgen_change_name(const struct pktgen_net *pn, struct net_device *d
> if (pkt_dev->odev != dev)
> continue;
>
> - remove_proc_entry(pkt_dev->entry->name, pn->proc_dir);
> + proc_remove(pkt_dev->entry);
>
> pkt_dev->entry = proc_create_data(dev->name, 0600,
> pn->proc_dir,
> @@ -3576,8 +3576,6 @@ static void _rem_dev_from_if_list(struct pktgen_thread *t,
> static int pktgen_remove_device(struct pktgen_thread *t,
> struct pktgen_dev *pkt_dev)
> {
> - struct pktgen_net *pn = t->net;
> -
> pr_debug("remove_device pkt_dev=%p\n", pkt_dev);
>
> if (pkt_dev->running) {
> @@ -3597,7 +3595,7 @@ static int pktgen_remove_device(struct pktgen_thread *t,
> _rem_dev_from_if_list(t, pkt_dev);
>
> if (pkt_dev->entry)
> - remove_proc_entry(pkt_dev->entry->name, pn->proc_dir);
> + proc_remove(pkt_dev->entry);
>
> #ifdef CONFIG_XFRM
> free_SAs(pkt_dev);
> diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
> index e4738fe..0b732ef 100644
> --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
> +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
> @@ -105,7 +105,7 @@ clusterip_config_entry_put(struct clusterip_config *c)
> * functions are also incrementing the refcount on their own,
> * so it's safe to remove the entry even if it's in use. */
> #ifdef CONFIG_PROC_FS
> - remove_proc_entry(c->pde->name, c->pde->parent);
> + proc_remove(c->pde);
> #endif
> return;
> }
> @@ -736,7 +736,7 @@ static void __exit clusterip_tg_exit(void)
> {
> pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION);
> #ifdef CONFIG_PROC_FS
> - remove_proc_entry(clusterip_procdir->name, clusterip_procdir->parent);
> + proc_remove(clusterip_procdir);
> #endif
> nf_unregister_hook(&cip_arp_ops);
> xt_unregister_target(&clusterip_tg_reg);
> diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
> index 7ea6e18..537d9ee 100644
> --- a/net/ipv6/proc.c
> +++ b/net/ipv6/proc.c
> @@ -287,8 +287,7 @@ int snmp6_unregister_dev(struct inet6_dev *idev)
> return -ENOENT;
> if (!idev->stats.proc_dir_entry)
> return -EINVAL;
> - remove_proc_entry(idev->stats.proc_dir_entry->name,
> - net->mib.proc_net_devsnmp6);
> + proc_remove(idev->stats.proc_dir_entry);
> idev->stats.proc_dir_entry = NULL;
> return 0;
> }
> diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
> index d2fd53b..40002ef 100644
> --- a/net/netfilter/xt_hashlimit.c
> +++ b/net/netfilter/xt_hashlimit.c
> @@ -330,7 +330,7 @@ static void htable_destroy(struct xt_hashlimit_htable *hinfo)
> parent = hashlimit_net->ip6t_hashlimit;
>
> if(parent != NULL)
> - remove_proc_entry(hinfo->pde->name, parent);
> + proc_remove(hinfo->pde);
>
> htable_selective_cleanup(hinfo, select_all);
> vfree(hinfo);
> @@ -887,7 +887,7 @@ static void __net_exit hashlimit_proc_net_exit(struct net *net)
> pde = hashlimit_net->ip6t_hashlimit;
>
> hlist_for_each_entry(hinfo, &hashlimit_net->htables, node)
> - remove_proc_entry(hinfo->pde->name, pde);
> + proc_remove(hinfo->pde);
>
> hashlimit_net->ipt_hashlimit = NULL;
> hashlimit_net->ip6t_hashlimit = NULL;
> diff --git a/sound/core/info.c b/sound/core/info.c
> index c7f41c3..3c9bd6b 100644
> --- a/sound/core/info.c
> +++ b/sound/core/info.c
> @@ -153,13 +153,6 @@ EXPORT_SYMBOL(snd_seq_root);
> struct snd_info_entry *snd_oss_root;
> #endif
>
> -static void snd_remove_proc_entry(struct proc_dir_entry *parent,
> - struct proc_dir_entry *de)
> -{
> - if (de)
> - remove_proc_entry(de->name, parent);
> -}
> -
> static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
> {
> struct snd_info_private_data *data;
> @@ -580,7 +573,7 @@ int __exit snd_info_done(void)
> #ifdef CONFIG_SND_OSSEMUL
> snd_info_free_entry(snd_oss_root);
> #endif
> - snd_remove_proc_entry(NULL, snd_proc_root);
> + proc_remove(snd_proc_root);
> }
> return 0;
> }
> @@ -642,7 +635,7 @@ void snd_info_card_id_change(struct snd_card *card)
> {
> mutex_lock(&info_mutex);
> if (card->proc_root_link) {
> - snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
> + proc_remove(card->proc_root_link);
> card->proc_root_link = NULL;
> }
> if (strcmp(card->id, card->proc_root->name))
> @@ -661,10 +654,8 @@ void snd_info_card_disconnect(struct snd_card *card)
> if (!card)
> return;
> mutex_lock(&info_mutex);
> - if (card->proc_root_link) {
> - snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
> - card->proc_root_link = NULL;
> - }
> + proc_remove(card->proc_root_link);
> + card->proc_root_link = NULL;
> if (card->proc_root)
> snd_info_disconnect(card->proc_root);
> mutex_unlock(&info_mutex);
> @@ -856,7 +847,7 @@ static void snd_info_disconnect(struct snd_info_entry *entry)
> list_del_init(&entry->list);
> root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
> snd_BUG_ON(!root);
> - snd_remove_proc_entry(root, entry->p);
> + proc_remove(entry->p);
> entry->p = NULL;
> }
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

--
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.

2013-04-18 16:42:05

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH 26/28] proc: Supply a function to remove a proc entry by PDE [RFC]

On Tue, Apr 16, 2013 at 12:27 PM, David Howells <[email protected]> wrote:
> Supply a function (proc_remove()) to remove a proc entry (and any subtree
> rooted there) by proc_dir_entry pointer rather than by name and (optionally)
> root dir entry pointer. This allows us to eliminate all remaining pde->name
> accesses outside of procfs.
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> ---
>
> drivers/acpi/sbs.c | 21 ++++-----------------
> drivers/char/ipmi/ipmi_msghandler.c | 2 +-
> drivers/misc/sgi-gru/gruprocfs.c | 2 +-
> drivers/of/base.c | 11 +----------
> drivers/pci/proc.c | 12 +++---------

For the drivers/pci part:

Acked-by: Bjorn Helgaas <[email protected]>

I assume you'll merge this via something other than my tree.

> fs/proc/generic.c | 7 +++++++
> fs/proc/vmcore.c | 2 +-
> include/linux/proc_fs.h | 2 ++
> kernel/irq/proc.c | 6 +-----
> net/8021q/vlanproc.c | 9 ++-------
> net/core/pktgen.c | 6 ++----
> net/ipv4/netfilter/ipt_CLUSTERIP.c | 4 ++--
> net/ipv6/proc.c | 3 +--
> net/netfilter/xt_hashlimit.c | 4 ++--
> sound/core/info.c | 19 +++++--------------
> 15 files changed, 35 insertions(+), 75 deletions(-)
>
> diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
> index a296e08..b6241ee 100644
> --- a/drivers/acpi/sbs.c
> +++ b/drivers/acpi/sbs.c
> @@ -521,19 +521,6 @@ acpi_sbs_add_fs(struct proc_dir_entry **dir,
> return 0;
> }
>
> -static void
> -acpi_sbs_remove_fs(struct proc_dir_entry **dir,
> - struct proc_dir_entry *parent_dir)
> -{
> - if (*dir) {
> - remove_proc_entry(ACPI_SBS_FILE_INFO, *dir);
> - remove_proc_entry(ACPI_SBS_FILE_STATE, *dir);
> - remove_proc_entry(ACPI_SBS_FILE_ALARM, *dir);
> - remove_proc_entry((*dir)->name, parent_dir);
> - *dir = NULL;
> - }
> -}
> -
> /* Smart Battery Interface */
> static struct proc_dir_entry *acpi_battery_dir = NULL;
>
> @@ -836,8 +823,8 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
> power_supply_unregister(&battery->bat);
> }
> #ifdef CONFIG_ACPI_PROCFS_POWER
> - if (battery->proc_entry)
> - acpi_sbs_remove_fs(&battery->proc_entry, acpi_battery_dir);
> + proc_remove(battery->proc_entry);
> + battery->proc_entry = NULL;
> #endif
> }
>
> @@ -873,8 +860,8 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
> if (sbs->charger.dev)
> power_supply_unregister(&sbs->charger);
> #ifdef CONFIG_ACPI_PROCFS_POWER
> - if (sbs->charger_entry)
> - acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir);
> + proc_remove(sbs->charger_entry);
> + sbs->charger_entry = NULL;
> #endif
> }
>
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index 1420bbb..4d439d2 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -4541,7 +4541,7 @@ static void __exit cleanup_ipmi(void)
> del_timer_sync(&ipmi_timer);
>
> #ifdef CONFIG_PROC_FS
> - remove_proc_entry(proc_ipmi_root->name, NULL);
> + proc_remove(proc_ipmi_root);
> #endif /* CONFIG_PROC_FS */
>
> driver_unregister(&ipmidriver.driver);
> diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
> index 950dbe9..797d796 100644
> --- a/drivers/misc/sgi-gru/gruprocfs.c
> +++ b/drivers/misc/sgi-gru/gruprocfs.c
> @@ -355,7 +355,7 @@ static void delete_proc_files(void)
> for (p = proc_files; p->name; p++)
> if (p->entry)
> remove_proc_entry(p->name, proc_gru);
> - remove_proc_entry("gru", proc_gru->parent);
> + proc_remove(proc_gru);
> }
> }
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 321d3ef..9c70436 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1452,16 +1452,7 @@ int of_attach_node(struct device_node *np)
> #ifdef CONFIG_PROC_DEVICETREE
> static void of_remove_proc_dt_entry(struct device_node *dn)
> {
> - struct device_node *parent = dn->parent;
> - struct property *prop = dn->properties;
> -
> - while (prop) {
> - remove_proc_entry(prop->name, dn->pde);
> - prop = prop->next;
> - }
> -
> - if (dn->pde)
> - remove_proc_entry(dn->pde->name, parent->pde);
> + proc_remove(dn->pde);
> }
> #else
> static void of_remove_proc_dt_entry(struct device_node *dn)
> diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
> index 7cde7c1..0812608 100644
> --- a/drivers/pci/proc.c
> +++ b/drivers/pci/proc.c
> @@ -427,20 +427,14 @@ int pci_proc_attach_device(struct pci_dev *dev)
>
> int pci_proc_detach_device(struct pci_dev *dev)
> {
> - struct proc_dir_entry *e;
> -
> - if ((e = dev->procent)) {
> - remove_proc_entry(e->name, dev->bus->procdir);
> - dev->procent = NULL;
> - }
> + proc_remove(dev->procent);
> + dev->procent = NULL;
> return 0;
> }
>
> int pci_proc_detach_bus(struct pci_bus* bus)
> {
> - struct proc_dir_entry *de = bus->procdir;
> - if (de)
> - remove_proc_entry(de->name, proc_bus_pci_dir);
> + proc_remove(bus->procdir);
> return 0;
> }
>
> diff --git a/fs/proc/generic.c b/fs/proc/generic.c
> index 2c6d6be..4b48033 100644
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -630,3 +630,10 @@ const char *get_proc_name(const struct proc_dir_entry *de)
> return de->name;
> }
> EXPORT_SYMBOL_GPL(get_proc_name);
> +
> +void proc_remove(struct proc_dir_entry *de)
> +{
> + if (de)
> + remove_proc_subtree(de->name, de->parent);
> +}
> +EXPORT_SYMBOL(proc_remove);
> diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
> index 38edddc..17f7e08 100644
> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -699,7 +699,7 @@ void vmcore_cleanup(void)
> struct list_head *pos, *next;
>
> if (proc_vmcore) {
> - remove_proc_entry(proc_vmcore->name, proc_vmcore->parent);
> + proc_remove(proc_vmcore);
> proc_vmcore = NULL;
> }
>
> diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
> index 7abc72a..b8949b1 100644
> --- a/include/linux/proc_fs.h
> +++ b/include/linux/proc_fs.h
> @@ -67,6 +67,7 @@ struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
> struct proc_dir_entry *parent,
> const struct file_operations *proc_fops,
> void *data);
> +extern void proc_remove(struct proc_dir_entry *);
> extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
> extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
>
> @@ -103,6 +104,7 @@ static inline struct proc_dir_entry *proc_create_data(const char *name,
> {
> return NULL;
> }
> +static inline void proc_remove(struct proc_dir_entry *de) {}
> #define remove_proc_entry(name, parent) do {} while (0)
> #define remove_proc_subtree(name, parent) do {} while (0)
>
> diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
> index d59ae37..19ed5c4 100644
> --- a/kernel/irq/proc.c
> +++ b/kernel/irq/proc.c
> @@ -366,11 +366,7 @@ void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)
>
> void unregister_handler_proc(unsigned int irq, struct irqaction *action)
> {
> - if (action->dir) {
> - struct irq_desc *desc = irq_to_desc(irq);
> -
> - remove_proc_entry(action->dir->name, desc->dir);
> - }
> + proc_remove(action->dir);
> }
>
> static void register_default_affinity_proc(void)
> diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
> index 959ddbb..1d0e8921 100644
> --- a/net/8021q/vlanproc.c
> +++ b/net/8021q/vlanproc.c
> @@ -184,14 +184,9 @@ int vlan_proc_add_dev(struct net_device *vlandev)
> */
> int vlan_proc_rem_dev(struct net_device *vlandev)
> {
> - struct vlan_net *vn = net_generic(dev_net(vlandev), vlan_net_id);
> -
> /** NOTE: This will consume the memory pointed to by dent, it seems. */
> - if (vlan_dev_priv(vlandev)->dent) {
> - remove_proc_entry(vlan_dev_priv(vlandev)->dent->name,
> - vn->proc_vlan_dir);
> - vlan_dev_priv(vlandev)->dent = NULL;
> - }
> + proc_remove(vlan_dev_priv(vlandev)->dent);
> + vlan_dev_priv(vlandev)->dent = NULL;
> return 0;
> }
>
> diff --git a/net/core/pktgen.c b/net/core/pktgen.c
> index f6af4fe..6c41e97 100644
> --- a/net/core/pktgen.c
> +++ b/net/core/pktgen.c
> @@ -1904,7 +1904,7 @@ static void pktgen_change_name(const struct pktgen_net *pn, struct net_device *d
> if (pkt_dev->odev != dev)
> continue;
>
> - remove_proc_entry(pkt_dev->entry->name, pn->proc_dir);
> + proc_remove(pkt_dev->entry);
>
> pkt_dev->entry = proc_create_data(dev->name, 0600,
> pn->proc_dir,
> @@ -3576,8 +3576,6 @@ static void _rem_dev_from_if_list(struct pktgen_thread *t,
> static int pktgen_remove_device(struct pktgen_thread *t,
> struct pktgen_dev *pkt_dev)
> {
> - struct pktgen_net *pn = t->net;
> -
> pr_debug("remove_device pkt_dev=%p\n", pkt_dev);
>
> if (pkt_dev->running) {
> @@ -3597,7 +3595,7 @@ static int pktgen_remove_device(struct pktgen_thread *t,
> _rem_dev_from_if_list(t, pkt_dev);
>
> if (pkt_dev->entry)
> - remove_proc_entry(pkt_dev->entry->name, pn->proc_dir);
> + proc_remove(pkt_dev->entry);
>
> #ifdef CONFIG_XFRM
> free_SAs(pkt_dev);
> diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
> index e4738fe..0b732ef 100644
> --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
> +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
> @@ -105,7 +105,7 @@ clusterip_config_entry_put(struct clusterip_config *c)
> * functions are also incrementing the refcount on their own,
> * so it's safe to remove the entry even if it's in use. */
> #ifdef CONFIG_PROC_FS
> - remove_proc_entry(c->pde->name, c->pde->parent);
> + proc_remove(c->pde);
> #endif
> return;
> }
> @@ -736,7 +736,7 @@ static void __exit clusterip_tg_exit(void)
> {
> pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION);
> #ifdef CONFIG_PROC_FS
> - remove_proc_entry(clusterip_procdir->name, clusterip_procdir->parent);
> + proc_remove(clusterip_procdir);
> #endif
> nf_unregister_hook(&cip_arp_ops);
> xt_unregister_target(&clusterip_tg_reg);
> diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
> index 7ea6e18..537d9ee 100644
> --- a/net/ipv6/proc.c
> +++ b/net/ipv6/proc.c
> @@ -287,8 +287,7 @@ int snmp6_unregister_dev(struct inet6_dev *idev)
> return -ENOENT;
> if (!idev->stats.proc_dir_entry)
> return -EINVAL;
> - remove_proc_entry(idev->stats.proc_dir_entry->name,
> - net->mib.proc_net_devsnmp6);
> + proc_remove(idev->stats.proc_dir_entry);
> idev->stats.proc_dir_entry = NULL;
> return 0;
> }
> diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
> index d2fd53b..40002ef 100644
> --- a/net/netfilter/xt_hashlimit.c
> +++ b/net/netfilter/xt_hashlimit.c
> @@ -330,7 +330,7 @@ static void htable_destroy(struct xt_hashlimit_htable *hinfo)
> parent = hashlimit_net->ip6t_hashlimit;
>
> if(parent != NULL)
> - remove_proc_entry(hinfo->pde->name, parent);
> + proc_remove(hinfo->pde);
>
> htable_selective_cleanup(hinfo, select_all);
> vfree(hinfo);
> @@ -887,7 +887,7 @@ static void __net_exit hashlimit_proc_net_exit(struct net *net)
> pde = hashlimit_net->ip6t_hashlimit;
>
> hlist_for_each_entry(hinfo, &hashlimit_net->htables, node)
> - remove_proc_entry(hinfo->pde->name, pde);
> + proc_remove(hinfo->pde);
>
> hashlimit_net->ipt_hashlimit = NULL;
> hashlimit_net->ip6t_hashlimit = NULL;
> diff --git a/sound/core/info.c b/sound/core/info.c
> index c7f41c3..3c9bd6b 100644
> --- a/sound/core/info.c
> +++ b/sound/core/info.c
> @@ -153,13 +153,6 @@ EXPORT_SYMBOL(snd_seq_root);
> struct snd_info_entry *snd_oss_root;
> #endif
>
> -static void snd_remove_proc_entry(struct proc_dir_entry *parent,
> - struct proc_dir_entry *de)
> -{
> - if (de)
> - remove_proc_entry(de->name, parent);
> -}
> -
> static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
> {
> struct snd_info_private_data *data;
> @@ -580,7 +573,7 @@ int __exit snd_info_done(void)
> #ifdef CONFIG_SND_OSSEMUL
> snd_info_free_entry(snd_oss_root);
> #endif
> - snd_remove_proc_entry(NULL, snd_proc_root);
> + proc_remove(snd_proc_root);
> }
> return 0;
> }
> @@ -642,7 +635,7 @@ void snd_info_card_id_change(struct snd_card *card)
> {
> mutex_lock(&info_mutex);
> if (card->proc_root_link) {
> - snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
> + proc_remove(card->proc_root_link);
> card->proc_root_link = NULL;
> }
> if (strcmp(card->id, card->proc_root->name))
> @@ -661,10 +654,8 @@ void snd_info_card_disconnect(struct snd_card *card)
> if (!card)
> return;
> mutex_lock(&info_mutex);
> - if (card->proc_root_link) {
> - snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
> - card->proc_root_link = NULL;
> - }
> + proc_remove(card->proc_root_link);
> + card->proc_root_link = NULL;
> if (card->proc_root)
> snd_info_disconnect(card->proc_root);
> mutex_unlock(&info_mutex);
> @@ -856,7 +847,7 @@ static void snd_info_disconnect(struct snd_info_entry *entry)
> list_del_init(&entry->list);
> root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
> snd_BUG_ON(!root);
> - snd_remove_proc_entry(root, entry->p);
> + proc_remove(entry->p);
> entry->p = NULL;
> }
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2013-04-18 16:43:16

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH 04/28] proc: Supply PDE attribute setting accessor functions [RFC]

On Tue, Apr 16, 2013 at 12:26 PM, David Howells <[email protected]> wrote:
> Supply accessor functions to set attributes in proc_dir_entry structs.
>
> The following are supplied: proc_set_size() and proc_set_user().
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> ---
>
> arch/powerpc/kernel/proc_powerpc.c | 2 +-
> arch/powerpc/platforms/pseries/reconfig.c | 2 +-
> drivers/media/pci/ttpci/av7110_ir.c | 2 +-
> drivers/net/irda/vlsi_ir.c | 2 +-
> drivers/net/wireless/airo.c | 34 +++++++++--------------------
> drivers/pci/proc.c | 2 +-

For the drivers/pci part:

Acked-by: Bjorn Helgaas <[email protected]>

> fs/proc/generic.c | 13 +++++++++++
> include/linux/proc_fs.h | 5 ++++
> kernel/configs.c | 2 +-
> kernel/profile.c | 2 +-
> net/netfilter/xt_recent.c | 3 +--
> sound/core/info.c | 2 +-
> 12 files changed, 38 insertions(+), 33 deletions(-)
>
> diff --git a/arch/powerpc/kernel/proc_powerpc.c b/arch/powerpc/kernel/proc_powerpc.c
> index 41d8ee9..feb8580 100644
> --- a/arch/powerpc/kernel/proc_powerpc.c
> +++ b/arch/powerpc/kernel/proc_powerpc.c
> @@ -83,7 +83,7 @@ static int __init proc_ppc64_init(void)
> &page_map_fops, vdso_data);
> if (!pde)
> return 1;
> - pde->size = PAGE_SIZE;
> + proc_set_size(pde, PAGE_SIZE);
>
> return 0;
> }
> diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
> index d6491bd..f93cdf5 100644
> --- a/arch/powerpc/platforms/pseries/reconfig.c
> +++ b/arch/powerpc/platforms/pseries/reconfig.c
> @@ -452,7 +452,7 @@ static int proc_ppc64_create_ofdt(void)
>
> ent = proc_create("powerpc/ofdt", S_IWUSR, NULL, &ofdt_fops);
> if (ent)
> - ent->size = 0;
> + proc_set_size(ent, 0);
>
> return 0;
> }
> diff --git a/drivers/media/pci/ttpci/av7110_ir.c b/drivers/media/pci/ttpci/av7110_ir.c
> index eb82286..0e763a7 100644
> --- a/drivers/media/pci/ttpci/av7110_ir.c
> +++ b/drivers/media/pci/ttpci/av7110_ir.c
> @@ -375,7 +375,7 @@ int av7110_ir_init(struct av7110 *av7110)
> if (av_cnt == 1) {
> e = proc_create("av7110_ir", S_IWUSR, NULL, &av7110_ir_proc_fops);
> if (e)
> - e->size = 4 + 256 * sizeof(u16);
> + proc_set_size(e, 4 + 256 * sizeof(u16));
> }
>
> tasklet_init(&av7110->ir.ir_tasklet, av7110_emit_key, (unsigned long) &av7110->ir);
> diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
> index e22cd4e..5f47584 100644
> --- a/drivers/net/irda/vlsi_ir.c
> +++ b/drivers/net/irda/vlsi_ir.c
> @@ -1678,7 +1678,7 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> IRDA_WARNING("%s: failed to create proc entry\n",
> __func__);
> } else {
> - ent->size = 0;
> + proc_set_size(ent, 0);
> }
> idev->proc_entry = ent;
> }
> diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
> index 66e398d..21d0233 100644
> --- a/drivers/net/wireless/airo.c
> +++ b/drivers/net/wireless/airo.c
> @@ -4507,73 +4507,63 @@ static int setup_proc_entry( struct net_device *dev,
> airo_entry);
> if (!apriv->proc_entry)
> goto fail;
> - apriv->proc_entry->uid = proc_kuid;
> - apriv->proc_entry->gid = proc_kgid;
> + proc_set_user(apriv->proc_entry, proc_kuid, proc_kgid);
>
> /* Setup the StatsDelta */
> entry = proc_create_data("StatsDelta", S_IRUGO & proc_perm,
> apriv->proc_entry, &proc_statsdelta_ops, dev);
> if (!entry)
> goto fail_stats_delta;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Stats */
> entry = proc_create_data("Stats", S_IRUGO & proc_perm,
> apriv->proc_entry, &proc_stats_ops, dev);
> if (!entry)
> goto fail_stats;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Status */
> entry = proc_create_data("Status", S_IRUGO & proc_perm,
> apriv->proc_entry, &proc_status_ops, dev);
> if (!entry)
> goto fail_status;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Config */
> entry = proc_create_data("Config", proc_perm,
> apriv->proc_entry, &proc_config_ops, dev);
> if (!entry)
> goto fail_config;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the SSID */
> entry = proc_create_data("SSID", proc_perm,
> apriv->proc_entry, &proc_SSID_ops, dev);
> if (!entry)
> goto fail_ssid;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the APList */
> entry = proc_create_data("APList", proc_perm,
> apriv->proc_entry, &proc_APList_ops, dev);
> if (!entry)
> goto fail_aplist;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the BSSList */
> entry = proc_create_data("BSSList", proc_perm,
> apriv->proc_entry, &proc_BSSList_ops, dev);
> if (!entry)
> goto fail_bsslist;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the WepKey */
> entry = proc_create_data("WepKey", proc_perm,
> apriv->proc_entry, &proc_wepkey_ops, dev);
> if (!entry)
> goto fail_wepkey;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> -
> + proc_set_user(entry, proc_kuid, proc_kgid);
> return 0;
>
> fail_wepkey:
> @@ -5695,10 +5685,8 @@ static int __init airo_init_module( void )
>
> airo_entry = proc_mkdir_mode("driver/aironet", airo_perm, NULL);
>
> - if (airo_entry) {
> - airo_entry->uid = proc_kuid;
> - airo_entry->gid = proc_kgid;
> - }
> + if (airo_entry)
> + proc_set_user(airo_entry, proc_kuid, proc_kgid);
>
> for (i = 0; i < 4 && io[i] && irq[i]; i++) {
> airo_print_info("", "Trying to configure ISA adapter at irq=%d "
> diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
> index 12e4fb5..7cde7c1 100644
> --- a/drivers/pci/proc.c
> +++ b/drivers/pci/proc.c
> @@ -419,7 +419,7 @@ int pci_proc_attach_device(struct pci_dev *dev)
> &proc_bus_pci_operations, dev);
> if (!e)
> return -ENOMEM;
> - e->size = dev->cfg_size;
> + proc_set_size(e, dev->cfg_size);
> dev->procent = e;
>
> return 0;
> diff --git a/fs/proc/generic.c b/fs/proc/generic.c
> index 1c07cad..5f6f6c3 100644
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -498,6 +498,19 @@ out:
> return NULL;
> }
> EXPORT_SYMBOL(proc_create_data);
> +
> +void proc_set_size(struct proc_dir_entry *de, loff_t size)
> +{
> + de->size = size;
> +}
> +EXPORT_SYMBOL(proc_set_size);
> +
> +void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid)
> +{
> + de->uid = uid;
> + de->gid = gid;
> +}
> +EXPORT_SYMBOL(proc_set_user);
>
> static void free_proc_entry(struct proc_dir_entry *de)
> {
> diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
> index 805edac..28a4d7e 100644
> --- a/include/linux/proc_fs.h
> +++ b/include/linux/proc_fs.h
> @@ -130,6 +130,9 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
> extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
> struct proc_dir_entry *parent);
>
> +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 struct file *proc_ns_fget(int fd);
> extern bool proc_ns_inode(struct inode *inode);
>
> @@ -158,6 +161,8 @@ static inline struct proc_dir_entry *proc_mkdir(const char *name,
> struct proc_dir_entry *parent) {return NULL;}
> static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
> umode_t mode, struct proc_dir_entry *parent) { return NULL; }
> +static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
> +static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
>
> struct tty_driver;
> static inline void proc_tty_register_driver(struct tty_driver *driver) {};
> diff --git a/kernel/configs.c b/kernel/configs.c
> index 42e8fa0..c18b1f1 100644
> --- a/kernel/configs.c
> +++ b/kernel/configs.c
> @@ -79,7 +79,7 @@ static int __init ikconfig_init(void)
> if (!entry)
> return -ENOMEM;
>
> - entry->size = kernel_config_data_size;
> + proc_set_size(entry, kernel_config_data_size);
>
> return 0;
> }
> diff --git a/kernel/profile.c b/kernel/profile.c
> index 524ce5e..0bf4007 100644
> --- a/kernel/profile.c
> +++ b/kernel/profile.c
> @@ -600,7 +600,7 @@ int __ref create_proc_profile(void) /* false positive from hotcpu_notifier */
> NULL, &proc_profile_operations);
> if (!entry)
> return 0;
> - entry->size = (1+prof_len) * sizeof(atomic_t);
> + proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
> hotcpu_notifier(profile_cpu_callback, 0);
> return 0;
> }
> diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
> index 3db2d38..1e657cf 100644
> --- a/net/netfilter/xt_recent.c
> +++ b/net/netfilter/xt_recent.c
> @@ -401,8 +401,7 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
> ret = -ENOMEM;
> goto out;
> }
> - pde->uid = uid;
> - pde->gid = gid;
> + proc_set_user(pde, uid, gid);
> #endif
> spin_lock_bh(&recent_lock);
> list_add_tail(&t->list, &recent_net->tables);
> diff --git a/sound/core/info.c b/sound/core/info.c
> index 3aa8864..c7f41c3 100644
> --- a/sound/core/info.c
> +++ b/sound/core/info.c
> @@ -970,7 +970,7 @@ int snd_info_register(struct snd_info_entry * entry)
> mutex_unlock(&info_mutex);
> return -ENOMEM;
> }
> - p->size = entry->size;
> + proc_set_size(p, entry->size);
> }
> entry->p = p;
> if (entry->parent)
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2013-04-18 18:39:56

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH 25/28] proc: Supply an accessor to get the process ID associated with some proc files [RFC]

Hello, David.

On Tue, Apr 16, 2013 at 07:27:30PM +0100, David Howells wrote:
> +struct pid *get_proc_pid(const struct inode *inode)
> +{
> + return PROC_I(inode)->pid;
> +}

Maybe we can add /** comment explaining what this is about? Other
than that, it looks fine to me. It probably would be best to route
this through -mm given it touches /proc too, so cc Andrew on the next
posting?

Thanks.

--
tejun

2013-04-18 20:34:21

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 26/28] proc: Supply a function to remove a proc entry by PDE [RFC]

Bjorn Helgaas <[email protected]> wrote:

> I assume you'll merge this via something other than my tree.

Al's vfs tree, I think.

David

2013-04-21 21:53:58

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 26/28] proc: Supply a function to remove a proc entry by PDE [RFC]

On Tuesday, April 16, 2013 07:27:34 PM David Howells wrote:
> Supply a function (proc_remove()) to remove a proc entry (and any subtree
> rooted there) by proc_dir_entry pointer rather than by name and (optionally)
> root dir entry pointer. This allows us to eliminate all remaining pde->name
> accesses outside of procfs.
>
> Signed-off-by: David Howells <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]

The ACPI changes look good to me.

Acked-by: Rafael J. Wysocki <[email protected]>

> ---
>
> drivers/acpi/sbs.c | 21 ++++-----------------
> drivers/char/ipmi/ipmi_msghandler.c | 2 +-
> drivers/misc/sgi-gru/gruprocfs.c | 2 +-
> drivers/of/base.c | 11 +----------
> drivers/pci/proc.c | 12 +++---------
> fs/proc/generic.c | 7 +++++++
> fs/proc/vmcore.c | 2 +-
> include/linux/proc_fs.h | 2 ++
> kernel/irq/proc.c | 6 +-----
> net/8021q/vlanproc.c | 9 ++-------
> net/core/pktgen.c | 6 ++----
> net/ipv4/netfilter/ipt_CLUSTERIP.c | 4 ++--
> net/ipv6/proc.c | 3 +--
> net/netfilter/xt_hashlimit.c | 4 ++--
> sound/core/info.c | 19 +++++--------------
> 15 files changed, 35 insertions(+), 75 deletions(-)
>
> diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
> index a296e08..b6241ee 100644
> --- a/drivers/acpi/sbs.c
> +++ b/drivers/acpi/sbs.c
> @@ -521,19 +521,6 @@ acpi_sbs_add_fs(struct proc_dir_entry **dir,
> return 0;
> }
>
> -static void
> -acpi_sbs_remove_fs(struct proc_dir_entry **dir,
> - struct proc_dir_entry *parent_dir)
> -{
> - if (*dir) {
> - remove_proc_entry(ACPI_SBS_FILE_INFO, *dir);
> - remove_proc_entry(ACPI_SBS_FILE_STATE, *dir);
> - remove_proc_entry(ACPI_SBS_FILE_ALARM, *dir);
> - remove_proc_entry((*dir)->name, parent_dir);
> - *dir = NULL;
> - }
> -}
> -
> /* Smart Battery Interface */
> static struct proc_dir_entry *acpi_battery_dir = NULL;
>
> @@ -836,8 +823,8 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
> power_supply_unregister(&battery->bat);
> }
> #ifdef CONFIG_ACPI_PROCFS_POWER
> - if (battery->proc_entry)
> - acpi_sbs_remove_fs(&battery->proc_entry, acpi_battery_dir);
> + proc_remove(battery->proc_entry);
> + battery->proc_entry = NULL;
> #endif
> }
>
> @@ -873,8 +860,8 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
> if (sbs->charger.dev)
> power_supply_unregister(&sbs->charger);
> #ifdef CONFIG_ACPI_PROCFS_POWER
> - if (sbs->charger_entry)
> - acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir);
> + proc_remove(sbs->charger_entry);
> + sbs->charger_entry = NULL;
> #endif
> }
>


--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2013-04-25 14:34:19

by Vasant Hegde

[permalink] [raw]
Subject: Re: [PATCH 22/28] ppc: Clean up rtas_flash driver somewhat [RFC]

On 04/16/2013 11:57 PM, David Howells wrote:
> Clean up some of the problems with the rtas_flash driver:
>
> (1) It shouldn't fiddle with the internals of the procfs filesystem (altering
> pde->count).
>
> (2) If pid namespaces are in effect, then you can get multiple inodes
> connected to a single pde, thereby rendering the pde->count> 2 test
> useless.
>
> (3) The pde->count fudging doesn't work for forked, dup'd or cloned file
> descriptors, so add static mutexes and use them to wrap access to the
> driver through read, write and release methods.
>
> (4) The driver can only handle one device, so allocate most of the data
> previously attached to the pde->data as static variables instead (though
> allocate the validation data buffer with kmalloc).
>
> (5) We don't need to save the pde pointers as long as we have the filenames
> available for removal.
>
> (6) Don't try to multiplex what the update file read method does based on the
> filename. Instead provide separate file ops and split the function.
>
> Whilst we're at it, tabulate the procfile information and loop through it when
> creating or destroying them rather than manually coding each one.
>
> Signed-off-by: David Howells<[email protected]>
> cc: Benjamin Herrenschmidt<[email protected]>
> cc: Paul Mackerras<[email protected]>
> cc: Anton Blanchard<[email protected]>
> cc: [email protected]
> ---
>
> arch/powerpc/kernel/rtas_flash.c | 446 +++++++++++++++++---------------------
> 1 file changed, 200 insertions(+), 246 deletions(-)
>
> diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
> index c642f01..8196bfb 100644
> --- a/arch/powerpc/kernel/rtas_flash.c
> +++ b/arch/powerpc/kernel/rtas_flash.c
> @@ -102,9 +102,10 @@ static struct kmem_cache *flash_block_cache = NULL;
>
> #define FLASH_BLOCK_LIST_VERSION (1UL)
>
> -/* Local copy of the flash block list.
> - * We only allow one open of the flash proc file and create this
> - * list as we go. The rtas_firmware_flash_list varable will be
> +/*
> + * Local copy of the flash block list.
> + *
> + * The rtas_firmware_flash_list varable will be

s/varable/variable/

> * set once the data is fully read.
> *
> * For convenience as we build the list we use virtual addrs,
> @@ -125,23 +126,23 @@ struct rtas_update_flash_t
> struct rtas_manage_flash_t
> {
> int status; /* Returned status */
> - unsigned int op; /* Reject or commit image */
> };
>
> /* Status int must be first member of struct */
> struct rtas_validate_flash_t
> {
> int status; /* Returned status */
> - char buf[VALIDATE_BUF_SIZE]; /* Candidate image buffer */
> + char *buf; /* Candidate image buffer */
> unsigned int buf_size; /* Size of image buf */
> unsigned int update_results; /* Update results token */
> };
>
> -static DEFINE_SPINLOCK(flash_file_open_lock);
> -static struct proc_dir_entry *firmware_flash_pde;
> -static struct proc_dir_entry *firmware_update_pde;
> -static struct proc_dir_entry *validate_pde;
> -static struct proc_dir_entry *manage_pde;
> +static struct rtas_update_flash_t rtas_update_flash_data;
> +static struct rtas_manage_flash_t rtas_manage_flash_data;
> +static struct rtas_validate_flash_t rtas_validate_flash_data;
> +static DEFINE_MUTEX(rtas_update_flash_mutex);
> +static DEFINE_MUTEX(rtas_manage_flash_mutex);
> +static DEFINE_MUTEX(rtas_validate_flash_mutex);
>
> /* Do simple sanity checks on the flash image. */
> static int flash_list_valid(struct flash_block_list *flist)
> @@ -191,10 +192,10 @@ static void free_flash_list(struct flash_block_list *f)
>
> static int rtas_flash_release(struct inode *inode, struct file *file)
> {
> - struct proc_dir_entry *dp = PDE(file_inode(file));
> - struct rtas_update_flash_t *uf;
> -
> - uf = (struct rtas_update_flash_t *) dp->data;
> + struct rtas_update_flash_t *const uf =&rtas_update_flash_data;
> +
> + mutex_lock(&rtas_update_flash_mutex);
> +
> if (uf->flist) {
> /* File was opened in write mode for a new flash attempt */
> /* Clear saved list */
> @@ -214,13 +215,14 @@ static int rtas_flash_release(struct inode *inode, struct file *file)
> uf->flist = NULL;
> }
>
> - atomic_dec(&dp->count);
> + mutex_unlock(&rtas_update_flash_mutex);
> return 0;
> }
>
> -static void get_flash_status_msg(int status, char *buf)
> +static size_t get_flash_status_msg(int status, char *buf)
> {
> - char *msg;
> + const char *msg;
> + size_t len;
>
> switch (status) {
> case FLASH_AUTH:
> @@ -242,34 +244,51 @@ static void get_flash_status_msg(int status, char *buf)
> msg = "ready: firmware image ready for flash on reboot\n";
> break;
> default:
> - sprintf(buf, "error: unexpected status value %d\n", status);
> - return;
> + return sprintf(buf, "error: unexpected status value %d\n",
> + status);
> }
>
> - strcpy(buf, msg);
> + len = strlen(msg);
> + memcpy(buf, msg, len + 1);
> + return len;
> }
>
> /* Reading the proc file will show status (not the firmware contents) */
> -static ssize_t rtas_flash_read(struct file *file, char __user *buf,
> - size_t count, loff_t *ppos)
> +static ssize_t rtas_flash_read_msg(struct file *file, char __user *buf,
> + size_t count, loff_t *ppos)
> {
> - struct proc_dir_entry *dp = PDE(file_inode(file));
> - struct rtas_update_flash_t *uf;
> + struct rtas_update_flash_t *const uf =&rtas_update_flash_data;
> char msg[RTAS_MSG_MAXLEN];
> + size_t len;
> + int status;
>
> - uf = dp->data;
> + mutex_lock(&rtas_update_flash_mutex);
> + status = uf->status;
> + mutex_unlock(&rtas_update_flash_mutex);
>
> - if (!strcmp(dp->name, FIRMWARE_FLASH_NAME)) {
> - get_flash_status_msg(uf->status, msg);
> - } else { /* FIRMWARE_UPDATE_NAME */
> - sprintf(msg, "%d\n", uf->status);
> - }
> + /* Read as text message */
> + len = get_flash_status_msg(uf->status, msg);

Above line should be
len = get_flash_status_msg(status, msg);

> + return simple_read_from_buffer(buf, count, ppos, msg, len);
> +}
> +
> +static ssize_t rtas_flash_read_num(struct file *file, char __user *buf,
> + size_t count, loff_t *ppos)
> +{
> + struct rtas_update_flash_t *const uf =&rtas_update_flash_data;
> + char msg[RTAS_MSG_MAXLEN];
> + int status;
>
> + mutex_lock(&rtas_update_flash_mutex);
> + status = uf->status;
> + mutex_unlock(&rtas_update_flash_mutex);
> +
> + /* Read as number */
> + sprintf(msg, "%d\n", status);
> return simple_read_from_buffer(buf, count, ppos, msg, strlen(msg));
> }
>
> /* constructor for flash_block_cache */
> -void rtas_block_ctor(void *ptr)
> +static void rtas_block_ctor(void *ptr)
> {
> memset(ptr, 0, RTAS_BLK_SIZE);
> }
> @@ -282,16 +301,15 @@ void rtas_block_ctor(void *ptr)
> static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
> size_t count, loff_t *off)
> {
> - struct proc_dir_entry *dp = PDE(file_inode(file));
> - struct rtas_update_flash_t *uf;
> + struct rtas_update_flash_t *const uf =&rtas_update_flash_data;
> char *p;
> - int next_free;
> + int next_free, rc;
> struct flash_block_list *fl;
>
> - uf = (struct rtas_update_flash_t *) dp->data;
> + mutex_lock(&rtas_update_flash_mutex);
>
> if (uf->status == FLASH_AUTH || count == 0)
> - return count; /* discard data */
> + goto out; /* discard data */
>
> /* In the case that the image is not ready for flashing, the memory
> * allocated for the block list will be freed upon the release of the
> @@ -300,7 +318,7 @@ static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
> if (uf->flist == NULL) {
> uf->flist = kmem_cache_alloc(flash_block_cache, GFP_KERNEL);
> if (!uf->flist)
> - return -ENOMEM;
> + goto nomem;
> }
>
> fl = uf->flist;
> @@ -311,7 +329,7 @@ static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
> /* Need to allocate another block_list */
> fl->next = kmem_cache_alloc(flash_block_cache, GFP_KERNEL);
> if (!fl->next)
> - return -ENOMEM;
> + goto nomem;
> fl = fl->next;
> next_free = 0;
> }
> @@ -320,52 +338,37 @@ static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
> count = RTAS_BLK_SIZE;
> p = kmem_cache_alloc(flash_block_cache, GFP_KERNEL);
> if (!p)
> - return -ENOMEM;
> + goto nomem;
>
> if(copy_from_user(p, buffer, count)) {
> kmem_cache_free(flash_block_cache, p);
> - return -EFAULT;
> + rc = -EFAULT;
> + goto error;
> }
> fl->blocks[next_free].data = p;
> fl->blocks[next_free].length = count;
> fl->num_blocks++;
> -
> +out:
> + mutex_lock(&rtas_update_flash_mutex);

Above line should be "mutext_unlock(....)".


> return count;
> -}
> -
> -static int rtas_excl_open(struct inode *inode, struct file *file)
> -{
> - struct proc_dir_entry *dp = PDE(inode);
> -
> - /* Enforce exclusive open with use count of PDE */
> - spin_lock(&flash_file_open_lock);
> - if (atomic_read(&dp->count)> 2) {
> - spin_unlock(&flash_file_open_lock);
> - return -EBUSY;
> - }
> -
> - atomic_inc(&dp->count);
> - spin_unlock(&flash_file_open_lock);
> -
> - return 0;
> -}
> -
> -static int rtas_excl_release(struct inode *inode, struct file *file)
> -{
> - struct proc_dir_entry *dp = PDE(inode);
>
> - atomic_dec(&dp->count);
> -
> - return 0;
> +nomem:
> + rc = -ENOMEM;
> +error:
> + mutex_lock(&rtas_update_flash_mutex);

Again, above line should be "mutex_unlock".

> + return rc;
> }
>
> -static void manage_flash(struct rtas_manage_flash_t *args_buf)
> +/*
> + * Flash management routines.
> + */
> +static void manage_flash(struct rtas_manage_flash_t *args_buf, unsigned int op)
> {
> s32 rc;
>
> do {
> - rc = rtas_call(rtas_token("ibm,manage-flash-image"), 1,
> - 1, NULL, args_buf->op);
> + rc = rtas_call(rtas_token("ibm,manage-flash-image"), 1, 1,
> + NULL, op);
> } while (rtas_busy_delay(rc));
>
> args_buf->status = rc;
> @@ -374,40 +377,38 @@ static void manage_flash(struct rtas_manage_flash_t *args_buf)
> static ssize_t manage_flash_read(struct file *file, char __user *buf,
> size_t count, loff_t *ppos)
> {
> - struct proc_dir_entry *dp = PDE(file_inode(file));
> - struct rtas_manage_flash_t *args_buf;
> + struct rtas_manage_flash_t *const args_buf =&rtas_manage_flash_data;
> char msg[RTAS_MSG_MAXLEN];
> - int msglen;
> + int msglen, status;
>
> - args_buf = dp->data;
> - if (args_buf == NULL)
> - return 0;
> -
> - msglen = sprintf(msg, "%d\n", args_buf->status);
> + mutex_lock(&rtas_manage_flash_mutex);
> + status = args_buf->status;
> + mutex_unlock(&rtas_manage_flash_mutex);
>
> + msglen = sprintf(msg, "%d\n", status);
> return simple_read_from_buffer(buf, count, ppos, msg, msglen);
> }
>
> static ssize_t manage_flash_write(struct file *file, const char __user *buf,
> size_t count, loff_t *off)
> {
> - struct proc_dir_entry *dp = PDE(file_inode(file));
> - struct rtas_manage_flash_t *args_buf;
> - const char reject_str[] = "0";
> - const char commit_str[] = "1";
> + struct rtas_manage_flash_t *const args_buf =&rtas_manage_flash_data;
> + static const char reject_str[] = "0";
> + static const char commit_str[] = "1";
> char stkbuf[10];
> - int op;
> + int op, rc;
> +
> + mutex_lock(&rtas_manage_flash_mutex);
>
> - args_buf = (struct rtas_manage_flash_t *) dp->data;
> if ((args_buf->status == MANAGE_AUTH) || (count == 0))
> - return count;
> + goto out;
>
> op = -1;
> if (buf) {
> if (count> 9) count = 9;
> - if (copy_from_user (stkbuf, buf, count)) {
> - return -EFAULT;
> - }
> + rc = -EFAULT;
> + if (copy_from_user (stkbuf, buf, count))
> + goto error;
> if (strncmp(stkbuf, reject_str, strlen(reject_str)) == 0)
> op = RTAS_REJECT_TMP_IMG;
> else if (strncmp(stkbuf, commit_str, strlen(commit_str)) == 0)
> @@ -417,12 +418,19 @@ static ssize_t manage_flash_write(struct file *file, const char __user *buf,
> if (op == -1) /* buf is empty, or contains invalid string */
> return -EINVAL;
>

We need to release mutex here.

+ if (op == -1) { /* buf is empty, or contains invalid string */
+ rc = -EINVAL;
+ goto error;
+ }



> - args_buf->op = op;
> - manage_flash(args_buf);
> -
> + manage_flash(args_buf, op);
> +out:
> + mutex_unlock(&rtas_manage_flash_mutex);
> return count;
> +
> +error:
> + mutex_unlock(&rtas_manage_flash_mutex);
> + return rc;
> }
>
> +/*
> + * Validation routines.
> + */
> static void validate_flash(struct rtas_validate_flash_t *args_buf)
> {
> int token = rtas_token("ibm,validate-flash-image");
> @@ -462,14 +470,14 @@ static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf,
> static ssize_t validate_flash_read(struct file *file, char __user *buf,
> size_t count, loff_t *ppos)
> {
> - struct proc_dir_entry *dp = PDE(file_inode(file));
> - struct rtas_validate_flash_t *args_buf;
> + struct rtas_validate_flash_t *const args_buf =
> + &rtas_validate_flash_data;
> char msg[RTAS_MSG_MAXLEN];
> int msglen;
>
> - args_buf = dp->data;
> -
> + mutex_lock(&rtas_validate_flash_mutex);
> msglen = get_validate_flash_msg(args_buf, msg);
> + mutex_unlock(&rtas_validate_flash_mutex);
>
> return simple_read_from_buffer(buf, count, ppos, msg, msglen);
> }
> @@ -477,24 +485,18 @@ static ssize_t validate_flash_read(struct file *file, char __user *buf,
> static ssize_t validate_flash_write(struct file *file, const char __user *buf,
> size_t count, loff_t *off)
> {
> - struct proc_dir_entry *dp = PDE(file_inode(file));
> - struct rtas_validate_flash_t *args_buf;
> + struct rtas_validate_flash_t *const args_buf =
> + &rtas_validate_flash_data;
> int rc;
>
> - args_buf = (struct rtas_validate_flash_t *) dp->data;
> -
> - if (dp->data == NULL) {
> - dp->data = kmalloc(sizeof(struct rtas_validate_flash_t),
> - GFP_KERNEL);
> - if (dp->data == NULL)
> - return -ENOMEM;
> - }
> + mutex_lock(&rtas_validate_flash_mutex);
>
> /* We are only interested in the first 4K of the
> * candidate image */
> if ((*off>= VALIDATE_BUF_SIZE) ||
> (args_buf->status == VALIDATE_AUTH)) {
> *off += count;
> + mutex_unlock(&rtas_validate_flash_mutex);
> return count;
> }
>
> @@ -517,31 +519,29 @@ static ssize_t validate_flash_write(struct file *file, const char __user *buf,
> *off += count;
> rc = count;
> done:
> - if (rc< 0) {
> - kfree(dp->data);
> - dp->data = NULL;
> - }
> + mutex_unlock(&rtas_validate_flash_mutex);
> return rc;
> }
>
> static int validate_flash_release(struct inode *inode, struct file *file)
> {
> - struct proc_dir_entry *dp = PDE(file_inode(file));
> - struct rtas_validate_flash_t *args_buf;
> + struct rtas_validate_flash_t *const args_buf =
> + &rtas_validate_flash_data;
>
> - args_buf = (struct rtas_validate_flash_t *) dp->data;
> + mutex_lock(&rtas_validate_flash_mutex);
>
> if (args_buf->status == VALIDATE_READY) {
> args_buf->buf_size = VALIDATE_BUF_SIZE;
> validate_flash(args_buf);
> }
>
> - /* The matching atomic_inc was in rtas_excl_open() */
> - atomic_dec(&dp->count);
> -
> + mutex_unlock(&rtas_validate_flash_mutex);
> return 0;
> }
>
> +/*
> + * On-reboot flash update applicator.
> + */
> static void rtas_flash_firmware(int reboot_type)
> {
> unsigned long image_size;
> @@ -634,75 +634,57 @@ static void rtas_flash_firmware(int reboot_type)
> spin_unlock(&rtas_data_buf_lock);
> }
>
> -static void remove_flash_pde(struct proc_dir_entry *dp)
> -{
> - if (dp) {
> - kfree(dp->data);
> - remove_proc_entry(dp->name, dp->parent);
> - }
> -}
> -
> -static int initialize_flash_pde_data(const char *rtas_call_name,
> - size_t buf_size,
> - struct proc_dir_entry *dp)
> -{
> +/*
> + * Manifest of proc files to create
> + */
> +struct rtas_flash_file {
> + const char *filename;
> + const char *rtas_call_name;
> int *status;
> - int token;
> -
> - dp->data = kzalloc(buf_size, GFP_KERNEL);
> - if (dp->data == NULL)
> - return -ENOMEM;
> -
> - /*
> - * This code assumes that the status int is the first member of the
> - * struct
> - */
> - status = (int *) dp->data;
> - token = rtas_token(rtas_call_name);
> - if (token == RTAS_UNKNOWN_SERVICE)
> - *status = FLASH_AUTH;
> - else
> - *status = FLASH_NO_OP;
> -
> - return 0;
> -}
> -
> -static struct proc_dir_entry *create_flash_pde(const char *filename,
> - const struct file_operations *fops)
> -{
> - return proc_create(filename, S_IRUSR | S_IWUSR, NULL, fops);
> -}
> -
> -static const struct file_operations rtas_flash_operations = {
> - .owner = THIS_MODULE,
> - .read = rtas_flash_read,
> - .write = rtas_flash_write,
> - .open = rtas_excl_open,
> - .release = rtas_flash_release,
> - .llseek = default_llseek,
> + const struct file_operations fops;
> };
>
> -static const struct file_operations manage_flash_operations = {
> - .owner = THIS_MODULE,
> - .read = manage_flash_read,
> - .write = manage_flash_write,
> - .open = rtas_excl_open,
> - .release = rtas_excl_release,
> - .llseek = default_llseek,
> -};
> -
> -static const struct file_operations validate_flash_operations = {
> - .owner = THIS_MODULE,
> - .read = validate_flash_read,
> - .write = validate_flash_write,
> - .open = rtas_excl_open,
> - .release = validate_flash_release,
> - .llseek = default_llseek,
> +static const struct rtas_flash_file rtas_flash_files[] = {
> + {
> + .filename = "powerpc/rtas/" FIRMWARE_FLASH_NAME,
> + .rtas_call_name = "ibm,update-flash-64-and-reboot",
> + .status =&rtas_update_flash_data.status,
> + .fops.read = rtas_flash_read_msg,
> + .fops.write = rtas_flash_write,
> + .fops.release = rtas_flash_release,
> + .fops.llseek = default_llseek,
> + },
> + {
> + .filename = "powerpc/rtas/" FIRMWARE_UPDATE_NAME,
> + .rtas_call_name = "ibm,update-flash-64-and-reboot",
> + .status =&rtas_update_flash_data.status,
> + .fops.read = rtas_flash_read_num,
> + .fops.write = rtas_flash_write,
> + .fops.release = rtas_flash_release,
> + .fops.llseek = default_llseek,
> + },
> + {
> + .filename = "powerpc/rtas/" VALIDATE_FLASH_NAME,
> + .rtas_call_name = "ibm,validate-flash-image",
> + .status =&rtas_validate_flash_data.status,
> + .fops.read = manage_flash_read,
> + .fops.write = manage_flash_write,


We have to validate FW here :-) Above two lines needs to be replaced like below.

+ .fops.read = validate_flash_read,
+ .fops.write = validate_flash_write,
+ .fops.release = validate_flash_release,


> + .fops.llseek = default_llseek,
> + },
> + {
> + .filename = "powerpc/rtas/" MANAGE_FLASH_NAME,
> + .rtas_call_name = "ibm,manage-flash-image",
> + .status =&rtas_manage_flash_data.status,
> + .fops.read = validate_flash_read,
> + .fops.write = validate_flash_write,
> + .fops.release = validate_flash_release,

Here we need to manage FW :-) Above three lines needs to be replaced like below.
+ .fops.read = manage_flash_read,
+ .fops.write = manage_flash_write,


I wrote below patch on top of yours to test rtas_flash.

--- rtas_flash.c.org 2013-04-25 04:35:42.000000000 -0400
+++ rtas_flash.c 2013-04-25 05:53:35.000000000 -0400
@@ -267,7 +267,7 @@ static ssize_t rtas_flash_read_msg(struc
mutex_unlock(&rtas_update_flash_mutex);

/* Read as text message */
- len = get_flash_status_msg(uf->status, msg);
+ len = get_flash_status_msg(status, msg);
return simple_read_from_buffer(buf, count, ppos, msg, len);
}

@@ -349,13 +349,13 @@ static ssize_t rtas_flash_write(struct f
fl->blocks[next_free].length = count;
fl->num_blocks++;
out:
- mutex_lock(&rtas_update_flash_mutex);
+ mutex_unlock(&rtas_update_flash_mutex);
return count;

nomem:
rc = -ENOMEM;
error:
- mutex_lock(&rtas_update_flash_mutex);
+ mutex_unlock(&rtas_update_flash_mutex);
return rc;
}

@@ -415,8 +415,10 @@ static ssize_t manage_flash_write(struct
op = RTAS_COMMIT_TMP_IMG;
}

- if (op == -1) /* buf is empty, or contains invalid string */
- return -EINVAL;
+ if (op == -1) { /* buf is empty, or contains invalid string */
+ rc = -EINVAL;
+ goto error;
+ }

manage_flash(args_buf, op);
out:
@@ -668,17 +670,17 @@ static const struct rtas_flash_file rtas
.filename = "powerpc/rtas/" VALIDATE_FLASH_NAME,
.rtas_call_name = "ibm,validate-flash-image",
.status = &rtas_validate_flash_data.status,
- .fops.read = manage_flash_read,
- .fops.write = manage_flash_write,
+ .fops.read = validate_flash_read,
+ .fops.write = validate_flash_write,
+ .fops.release = validate_flash_release,
.fops.llseek = default_llseek,
},
{
.filename = "powerpc/rtas/" MANAGE_FLASH_NAME,
.rtas_call_name = "ibm,manage-flash-image",
.status = &rtas_manage_flash_data.status,
- .fops.read = validate_flash_read,
- .fops.write = validate_flash_write,
- .fops.release = validate_flash_release,
+ .fops.read = manage_flash_read,
+ .fops.write = manage_flash_write,
.fops.llseek = default_llseek,
}
};



-Vasant


> + .fops.llseek = default_llseek,
> + }
> };
>
> static int __init rtas_flash_init(void)
> {
> - int rc;
> + int i;
>
> if (rtas_token("ibm,update-flash-64-and-reboot") ==
> RTAS_UNKNOWN_SERVICE) {
> @@ -710,93 +692,65 @@ static int __init rtas_flash_init(void)
> return 1;
> }
>
> - firmware_flash_pde = create_flash_pde("powerpc/rtas/"
> - FIRMWARE_FLASH_NAME,
> - &rtas_flash_operations);
> - if (firmware_flash_pde == NULL) {
> - rc = -ENOMEM;
> - goto cleanup;
> - }
> + rtas_validate_flash_data.buf = kzalloc(VALIDATE_BUF_SIZE, GFP_KERNEL);
> + if (!rtas_validate_flash_data.buf)
> + return -ENOMEM;
>
> - rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot",
> - sizeof(struct rtas_update_flash_t),
> - firmware_flash_pde);
> - if (rc != 0)
> - goto cleanup;
> -
> - firmware_update_pde = create_flash_pde("powerpc/rtas/"
> - FIRMWARE_UPDATE_NAME,
> - &rtas_flash_operations);
> - if (firmware_update_pde == NULL) {
> - rc = -ENOMEM;
> - goto cleanup;
> + flash_block_cache = kmem_cache_create("rtas_flash_cache",
> + RTAS_BLK_SIZE, RTAS_BLK_SIZE, 0,
> + rtas_block_ctor);
> + if (!flash_block_cache) {
> + printk(KERN_ERR "%s: failed to create block cache\n",
> + __func__);
> + goto enomem_buf;
> }
>
> - rc = initialize_flash_pde_data("ibm,update-flash-64-and-reboot",
> - sizeof(struct rtas_update_flash_t),
> - firmware_update_pde);
> - if (rc != 0)
> - goto cleanup;
> -
> - validate_pde = create_flash_pde("powerpc/rtas/" VALIDATE_FLASH_NAME,
> - &validate_flash_operations);
> - if (validate_pde == NULL) {
> - rc = -ENOMEM;
> - goto cleanup;
> - }
> + for (i = 0; i< ARRAY_SIZE(rtas_flash_files); i++) {
> + const struct rtas_flash_file *f =&rtas_flash_files[i];
> + int token;
>
> - rc = initialize_flash_pde_data("ibm,validate-flash-image",
> - sizeof(struct rtas_validate_flash_t),
> - validate_pde);
> - if (rc != 0)
> - goto cleanup;
> -
> - manage_pde = create_flash_pde("powerpc/rtas/" MANAGE_FLASH_NAME,
> - &manage_flash_operations);
> - if (manage_pde == NULL) {
> - rc = -ENOMEM;
> - goto cleanup;
> - }
> + if (!proc_create(f->filename, S_IRUSR | S_IWUSR, NULL,&f->fops))
> + goto enomem;
>
> - rc = initialize_flash_pde_data("ibm,manage-flash-image",
> - sizeof(struct rtas_manage_flash_t),
> - manage_pde);
> - if (rc != 0)
> - goto cleanup;
> + /*
> + * This code assumes that the status int is the first member of the
> + * struct
> + */
> + token = rtas_token(f->rtas_call_name);
> + if (token == RTAS_UNKNOWN_SERVICE)
> + *f->status = FLASH_AUTH;
> + else
> + *f->status = FLASH_NO_OP;
> + }
>
> rtas_flash_term_hook = rtas_flash_firmware;
> -
> - flash_block_cache = kmem_cache_create("rtas_flash_cache",
> - RTAS_BLK_SIZE, RTAS_BLK_SIZE, 0,
> - rtas_block_ctor);
> - if (!flash_block_cache) {
> - printk(KERN_ERR "%s: failed to create block cache\n",
> - __func__);
> - rc = -ENOMEM;
> - goto cleanup;
> - }
> return 0;
>
> -cleanup:
> - remove_flash_pde(firmware_flash_pde);
> - remove_flash_pde(firmware_update_pde);
> - remove_flash_pde(validate_pde);
> - remove_flash_pde(manage_pde);
> +enomem:
> + while (--i>= 0) {
> + const struct rtas_flash_file *f =&rtas_flash_files[i];
> + remove_proc_entry(f->filename, NULL);
> + }
>
> - return rc;
> + kmem_cache_destroy(flash_block_cache);
> +enomem_buf:
> + kfree(rtas_validate_flash_data.buf);
> + return -ENOMEM;
> }
>
> static void __exit rtas_flash_cleanup(void)
> {
> + int i;
> +
> rtas_flash_term_hook = NULL;
>
> - if (flash_block_cache)
> - kmem_cache_destroy(flash_block_cache);
> + for (i = 0; i< ARRAY_SIZE(rtas_flash_files); i++) {
> + const struct rtas_flash_file *f =&rtas_flash_files[i];
> + remove_proc_entry(f->filename, NULL);
> + }
>
> - remove_flash_pde(firmware_flash_pde);
> - remove_flash_pde(firmware_update_pde);
> - remove_flash_pde(validate_pde);
> - remove_flash_pde(manage_pde);
> + kmem_cache_destroy(flash_block_cache);
> + kfree(rtas_validate_flash_data.buf);
> }
>
> module_init(rtas_flash_init);
>
> _______________________________________________
> Linuxppc-dev mailing list
> [email protected]
> https://lists.ozlabs.org/listinfo/linuxppc-dev
>

2013-04-25 15:01:52

by Vasant Hegde

[permalink] [raw]
Subject: Re: [PATCH 23/28] ppc: Clean up scanlog [RFC]

On 04/16/2013 11:57 PM, David Howells wrote:
> Clean up the pseries scanlog driver's use of procfs:
>
> (1) Don't need to save the proc_dir_entry pointer as we have the filename to
> remove with.
>
> (2) Save the scan log buffer pointer in a static variable (there is only one
> of it) and don't save it in the PDE (which doesn't have a destructor).

Changes looks good.

-Vasant

>
> Signed-off-by: David Howells<[email protected]>
> cc: Benjamin Herrenschmidt<[email protected]>
> cc: Paul Mackerras<[email protected]>
> cc: [email protected]
> ---
>
> arch/powerpc/platforms/pseries/scanlog.c | 29 +++++++++++------------------
> 1 file changed, 11 insertions(+), 18 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/scanlog.c b/arch/powerpc/platforms/pseries/scanlog.c
> index cc220d2..b502ab6 100644
> --- a/arch/powerpc/platforms/pseries/scanlog.c
> +++ b/arch/powerpc/platforms/pseries/scanlog.c
> @@ -41,12 +41,12 @@
>
>
> static unsigned int ibm_scan_log_dump; /* RTAS token */
> -static struct proc_dir_entry *proc_ppc64_scan_log_dump; /* The proc file */
> +static unsigned int *scanlog_buffer; /* The data buffer */
>
> static ssize_t scanlog_read(struct file *file, char __user *buf,
> size_t count, loff_t *ppos)
> {
> - unsigned int *data = PDE_DATA(file_inode(file));
> + unsigned int *data = scanlog_buffer;
> int status;
> unsigned long len, off;
> unsigned int wait_time;
> @@ -134,7 +134,7 @@ static ssize_t scanlog_write(struct file * file, const char __user * buf,
>
> static int scanlog_open(struct inode * inode, struct file * file)
> {
> - unsigned int *data = PDE_DATA(file_inode(file));
> + unsigned int *data = scanlog_buffer;
>
> if (data[0] != 0) {
> /* This imperfect test stops a second copy of the
> @@ -150,10 +150,9 @@ static int scanlog_open(struct inode * inode, struct file * file)
>
> static int scanlog_release(struct inode * inode, struct file * file)
> {
> - unsigned int *data = PDE_DATA(file_inode(file));
> + unsigned int *data = scanlog_buffer;
>
> data[0] = 0;
> -
> return 0;
> }
>
> @@ -169,7 +168,6 @@ const struct file_operations scanlog_fops = {
> static int __init scanlog_init(void)
> {
> struct proc_dir_entry *ent;
> - void *data;
> int err = -ENOMEM;
>
> ibm_scan_log_dump = rtas_token("ibm,scan-log-dump");
> @@ -177,29 +175,24 @@ static int __init scanlog_init(void)
> return -ENODEV;
>
> /* Ideally we could allocate a buffer< 4G */
> - data = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
> - if (!data)
> + scanlog_buffer = kzalloc(RTAS_DATA_BUF_SIZE, GFP_KERNEL);
> + if (!scanlog_buffer)
> goto err;
>
> - ent = proc_create_data("powerpc/rtas/scan-log-dump", S_IRUSR, NULL,
> - &scanlog_fops, data);
> + ent = proc_create("powerpc/rtas/scan-log-dump", S_IRUSR, NULL,
> + &scanlog_fops);
> if (!ent)
> goto err;
> -
> - proc_ppc64_scan_log_dump = ent;
> -
> return 0;
> err:
> - kfree(data);
> + kfree(scanlog_buffer);
> return err;
> }
>
> static void __exit scanlog_cleanup(void)
> {
> - if (proc_ppc64_scan_log_dump) {
> - kfree(proc_ppc64_scan_log_dump->data);
> - remove_proc_entry("scan-log-dump", proc_ppc64_scan_log_dump->parent);
> - }
> + remove_proc_entry("powerpc/rtas/scan-log-dump", NULL);
> + kfree(scanlog_buffer);
> }
>
> module_init(scanlog_init);
>
> _______________________________________________
> Linuxppc-dev mailing list
> [email protected]
> https://lists.ozlabs.org/listinfo/linuxppc-dev
>

2013-04-25 15:23:07

by Vasant Hegde

[permalink] [raw]
Subject: Re: [PATCH 04/28] proc: Supply PDE attribute setting accessor functions [RFC]

On 04/16/2013 11:56 PM, David Howells wrote:
> Supply accessor functions to set attributes in proc_dir_entry structs.
>
> The following are supplied: proc_set_size() and proc_set_user().
>
> Signed-off-by: David Howells<[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> ---
>
> arch/powerpc/kernel/proc_powerpc.c | 2 +-
> arch/powerpc/platforms/pseries/reconfig.c | 2 +-

arch/powerpc side changes looks good.

-Vasant

> drivers/media/pci/ttpci/av7110_ir.c | 2 +-
> drivers/net/irda/vlsi_ir.c | 2 +-
> drivers/net/wireless/airo.c | 34 +++++++++--------------------
> drivers/pci/proc.c | 2 +-
> fs/proc/generic.c | 13 +++++++++++
> include/linux/proc_fs.h | 5 ++++
> kernel/configs.c | 2 +-
> kernel/profile.c | 2 +-
> net/netfilter/xt_recent.c | 3 +--
> sound/core/info.c | 2 +-
> 12 files changed, 38 insertions(+), 33 deletions(-)
>
> diff --git a/arch/powerpc/kernel/proc_powerpc.c b/arch/powerpc/kernel/proc_powerpc.c
> index 41d8ee9..feb8580 100644
> --- a/arch/powerpc/kernel/proc_powerpc.c
> +++ b/arch/powerpc/kernel/proc_powerpc.c
> @@ -83,7 +83,7 @@ static int __init proc_ppc64_init(void)
> &page_map_fops, vdso_data);
> if (!pde)
> return 1;
> - pde->size = PAGE_SIZE;
> + proc_set_size(pde, PAGE_SIZE);
>
> return 0;
> }
> diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
> index d6491bd..f93cdf5 100644
> --- a/arch/powerpc/platforms/pseries/reconfig.c
> +++ b/arch/powerpc/platforms/pseries/reconfig.c
> @@ -452,7 +452,7 @@ static int proc_ppc64_create_ofdt(void)
>
> ent = proc_create("powerpc/ofdt", S_IWUSR, NULL,&ofdt_fops);
> if (ent)
> - ent->size = 0;
> + proc_set_size(ent, 0);
>
> return 0;
> }
> diff --git a/drivers/media/pci/ttpci/av7110_ir.c b/drivers/media/pci/ttpci/av7110_ir.c
> index eb82286..0e763a7 100644
> --- a/drivers/media/pci/ttpci/av7110_ir.c
> +++ b/drivers/media/pci/ttpci/av7110_ir.c
> @@ -375,7 +375,7 @@ int av7110_ir_init(struct av7110 *av7110)
> if (av_cnt == 1) {
> e = proc_create("av7110_ir", S_IWUSR, NULL,&av7110_ir_proc_fops);
> if (e)
> - e->size = 4 + 256 * sizeof(u16);
> + proc_set_size(e, 4 + 256 * sizeof(u16));
> }
>
> tasklet_init(&av7110->ir.ir_tasklet, av7110_emit_key, (unsigned long)&av7110->ir);
> diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
> index e22cd4e..5f47584 100644
> --- a/drivers/net/irda/vlsi_ir.c
> +++ b/drivers/net/irda/vlsi_ir.c
> @@ -1678,7 +1678,7 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> IRDA_WARNING("%s: failed to create proc entry\n",
> __func__);
> } else {
> - ent->size = 0;
> + proc_set_size(ent, 0);
> }
> idev->proc_entry = ent;
> }
> diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
> index 66e398d..21d0233 100644
> --- a/drivers/net/wireless/airo.c
> +++ b/drivers/net/wireless/airo.c
> @@ -4507,73 +4507,63 @@ static int setup_proc_entry( struct net_device *dev,
> airo_entry);
> if (!apriv->proc_entry)
> goto fail;
> - apriv->proc_entry->uid = proc_kuid;
> - apriv->proc_entry->gid = proc_kgid;
> + proc_set_user(apriv->proc_entry, proc_kuid, proc_kgid);
>
> /* Setup the StatsDelta */
> entry = proc_create_data("StatsDelta", S_IRUGO& proc_perm,
> apriv->proc_entry,&proc_statsdelta_ops, dev);
> if (!entry)
> goto fail_stats_delta;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Stats */
> entry = proc_create_data("Stats", S_IRUGO& proc_perm,
> apriv->proc_entry,&proc_stats_ops, dev);
> if (!entry)
> goto fail_stats;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Status */
> entry = proc_create_data("Status", S_IRUGO& proc_perm,
> apriv->proc_entry,&proc_status_ops, dev);
> if (!entry)
> goto fail_status;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the Config */
> entry = proc_create_data("Config", proc_perm,
> apriv->proc_entry,&proc_config_ops, dev);
> if (!entry)
> goto fail_config;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the SSID */
> entry = proc_create_data("SSID", proc_perm,
> apriv->proc_entry,&proc_SSID_ops, dev);
> if (!entry)
> goto fail_ssid;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the APList */
> entry = proc_create_data("APList", proc_perm,
> apriv->proc_entry,&proc_APList_ops, dev);
> if (!entry)
> goto fail_aplist;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the BSSList */
> entry = proc_create_data("BSSList", proc_perm,
> apriv->proc_entry,&proc_BSSList_ops, dev);
> if (!entry)
> goto fail_bsslist;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> + proc_set_user(entry, proc_kuid, proc_kgid);
>
> /* Setup the WepKey */
> entry = proc_create_data("WepKey", proc_perm,
> apriv->proc_entry,&proc_wepkey_ops, dev);
> if (!entry)
> goto fail_wepkey;
> - entry->uid = proc_kuid;
> - entry->gid = proc_kgid;
> -
> + proc_set_user(entry, proc_kuid, proc_kgid);
> return 0;
>
> fail_wepkey:
> @@ -5695,10 +5685,8 @@ static int __init airo_init_module( void )
>
> airo_entry = proc_mkdir_mode("driver/aironet", airo_perm, NULL);
>
> - if (airo_entry) {
> - airo_entry->uid = proc_kuid;
> - airo_entry->gid = proc_kgid;
> - }
> + if (airo_entry)
> + proc_set_user(airo_entry, proc_kuid, proc_kgid);
>
> for (i = 0; i< 4&& io[i]&& irq[i]; i++) {
> airo_print_info("", "Trying to configure ISA adapter at irq=%d "
> diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
> index 12e4fb5..7cde7c1 100644
> --- a/drivers/pci/proc.c
> +++ b/drivers/pci/proc.c
> @@ -419,7 +419,7 @@ int pci_proc_attach_device(struct pci_dev *dev)
> &proc_bus_pci_operations, dev);
> if (!e)
> return -ENOMEM;
> - e->size = dev->cfg_size;
> + proc_set_size(e, dev->cfg_size);
> dev->procent = e;
>
> return 0;
> diff --git a/fs/proc/generic.c b/fs/proc/generic.c
> index 1c07cad..5f6f6c3 100644
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -498,6 +498,19 @@ out:
> return NULL;
> }
> EXPORT_SYMBOL(proc_create_data);
> +
> +void proc_set_size(struct proc_dir_entry *de, loff_t size)
> +{
> + de->size = size;
> +}
> +EXPORT_SYMBOL(proc_set_size);
> +
> +void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid)
> +{
> + de->uid = uid;
> + de->gid = gid;
> +}
> +EXPORT_SYMBOL(proc_set_user);
>
> static void free_proc_entry(struct proc_dir_entry *de)
> {
> diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
> index 805edac..28a4d7e 100644
> --- a/include/linux/proc_fs.h
> +++ b/include/linux/proc_fs.h
> @@ -130,6 +130,9 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
> extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
> struct proc_dir_entry *parent);
>
> +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 struct file *proc_ns_fget(int fd);
> extern bool proc_ns_inode(struct inode *inode);
>
> @@ -158,6 +161,8 @@ static inline struct proc_dir_entry *proc_mkdir(const char *name,
> struct proc_dir_entry *parent) {return NULL;}
> static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
> umode_t mode, struct proc_dir_entry *parent) { return NULL; }
> +static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
> +static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
>
> struct tty_driver;
> static inline void proc_tty_register_driver(struct tty_driver *driver) {};
> diff --git a/kernel/configs.c b/kernel/configs.c
> index 42e8fa0..c18b1f1 100644
> --- a/kernel/configs.c
> +++ b/kernel/configs.c
> @@ -79,7 +79,7 @@ static int __init ikconfig_init(void)
> if (!entry)
> return -ENOMEM;
>
> - entry->size = kernel_config_data_size;
> + proc_set_size(entry, kernel_config_data_size);
>
> return 0;
> }
> diff --git a/kernel/profile.c b/kernel/profile.c
> index 524ce5e..0bf4007 100644
> --- a/kernel/profile.c
> +++ b/kernel/profile.c
> @@ -600,7 +600,7 @@ int __ref create_proc_profile(void) /* false positive from hotcpu_notifier */
> NULL,&proc_profile_operations);
> if (!entry)
> return 0;
> - entry->size = (1+prof_len) * sizeof(atomic_t);
> + proc_set_size(entry, (1 + prof_len) * sizeof(atomic_t));
> hotcpu_notifier(profile_cpu_callback, 0);
> return 0;
> }
> diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
> index 3db2d38..1e657cf 100644
> --- a/net/netfilter/xt_recent.c
> +++ b/net/netfilter/xt_recent.c
> @@ -401,8 +401,7 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
> ret = -ENOMEM;
> goto out;
> }
> - pde->uid = uid;
> - pde->gid = gid;
> + proc_set_user(pde, uid, gid);
> #endif
> spin_lock_bh(&recent_lock);
> list_add_tail(&t->list,&recent_net->tables);
> diff --git a/sound/core/info.c b/sound/core/info.c
> index 3aa8864..c7f41c3 100644
> --- a/sound/core/info.c
> +++ b/sound/core/info.c
> @@ -970,7 +970,7 @@ int snd_info_register(struct snd_info_entry * entry)
> mutex_unlock(&info_mutex);
> return -ENOMEM;
> }
> - p->size = entry->size;
> + proc_set_size(p, entry->size);
> }
> entry->p = p;
> if (entry->parent)
>
> _______________________________________________
> Linuxppc-dev mailing list
> [email protected]
> https://lists.ozlabs.org/listinfo/linuxppc-dev
>

2013-05-01 20:51:17

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 00/28] Privatise procfs internals [RFC]

On Tue, Apr 16, 2013 at 8:25 PM, David Howells <[email protected]> wrote:
> Here is a series of patches to make the procfs internals private to the procfs
> filesystem. This is built on top of the patches to eliminate
> create_proc_read_entry() after the kill-read_proc_t tag.
>
> These patches include fixes for the places that are attempting to abuse
> proc_dir_entry->count and doing it incorrectly because PID namespaces now
> exist.
>
> All accesses to the PDE struct have been replaced with out-of-line accessor
> functions. This is a bit less efficient than it used to be, but this could be
> mitigated by using inode->i_private.
>
> The internal procfs structs have moved to fs/procfs/internal.h. Some of the
> remaining stuff in linux/proc_fs.h has been split out to linux/kcore.h and
> linux/proc_ns.h as they's separate specialised intefaces.

drivers/nubus/proc.c:156:7: error: dereferencing pointer to incomplete type
drivers/nubus/proc.c:158:22: error: dereferencing pointer to incomplete type
make[3]: *** [drivers/nubus/proc.o] Error 1
make[2]: *** [drivers/nubus] Error 2
drivers/zorro/proc.c:142:7: error: dereferencing pointer to incomplete type
make[3]: *** [drivers/zorro/proc.o] Error 1
make[2]: *** [drivers/zorro] Error 2

http://kisskb.ellerman.id.au/kisskb/buildresult/8673100/

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2013-05-03 20:27:08

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 00/28] Privatise procfs internals [RFC]

On Wed, May 1, 2013 at 10:51 PM, Geert Uytterhoeven
<[email protected]> wrote:
> On Tue, Apr 16, 2013 at 8:25 PM, David Howells <[email protected]> wrote:
>> Here is a series of patches to make the procfs internals private to the procfs
>> filesystem. This is built on top of the patches to eliminate
>> create_proc_read_entry() after the kill-read_proc_t tag.
>>
>> These patches include fixes for the places that are attempting to abuse
>> proc_dir_entry->count and doing it incorrectly because PID namespaces now
>> exist.
>>
>> All accesses to the PDE struct have been replaced with out-of-line accessor
>> functions. This is a bit less efficient than it used to be, but this could be
>> mitigated by using inode->i_private.
>>
>> The internal procfs structs have moved to fs/procfs/internal.h. Some of the
>> remaining stuff in linux/proc_fs.h has been split out to linux/kcore.h and
>> linux/proc_ns.h as they's separate specialised intefaces.
>
> drivers/nubus/proc.c:156:7: error: dereferencing pointer to incomplete type
> drivers/nubus/proc.c:158:22: error: dereferencing pointer to incomplete type
> make[3]: *** [drivers/nubus/proc.o] Error 1
> make[2]: *** [drivers/nubus] Error 2

I've just sent out a patch to fix this.

> drivers/zorro/proc.c:142:7: error: dereferencing pointer to incomplete type
> make[3]: *** [drivers/zorro/proc.o] Error 1
> make[2]: *** [drivers/zorro] Error 2

This one is fixed in mainline.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds