proc: Supply a function to remove a proc entry by PDE
authorDavid Howells <dhowells@redhat.com>
Fri, 12 Apr 2013 16:27:28 +0000 (17:27 +0100)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 1 May 2013 21:29:46 +0000 (17:29 -0400)
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 <dhowells@redhat.com>
Acked-by: Grant Likely <grant.likely@linaro.or>
cc: linux-acpi@vger.kernel.org
cc: openipmi-developer@lists.sourceforge.net
cc: devicetree-discuss@lists.ozlabs.org
cc: linux-pci@vger.kernel.org
cc: netdev@vger.kernel.org
cc: netfilter-devel@vger.kernel.org
cc: alsa-devel@alsa-project.org
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
14 files changed:
drivers/acpi/sbs.c
drivers/char/ipmi/ipmi_msghandler.c
drivers/misc/sgi-gru/gruprocfs.c
drivers/of/base.c
drivers/pci/proc.c
fs/proc/generic.c
fs/proc/vmcore.c
include/linux/proc_fs.h
kernel/irq/proc.c
net/8021q/vlanproc.c
net/core/pktgen.c
net/ipv4/netfilter/ipt_CLUSTERIP.c
net/ipv6/proc.c
sound/core/info.c

index a296e08d76b6b8a0a5a30e04888940417e293f23..b6241eeb1132a0b3afed934ba96f52545a4a1d13 100644 (file)
@@ -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
 }
 
index 1420bbbe1a61805748ca3fd89d71aaa1f2ea5f65..4d439d2fcfd685a7e3e969aee8d7cef5e1cf14ee 100644 (file)
@@ -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);
index 950dbe9ecb36540a5eaaffaa63b62ed976360763..797d7962cc8831ce70b3dd852874cd4ab6a02ca0 100644 (file)
@@ -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);
        }
 }
 
index 321d3ef050065e12b2d639e02fada00ec6b9e658..9c704369eda858644b49d39166205883bb0789a6 100644 (file)
@@ -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)
index 7cde7c131fd0d36dfe575d706dfb385897a37de2..08126087ec3125c29de84c5b9e5f68d45d2b0328 100644 (file)
@@ -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;
 }
 
index 75e08d36b2f1141c28e7dd730e00afa5f21bcdba..d9631d9b7affc22ae87534b1f4955959aefa84a9 100644 (file)
@@ -624,3 +624,10 @@ void *proc_get_parent_data(const struct inode *inode)
        return de->parent->data;
 }
 EXPORT_SYMBOL_GPL(proc_get_parent_data);
+
+void proc_remove(struct proc_dir_entry *de)
+{
+       if (de)
+               remove_proc_subtree(de->name, de->parent);
+}
+EXPORT_SYMBOL(proc_remove);
index 38edddc25816299a46e36ab4d93ba2443757b948..17f7e080d7ff6c5c301c6b71bd1c793b1439357c 100644 (file)
@@ -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;
        }
 
index bae82074234194e2dda400a590f53b3bed3e53a0..cb78d5be6859447600d315c909327cf3dfe0af0c 100644 (file)
@@ -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);
 
@@ -101,6 +102,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)
 
index d59ae3751a33e0ab09e37ba9119aac8ee28a65d1..19ed5c425c3b95e6d49ab8fb7bc7dd9717d2b570 100644 (file)
@@ -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)
index 959ddbb0ca4dabc3dcc29e32531d6ebe3ca4badd..1d0e89213a28e8e9200a2ead740c6980f9be46c5 100644 (file)
@@ -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;
 }
 
index f6af4fe59f2e960c5d6d170c094906d962956809..6c41e979dc884b7b34d79d03f2cb396669680773 100644 (file)
@@ -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);
index e4738fef070a4738b7f1a2ead641b28aad837cbc..0b732efd32e20aa8e22e6c9bd5aa4edfb7e5516d 100644 (file)
@@ -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);
index 7ea6e180139c702090159984fc099bfc2b31636f..537d9ee7209f91254d6b75446b8495a9679d1bf1 100644 (file)
@@ -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;
 }
index c7f41c3bbd5cd3379169d8882df5f25eac0c1118..3c9bd6b10a961e6d430d044a69fe643c0cdc07ba 100644 (file)
@@ -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;
 }