diff options
author | Rob Herring <robh@kernel.org> | 2023-08-18 22:41:01 +0200 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2023-08-22 00:09:57 +0200 |
commit | fab610be30dbaa4ef5dcfabe4dc498c557a1b7ad (patch) | |
tree | b9e6f627170855e7332856402748b849346e5eae /drivers/of/base.c | |
parent | of: dynamic: Move dead property list check into property add/update functions (diff) | |
download | linux-fab610be30dbaa4ef5dcfabe4dc498c557a1b7ad.tar.xz linux-fab610be30dbaa4ef5dcfabe4dc498c557a1b7ad.zip |
of: Refactor node and property manipulation function locking
All callers of __of_{add,remove,update}_property() and
__of_{attach,detach}_node() wrap the call with the devtree_lock
spinlock. Let's move the spinlock into the functions. This allows moving
the sysfs update functions into those functions as well.
Link: https://lore.kernel.org/r/20230801-dt-changeset-fixes-v3-6-5f0410e007dd@kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r-- | drivers/of/base.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 3f9ddd18ff4b..8d93cb6ea9cd 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1551,21 +1551,32 @@ static struct property *__of_remove_property_from_list(struct property **list, s */ int __of_add_property(struct device_node *np, struct property *prop) { + int rc = 0; + unsigned long flags; struct property **next; + raw_spin_lock_irqsave(&devtree_lock, flags); + __of_remove_property_from_list(&np->deadprops, prop); prop->next = NULL; next = &np->properties; while (*next) { - if (strcmp(prop->name, (*next)->name) == 0) + if (strcmp(prop->name, (*next)->name) == 0) { /* duplicate ! don't insert it */ - return -EEXIST; - + rc = -EEXIST; + goto out_unlock; + } next = &(*next)->next; } *next = prop; +out_unlock: + raw_spin_unlock_irqrestore(&devtree_lock, flags); + if (rc) + return rc; + + __of_add_property_sysfs(np, prop); return 0; } @@ -1576,18 +1587,10 @@ int __of_add_property(struct device_node *np, struct property *prop) */ int of_add_property(struct device_node *np, struct property *prop) { - unsigned long flags; int rc; mutex_lock(&of_mutex); - - raw_spin_lock_irqsave(&devtree_lock, flags); rc = __of_add_property(np, prop); - raw_spin_unlock_irqrestore(&devtree_lock, flags); - - if (!rc) - __of_add_property_sysfs(np, prop); - mutex_unlock(&of_mutex); if (!rc) @@ -1599,14 +1602,24 @@ EXPORT_SYMBOL_GPL(of_add_property); int __of_remove_property(struct device_node *np, struct property *prop) { + unsigned long flags; + int rc = -ENODEV; + + raw_spin_lock_irqsave(&devtree_lock, flags); + if (__of_remove_property_from_list(&np->properties, prop)) { /* Found the property, add it to deadprops list */ prop->next = np->deadprops; np->deadprops = prop; - return 0; + rc = 0; } - return -ENODEV; + raw_spin_unlock_irqrestore(&devtree_lock, flags); + if (rc) + return rc; + + __of_remove_property_sysfs(np, prop); + return 0; } /** @@ -1621,21 +1634,13 @@ int __of_remove_property(struct device_node *np, struct property *prop) */ int of_remove_property(struct device_node *np, struct property *prop) { - unsigned long flags; int rc; if (!prop) return -ENODEV; mutex_lock(&of_mutex); - - raw_spin_lock_irqsave(&devtree_lock, flags); rc = __of_remove_property(np, prop); - raw_spin_unlock_irqrestore(&devtree_lock, flags); - - if (!rc) - __of_remove_property_sysfs(np, prop); - mutex_unlock(&of_mutex); if (!rc) @@ -1649,6 +1654,9 @@ int __of_update_property(struct device_node *np, struct property *newprop, struct property **oldpropp) { struct property **next, *oldprop; + unsigned long flags; + + raw_spin_lock_irqsave(&devtree_lock, flags); __of_remove_property_from_list(&np->deadprops, newprop); @@ -1670,6 +1678,10 @@ int __of_update_property(struct device_node *np, struct property *newprop, *next = newprop; } + raw_spin_unlock_irqrestore(&devtree_lock, flags); + + __of_update_property_sysfs(np, newprop, oldprop); + return 0; } @@ -1685,21 +1697,13 @@ int __of_update_property(struct device_node *np, struct property *newprop, int of_update_property(struct device_node *np, struct property *newprop) { struct property *oldprop; - unsigned long flags; int rc; if (!newprop->name) return -EINVAL; mutex_lock(&of_mutex); - - raw_spin_lock_irqsave(&devtree_lock, flags); rc = __of_update_property(np, newprop, &oldprop); - raw_spin_unlock_irqrestore(&devtree_lock, flags); - - if (!rc) - __of_update_property_sysfs(np, newprop, oldprop); - mutex_unlock(&of_mutex); if (!rc) |