Lines Matching +full:string +full:- +full:array +full:- +full:property
1 // SPDX-License-Identifier: GPL-2.0
15 #include <linux/string.h>
26 * of_node_get() - Increment refcount of a node
35 kobject_get(&node->kobj); in of_node_get()
41 * of_node_put() - Decrement refcount of a node
48 kobject_put(&node->kobj); in of_node_put()
76 func("changeset: " prefix "%-15s %pOF%s%s\n", \
78 prop ? ":" : "", prop ? prop->name : ""); \
88 of_changeset_action_debug("notify: ", action, pr->dn, pr->prop); in of_reconfig_notify()
95 * of_reconfig_get_state_change() - Returns new state of device
96 * @action - action of the of notifier
97 * @arg - argument of the of notifier
102 * going from disabled to enabled and -1 on no change.
106 struct property *prop, *old_prop = NULL; in of_reconfig_get_state_change()
113 prop = of_find_property(pr->dn, "status", NULL); in of_reconfig_get_state_change()
117 prop = pr->prop; in of_reconfig_get_state_change()
120 prop = pr->prop; in of_reconfig_get_state_change()
121 old_prop = pr->old_prop; in of_reconfig_get_state_change()
128 status_state = -1; in of_reconfig_get_state_change()
129 old_status_state = -1; in of_reconfig_get_state_change()
130 prev_state = -1; in of_reconfig_get_state_change()
131 new_state = -1; in of_reconfig_get_state_change()
133 if (prop && !strcmp(prop->name, "status")) { in of_reconfig_get_state_change()
135 status_state = !strcmp(prop->value, "okay") || in of_reconfig_get_state_change()
136 !strcmp(prop->value, "ok"); in of_reconfig_get_state_change()
138 old_status_state = !strcmp(old_prop->value, "okay") || in of_reconfig_get_state_change()
139 !strcmp(old_prop->value, "ok"); in of_reconfig_get_state_change()
145 /* -1 & 0 status either missing or okay */ in of_reconfig_get_state_change()
149 /* -1 & 0 status either missing or okay */ in of_reconfig_get_state_change()
155 /* no status property -> enabled (legacy) */ in of_reconfig_get_state_change()
163 /* no status property -> enabled (legacy) */ in of_reconfig_get_state_change()
183 struct property *prop, struct property *oldprop) in of_property_notify()
206 np->name = __of_get_property(np, "name", NULL); in __of_attach_node()
207 if (!np->name) in __of_attach_node()
208 np->name = "<NULL>"; in __of_attach_node()
216 np->phandle = be32_to_cpup(phandle); in __of_attach_node()
218 np->phandle = 0; in __of_attach_node()
221 np->child = NULL; in __of_attach_node()
222 np->sibling = np->parent->child; in __of_attach_node()
223 np->parent->child = np; in __of_attach_node()
225 np->fwnode.flags |= FWNODE_FLAG_NOT_DEVICE; in __of_attach_node()
233 * of_attach_node() - Plug a device node into the tree and global list.
259 parent = np->parent; in __of_detach_node()
265 if (parent->child == np) in __of_detach_node()
266 parent->child = np->sibling; in __of_detach_node()
269 for (prevsib = np->parent->child; in __of_detach_node()
270 prevsib->sibling != np; in __of_detach_node()
271 prevsib = prevsib->sibling) in __of_detach_node()
273 prevsib->sibling = np->sibling; in __of_detach_node()
279 __of_phandle_cache_inv_entry(np->phandle); in __of_detach_node()
287 * of_detach_node() - "Unplug" a node from the device tree.
307 static void property_list_free(struct property *prop_list) in property_list_free()
309 struct property *prop, *next; in property_list_free()
312 next = prop->next; in property_list_free()
313 kfree(prop->name); in property_list_free()
314 kfree(prop->value); in property_list_free()
320 * of_node_release() - release a dynamically allocated node
339 __func__, node->parent, node->full_name); in of_node_release()
348 strcmp(node->parent->full_name, "testcase-data")) { in of_node_release()
350 …e_put() on this node will result in a kobject warning 'refcount_t: underflow; use-after-free.'\n"); in of_node_release()
368 * If node->properties non-empty then properties were added in of_node_release()
370 * yet been removed, or by a non-overlay mechanism. in of_node_release()
372 if (node->properties) in of_node_release()
377 if (node->child) in of_node_release()
379 __func__, node->parent, node->full_name); in of_node_release()
381 property_list_free(node->properties); in of_node_release()
382 property_list_free(node->deadprops); in of_node_release()
385 kfree(node->full_name); in of_node_release()
386 kfree(node->data); in of_node_release()
391 * __of_prop_dup - Copy a property dynamically.
392 * @prop: Property to copy
395 * Copy a property by dynamically allocating the memory of both the
396 * property structure and the property name & contents. The property's
400 * Return: The newly allocated property or NULL on out of memory error.
402 struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags) in __of_prop_dup()
404 struct property *new; in __of_prop_dup()
412 * In case of a boolean property, this will allocate a value in __of_prop_dup()
416 new->name = kstrdup(prop->name, allocflags); in __of_prop_dup()
417 new->value = kmemdup(prop->value, prop->length, allocflags); in __of_prop_dup()
418 new->length = prop->length; in __of_prop_dup()
419 if (!new->name || !new->value) in __of_prop_dup()
422 /* mark the property as dynamic */ in __of_prop_dup()
428 kfree(new->name); in __of_prop_dup()
429 kfree(new->value); in __of_prop_dup()
435 * __of_node_dup() - Duplicate or create an empty device node dynamically.
437 * @full_name: string value to be duplicated into new node's full_name field
454 node->full_name = kstrdup(full_name, GFP_KERNEL); in __of_node_dup()
455 if (!node->full_name) { in __of_node_dup()
466 struct property *pp, *new_pp; in __of_node_dup()
472 kfree(new_pp->name); in __of_node_dup()
473 kfree(new_pp->value); in __of_node_dup()
487 * of_changeset_create_node - Dynamically create a device node and attach to
506 np->parent = parent; in of_changeset_create_node()
520 if (ce->action == OF_RECONFIG_ATTACH_NODE && in __of_changeset_entry_destroy()
521 of_node_check_flag(ce->np, OF_OVERLAY)) { in __of_changeset_entry_destroy()
522 if (kref_read(&ce->np->kobj.kref) > 1) { in __of_changeset_entry_destroy()
523 …, expected refcount 1 instead of %d, of_node_get()/of_node_put() unbalanced - destroy cset entry: … in __of_changeset_entry_destroy()
524 kref_read(&ce->np->kobj.kref), ce->np); in __of_changeset_entry_destroy()
526 of_node_set_flag(ce->np, OF_OVERLAY_FREE_CSET); in __of_changeset_entry_destroy()
530 of_node_put(ce->np); in __of_changeset_entry_destroy()
531 list_del(&ce->node); in __of_changeset_entry_destroy()
540 switch (ce->action) { in __of_changeset_entry_invert()
542 rce->action = OF_RECONFIG_DETACH_NODE; in __of_changeset_entry_invert()
545 rce->action = OF_RECONFIG_ATTACH_NODE; in __of_changeset_entry_invert()
548 rce->action = OF_RECONFIG_REMOVE_PROPERTY; in __of_changeset_entry_invert()
551 rce->action = OF_RECONFIG_ADD_PROPERTY; in __of_changeset_entry_invert()
554 rce->old_prop = ce->prop; in __of_changeset_entry_invert()
555 rce->prop = ce->old_prop; in __of_changeset_entry_invert()
556 /* update was used but original property did not exist */ in __of_changeset_entry_invert()
557 if (!rce->prop) { in __of_changeset_entry_invert()
558 rce->action = OF_RECONFIG_REMOVE_PROPERTY; in __of_changeset_entry_invert()
559 rce->prop = ce->prop; in __of_changeset_entry_invert()
577 switch (ce->action) { in __of_changeset_entry_notify()
581 rd.dn = ce->np; in __of_changeset_entry_notify()
582 ret = of_reconfig_notify(ce->action, &rd); in __of_changeset_entry_notify()
587 ret = of_property_notify(ce->action, ce->np, ce->prop, ce->old_prop); in __of_changeset_entry_notify()
591 (int)ce->action); in __of_changeset_entry_notify()
592 ret = -EINVAL; in __of_changeset_entry_notify()
596 pr_err("changeset notifier error @%pOF\n", ce->np); in __of_changeset_entry_notify()
604 of_changeset_action_debug("apply: ", ce->action, ce->np, ce->prop); in __of_changeset_entry_apply()
606 switch (ce->action) { in __of_changeset_entry_apply()
608 __of_attach_node(ce->np); in __of_changeset_entry_apply()
611 __of_detach_node(ce->np); in __of_changeset_entry_apply()
614 ret = __of_add_property(ce->np, ce->prop); in __of_changeset_entry_apply()
617 ret = __of_remove_property(ce->np, ce->prop); in __of_changeset_entry_apply()
621 ret = __of_update_property(ce->np, ce->prop, &ce->old_prop); in __of_changeset_entry_apply()
624 ret = -EINVAL; in __of_changeset_entry_apply()
628 of_changeset_action_err("apply failed: ", ce->action, ce->np, ce->prop); in __of_changeset_entry_apply()
644 * of_changeset_init - Initialize a changeset for use
653 INIT_LIST_HEAD(&ocs->entries); in of_changeset_init()
658 * of_changeset_destroy - Destroy a changeset
669 list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node) in of_changeset_destroy()
690 list_for_each_entry(ce, &ocs->entries, node) { in __of_changeset_apply_entries()
694 list_for_each_entry_continue_reverse(ce, &ocs->entries, in __of_changeset_apply_entries()
722 list_for_each_entry(ce, &ocs->entries, node) { in __of_changeset_apply_notify()
753 * of_changeset_apply - Applies a changeset
758 * Any side-effects of live tree state changes are applied here on
759 * success, like creation/destruction of devices and side-effects
779 * If revert fails, an attempt is made to re-apply the entries that were
782 * If multiple re-apply errors occur then only the final apply error is
794 list_for_each_entry_reverse(ce, &ocs->entries, node) { in __of_changeset_revert_entries()
798 list_for_each_entry_continue(ce, &ocs->entries, node) { in __of_changeset_revert_entries()
823 list_for_each_entry_reverse(ce, &ocs->entries, node) { in __of_changeset_revert_notify()
848 * of_changeset_revert - Reverts an applied changeset
854 * Any side-effects like creation/destruction of devices and
872 * of_changeset_action - Add an action to the tail of the changeset list
877 * @prop: Pointer to property
889 struct device_node *np, struct property *prop) in of_changeset_action()
894 return -EINVAL; in of_changeset_action()
898 return -ENOMEM; in of_changeset_action()
901 ce->action = action; in of_changeset_action()
902 ce->np = of_node_get(np); in of_changeset_action()
903 ce->prop = prop; in of_changeset_action()
906 list_add_tail(&ce->node, &ocs->entries); in of_changeset_action()
913 const struct property *pp) in of_changeset_add_prop_helper()
915 struct property *new_pp; in of_changeset_add_prop_helper()
920 return -ENOMEM; in of_changeset_add_prop_helper()
924 kfree(new_pp->name); in of_changeset_add_prop_helper()
925 kfree(new_pp->value); in of_changeset_add_prop_helper()
933 * of_changeset_add_prop_string - Add a string property to a changeset
937 * @prop_name: name of the property to be added
938 * @str: pointer to null terminated string
940 * Create a string property and add it to a changeset.
948 struct property prop; in of_changeset_add_prop_string()
959 * of_changeset_add_prop_string_array - Add a string list property to
964 * @prop_name: name of the property to be added
965 * @str_array: pointer to an array of null terminated strings
966 * @sz: number of string array elements
968 * Create a string list property and add it to a changeset.
977 struct property prop; in of_changeset_add_prop_string_array()
989 return -ENOMEM; in of_changeset_add_prop_string_array()
993 vp += snprintf(vp, (char *)prop.value + prop.length - vp, "%s", in of_changeset_add_prop_string_array()
1004 * of_changeset_add_prop_u32_array - Add a property of 32 bit integers
1005 * property to a changeset
1009 * @prop_name: name of the property to be added
1010 * @array: pointer to an array of 32 bit integers
1011 * @sz: number of array elements
1013 * Create a property of 32 bit integers and add it to a changeset.
1020 const u32 *array, size_t sz) in of_changeset_add_prop_u32_array() argument
1022 struct property prop; in of_changeset_add_prop_u32_array()
1028 return -ENOMEM; in of_changeset_add_prop_u32_array()
1031 val[i] = cpu_to_be32(array[i]); in of_changeset_add_prop_u32_array()