Skip to content

Commit 02ed594

Browse files
Xiubo Liglikely
authored andcommitted
of: fix of_update_property()
The of_update_property() is intented to update a property in a node and if the property does not exist, will add it. The second search of the property is possibly won't be found, that maybe removed by other thread just before the second search begain. Using the __of_find_property() and __of_add_property() instead and move them into lock operations. Signed-off-by: Xiubo Li <[email protected]> Cc: Pantelis Antoniou <[email protected]> Signed-off-by: Grant Likely <[email protected]>
1 parent 62664f6 commit 02ed594

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

drivers/of/base.c

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ int of_update_property(struct device_node *np, struct property *newprop)
15971597
{
15981598
struct property **next, *oldprop;
15991599
unsigned long flags;
1600-
int rc, found = 0;
1600+
int rc = 0;
16011601

16021602
rc = of_property_notify(OF_RECONFIG_UPDATE_PROPERTY, np, newprop);
16031603
if (rc)
@@ -1606,36 +1606,28 @@ int of_update_property(struct device_node *np, struct property *newprop)
16061606
if (!newprop->name)
16071607
return -EINVAL;
16081608

1609-
oldprop = of_find_property(np, newprop->name, NULL);
1610-
if (!oldprop)
1611-
return of_add_property(np, newprop);
1612-
16131609
raw_spin_lock_irqsave(&devtree_lock, flags);
1614-
next = &np->properties;
1615-
while (*next) {
1616-
if (*next == oldprop) {
1617-
/* found the node */
1618-
newprop->next = oldprop->next;
1619-
*next = newprop;
1620-
oldprop->next = np->deadprops;
1621-
np->deadprops = oldprop;
1622-
found = 1;
1623-
break;
1624-
}
1625-
next = &(*next)->next;
1610+
oldprop = __of_find_property(np, newprop->name, NULL);
1611+
if (!oldprop) {
1612+
/* add the node */
1613+
rc = __of_add_property(np, newprop);
1614+
} else {
1615+
/* replace the node */
1616+
next = &oldprop;
1617+
newprop->next = oldprop->next;
1618+
*next = newprop;
1619+
oldprop->next = np->deadprops;
1620+
np->deadprops = oldprop;
16261621
}
16271622
raw_spin_unlock_irqrestore(&devtree_lock, flags);
16281623

1629-
if (!found)
1630-
return -ENODEV;
1631-
16321624
#ifdef CONFIG_PROC_DEVICETREE
16331625
/* try to add to proc as well if it was initialized */
1634-
if (np->pde)
1626+
if (!rc && np->pde)
16351627
proc_device_tree_update_prop(np->pde, newprop, oldprop);
16361628
#endif /* CONFIG_PROC_DEVICETREE */
16371629

1638-
return 0;
1630+
return rc;
16391631
}
16401632

16411633
#if defined(CONFIG_OF_DYNAMIC)

0 commit comments

Comments
 (0)