Patchwork [24/28] proc: Supply an accessor to get the name in a proc_dir_entry struct [RFC]

login
register
mail settings
Submitter David Howells
Date April 16, 2013, 6:27 p.m.
Message ID <20130416182725.27773.42175.stgit@warthog.procyon.org.uk>
Download mbox | patch
Permalink /patch/237053/
State Awaiting Upstream
Headers show

Comments

David Howells - April 16, 2013, 6:27 p.m.
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 <dhowells@redhat.com>
cc: Harald Welte <laforge@netfilter.org>
cc: Jan Engelhardt <jengelh@medozas.de>
cc: netfilter-devel@vger.kernel.org
---

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


--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Harald Welte - April 16, 2013, 10:20 p.m.
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

Patch

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;