[PATCH 3/5] powerpc: prom.c support for updating and removing device tree entries
Dave C Boutcher
sleddog at us.ibm.com
Wed Jan 11 21:02:46 EST 2006
Add support for updating and removing device tree
properties. Since we hand out pointers to properties with gay
abandon, we can't just free the property storage. Instead we
move deleted, or the old copy of an updated property, to a
"dead properties" list.
Also note, its not feasable to kref device tree properties.
we call get_property() all over the kernel in a wild variety
of contexts.
One consequence of this change is that we now take a
read_lock(&devtree_lock) when doing get_property().
Signed-off-by: Dave Boutcher <sleddog at us.ibm.com>
arch/powerpc/kernel/prom.c | 93 ++++++++++++++++++++++++++++++++++++++++++++-
include/asm-powerpc/prom.h | 5 ++
2 files changed, 96 insertions(+), 2 deletions(-)
diff -uNr -X exclude-files linux-2.6.15-patched/include/asm-powerpc/prom.h linux-2.6.15-patched2/include/asm-powerpc/prom.h
--- linux-2.6.15-patched/include/asm-powerpc/prom.h 2006-01-11 01:52:09.000000000 -0600
+++ linux-2.6.15-patched2/include/asm-powerpc/prom.h 2006-01-11 02:59:48.000000000 -0600
@@ -127,6 +127,7 @@
char *full_name;
struct property *properties;
+ struct property *deadprops; /* removed properties */
struct device_node *parent;
struct device_node *child;
struct device_node *sibling;
@@ -204,6 +205,10 @@
extern int prom_n_intr_cells(struct device_node* np);
extern void prom_get_irq_senses(unsigned char *senses, int off, int max);
extern int prom_add_property(struct device_node* np, struct property* prop);
+extern int prom_remove_property(struct device_node* np, struct property* prop);
+extern int prom_update_property(struct device_node* np,
+ struct property* newprop,
+ struct property *oldprop);
#ifdef CONFIG_PPC32
/*
diff -uNr -X exclude-files linux-2.6.15-patched/arch/powerpc/kernel/prom.c linux-2.6.15-patched2/arch/powerpc/kernel/prom.c
--- linux-2.6.15-patched/arch/powerpc/kernel/prom.c 2006-01-11 02:40:12.000000000 -0600
+++ linux-2.6.15-patched2/arch/powerpc/kernel/prom.c 2006-01-11 02:59:49.000000000 -0600
@@ -1801,6 +1801,11 @@
kfree(prop->value);
kfree(prop);
prop = next;
+
+ if (!prop) {
+ prop = node->deadprops;
+ node->deadprops = NULL;
+ }
}
kfree(node->intrs);
kfree(node->addrs);
@@ -1957,13 +1962,16 @@
{
struct property *pp;
+ read_lock(&devtree_lock);
for (pp = np->properties; pp != 0; pp = pp->next)
if (strcmp(pp->name, name) == 0) {
if (lenp != 0)
*lenp = pp->length;
- return pp->value;
+ break;
}
- return NULL;
+ read_unlock(&devtree_lock);
+
+ return pp ? pp->value : NULL;
}
EXPORT_SYMBOL(get_property);
@@ -1997,6 +2005,87 @@
return 0;
}
+/*
+ * Remove a property from a node. Note that we don't actually
+ * remove it, since we have given out who-knows-how-many pointers
+ * to the data using get-property. Instead we just move the property
+ * to the "dead properties" list, so it won't be found any more.
+ */
+int prom_remove_property(struct device_node* np, struct property* prop)
+{
+ struct property **next;
+ int found = 0;
+
+ write_lock(&devtree_lock);
+ next = &np->properties;
+ while (*next) {
+ if (*next == prop) {
+ /* found the node */
+ *next = prop->next;
+ prop->next = np->deadprops;
+ np->deadprops = prop;
+ found = 1;
+ break;
+ }
+ next = &(*next)->next;
+ }
+ write_unlock(&devtree_lock);
+
+ if (!found)
+ return -ENODEV;
+
+#ifdef CONFIG_PROC_DEVICETREE
+ /* try to remove the proc node as well */
+ if (np->pde)
+ proc_device_tree_remove_prop(np->pde, prop);
+#endif /* CONFIG_PROC_DEVICETREE */
+
+ return 0;
+}
+
+/*
+ * Update a property in a node. Note that we don't actually
+ * remove it, since we have given out who-knows-how-many pointers
+ * to the data using get-property. Instead we just move the property
+ * to the "dead properties" list, and add the new property to the
+ * property list
+ */
+int prom_update_property(struct device_node* np,
+ struct property* newprop,
+ struct property *oldprop)
+{
+ struct property **next;
+ int found = 0;
+
+ write_lock(&devtree_lock);
+ next = &np->properties;
+ while (*next) {
+ if (*next == oldprop) {
+ /* found the node */
+ newprop->next = oldprop->next;
+ *next = newprop;
+ oldprop->next = np->deadprops;
+ np->deadprops = oldprop;
+ found = 1;
+ break;
+ }
+ next = &(*next)->next;
+ }
+ write_unlock(&devtree_lock);
+
+ if (!found)
+ return -ENODEV;
+
+#ifdef CONFIG_PROC_DEVICETREE
+ /* try to add to proc as well if it was initialized */
+ if (np->pde)
+ proc_device_tree_update_prop(np->pde, newprop,
+ oldprop);
+#endif /* CONFIG_PROC_DEVICETREE */
+
+ return 0;
+}
+
/* I quickly hacked that one, check against spec ! */
static inline unsigned long
bus_space_to_resource_flags(unsigned int bus_space)
--
Dave Boutcher
More information about the Linuxppc64-dev
mailing list