diff options
author | Xiubo Li <Li.Xiubo@freescale.com> | 2014-01-22 00:57:39 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@linaro.org> | 2014-02-04 12:21:07 -0500 |
commit | 62664f67775fad840cf6f68d6b5f428817bef6c5 (patch) | |
tree | b05d5f8fba0b95c6abc92a4c1389de725d483aa5 /drivers/of/base.c | |
parent | e3963fd60a83967573f6330c9db134bd581da746 (diff) |
of: add __of_add_property() without lock operations
There two places will use the same code for adding one new property to
the DT node. Adding __of_add_property() and prepare for fixing
of_update_property()'s bug.
Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Grant Likely <grant.likely@linaro.org>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r-- | drivers/of/base.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 87038d80b473..6ad3dc976b18 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -1493,11 +1493,31 @@ static int of_property_notify(int action, struct device_node *np, | |||
1493 | #endif | 1493 | #endif |
1494 | 1494 | ||
1495 | /** | 1495 | /** |
1496 | * __of_add_property - Add a property to a node without lock operations | ||
1497 | */ | ||
1498 | static int __of_add_property(struct device_node *np, struct property *prop) | ||
1499 | { | ||
1500 | struct property **next; | ||
1501 | |||
1502 | prop->next = NULL; | ||
1503 | next = &np->properties; | ||
1504 | while (*next) { | ||
1505 | if (strcmp(prop->name, (*next)->name) == 0) | ||
1506 | /* duplicate ! don't insert it */ | ||
1507 | return -EEXIST; | ||
1508 | |||
1509 | next = &(*next)->next; | ||
1510 | } | ||
1511 | *next = prop; | ||
1512 | |||
1513 | return 0; | ||
1514 | } | ||
1515 | |||
1516 | /** | ||
1496 | * of_add_property - Add a property to a node | 1517 | * of_add_property - Add a property to a node |
1497 | */ | 1518 | */ |
1498 | int of_add_property(struct device_node *np, struct property *prop) | 1519 | int of_add_property(struct device_node *np, struct property *prop) |
1499 | { | 1520 | { |
1500 | struct property **next; | ||
1501 | unsigned long flags; | 1521 | unsigned long flags; |
1502 | int rc; | 1522 | int rc; |
1503 | 1523 | ||
@@ -1505,27 +1525,17 @@ int of_add_property(struct device_node *np, struct property *prop) | |||
1505 | if (rc) | 1525 | if (rc) |
1506 | return rc; | 1526 | return rc; |
1507 | 1527 | ||
1508 | prop->next = NULL; | ||
1509 | raw_spin_lock_irqsave(&devtree_lock, flags); | 1528 | raw_spin_lock_irqsave(&devtree_lock, flags); |
1510 | next = &np->properties; | 1529 | rc = __of_add_property(np, prop); |
1511 | while (*next) { | ||
1512 | if (strcmp(prop->name, (*next)->name) == 0) { | ||
1513 | /* duplicate ! don't insert it */ | ||
1514 | raw_spin_unlock_irqrestore(&devtree_lock, flags); | ||
1515 | return -1; | ||
1516 | } | ||
1517 | next = &(*next)->next; | ||
1518 | } | ||
1519 | *next = prop; | ||
1520 | raw_spin_unlock_irqrestore(&devtree_lock, flags); | 1530 | raw_spin_unlock_irqrestore(&devtree_lock, flags); |
1521 | 1531 | ||
1522 | #ifdef CONFIG_PROC_DEVICETREE | 1532 | #ifdef CONFIG_PROC_DEVICETREE |
1523 | /* try to add to proc as well if it was initialized */ | 1533 | /* try to add to proc as well if it was initialized */ |
1524 | if (np->pde) | 1534 | if (!rc && np->pde) |
1525 | proc_device_tree_add_prop(np->pde, prop); | 1535 | proc_device_tree_add_prop(np->pde, prop); |
1526 | #endif /* CONFIG_PROC_DEVICETREE */ | 1536 | #endif /* CONFIG_PROC_DEVICETREE */ |
1527 | 1537 | ||
1528 | return 0; | 1538 | return rc; |
1529 | } | 1539 | } |
1530 | 1540 | ||
1531 | /** | 1541 | /** |