Skip to content

Commit

Permalink
of: Improve prom_update_property() function
Browse files Browse the repository at this point in the history
prom_update_property() currently fails if the property doesn't
actually exist yet which isn't what we want. Change to add-or-update
instead of update-only, then we can remove a lot duplicated lines.

Suggested-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>
Acked-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
  • Loading branch information
Dong Aisheng authored and Benjamin Herrenschmidt committed Jul 11, 2012
1 parent b416c9a commit 475d009
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 30 deletions.
8 changes: 1 addition & 7 deletions arch/powerpc/platforms/85xx/p1022_ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,7 @@ void __init p1022_ds_pic_init(void)
*/
static void __init disable_one_node(struct device_node *np, struct property *new)
{
struct property *old;

old = of_find_property(np, new->name, NULL);
if (old)
prom_update_property(np, new, old);
else
prom_add_property(np, new);
prom_update_property(np, new);
}

/* TRUE if there is a "video=fslfb" command-line parameter. */
Expand Down
8 changes: 1 addition & 7 deletions arch/powerpc/platforms/pseries/mobility.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ static int update_dt_property(struct device_node *dn, struct property **prop,
const char *name, u32 vd, char *value)
{
struct property *new_prop = *prop;
struct property *old_prop;
int more = 0;

/* A negative 'vd' value indicates that only part of the new property
Expand Down Expand Up @@ -117,12 +116,7 @@ static int update_dt_property(struct device_node *dn, struct property **prop,
}

if (!more) {
old_prop = of_find_property(dn, new_prop->name, NULL);
if (old_prop)
prom_update_property(dn, new_prop, old_prop);
else
prom_add_property(dn, new_prop);

prom_update_property(dn, new_prop);
new_prop = NULL;
}

Expand Down
16 changes: 6 additions & 10 deletions arch/powerpc/platforms/pseries/reconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static int do_update_property(char *buf, size_t bufsize)
unsigned char *value;
char *name, *end, *next_prop;
int rc, length;
struct property *newprop, *oldprop;
struct property *newprop;
buf = parse_node(buf, bufsize, &np);
end = buf + bufsize;

Expand All @@ -443,25 +443,21 @@ static int do_update_property(char *buf, size_t bufsize)
if (!next_prop)
return -EINVAL;

if (!strlen(name))
return -ENODEV;

newprop = new_property(name, length, value, NULL);
if (!newprop)
return -ENOMEM;

if (!strcmp(name, "slb-size") || !strcmp(name, "ibm,slb-size"))
slb_set_size(*(int *)value);

oldprop = of_find_property(np, name,NULL);
if (!oldprop) {
if (strlen(name))
return prom_add_property(np, newprop);
return -ENODEV;
}

upd_value.node = np;
upd_value.property = newprop;
pSeries_reconfig_notify(PSERIES_UPDATE_PROPERTY, &upd_value);

rc = prom_update_property(np, newprop, oldprop);
rc = prom_update_property(np, newprop);
if (rc)
return rc;

Expand All @@ -486,7 +482,7 @@ static int do_update_property(char *buf, size_t bufsize)

rc = pSeries_reconfig_notify(action, value);
if (rc) {
prom_update_property(np, oldprop, newprop);
prom_update_property(np, newprop);
return rc;
}
}
Expand Down
15 changes: 11 additions & 4 deletions drivers/of/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,21 +1073,28 @@ int prom_remove_property(struct device_node *np, struct property *prop)
}

/*
* prom_update_property - Update a property in a node.
* prom_update_property - Update a property in a node, if the property does
* not exist, add it.
*
* 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 *newprop)
{
struct property **next;
struct property **next, *oldprop;
unsigned long flags;
int found = 0;

if (!newprop->name)
return -EINVAL;

oldprop = of_find_property(np, newprop->name, NULL);
if (!oldprop)
return prom_add_property(np, newprop);

write_lock_irqsave(&devtree_lock, flags);
next = &np->properties;
while (*next) {
Expand Down
5 changes: 5 additions & 0 deletions fs/proc/proc_devtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ void proc_device_tree_update_prop(struct proc_dir_entry *pde,
{
struct proc_dir_entry *ent;

if (!oldprop) {
proc_device_tree_add_prop(pde, newprop);
return;
}

for (ent = pde->subdir; ent != NULL; ent = ent->next)
if (ent->data == oldprop)
break;
Expand Down
3 changes: 1 addition & 2 deletions include/linux/of.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ extern int of_machine_is_compatible(const char *compat);
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);
struct property *newprop);

#if defined(CONFIG_OF_DYNAMIC)
/* For updating the device tree at runtime */
Expand Down

0 comments on commit 475d009

Please sign in to comment.