Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Support for dynamic device trees.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * On some platforms, the device tree can be manipulated at runtime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * The routines in this section support adding, removing and changing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * device tree nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt)	"OF: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "of_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static struct device_node *kobj_to_device_node(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	return container_of(kobj, struct device_node, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * of_node_get() - Increment refcount of a node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * @node:	Node to inc refcount, NULL is supported to simplify writing of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *		callers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * Returns node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct device_node *of_node_get(struct device_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	if (node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		kobject_get(&node->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) EXPORT_SYMBOL(of_node_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * of_node_put() - Decrement refcount of a node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * @node:	Node to dec refcount, NULL is supported to simplify writing of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *		callers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) void of_node_put(struct device_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		kobject_put(&node->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) EXPORT_SYMBOL(of_node_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static BLOCKING_NOTIFIER_HEAD(of_reconfig_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) int of_reconfig_notifier_register(struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return blocking_notifier_chain_register(&of_reconfig_chain, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) EXPORT_SYMBOL_GPL(of_reconfig_notifier_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) int of_reconfig_notifier_unregister(struct notifier_block *nb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return blocking_notifier_chain_unregister(&of_reconfig_chain, nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) const char *action_names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	[OF_RECONFIG_ATTACH_NODE] = "ATTACH_NODE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	[OF_RECONFIG_DETACH_NODE] = "DETACH_NODE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	[OF_RECONFIG_ADD_PROPERTY] = "ADD_PROPERTY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	[OF_RECONFIG_REMOVE_PROPERTY] = "REMOVE_PROPERTY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	[OF_RECONFIG_UPDATE_PROPERTY] = "UPDATE_PROPERTY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) int of_reconfig_notify(unsigned long action, struct of_reconfig_data *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct of_reconfig_data *pr = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	case OF_RECONFIG_ATTACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	case OF_RECONFIG_DETACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		pr_debug("notify %-15s %pOF\n", action_names[action],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			pr->dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	case OF_RECONFIG_ADD_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	case OF_RECONFIG_REMOVE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	case OF_RECONFIG_UPDATE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		pr_debug("notify %-15s %pOF:%s\n", action_names[action],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			pr->dn, pr->prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	rc = blocking_notifier_call_chain(&of_reconfig_chain, action, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return notifier_to_errno(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * of_reconfig_get_state_change()	- Returns new state of device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * @action	- action of the of notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * @arg		- argument of the of notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Returns the new state of a device based on the notifier used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * Returns 0 on device going from enabled to disabled, 1 on device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * going from disabled to enabled and -1 on no change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int of_reconfig_get_state_change(unsigned long action, struct of_reconfig_data *pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct property *prop, *old_prop = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	int is_status, status_state, old_status_state, prev_state, new_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* figure out if a device should be created or destroyed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case OF_RECONFIG_ATTACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	case OF_RECONFIG_DETACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		prop = of_find_property(pr->dn, "status", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	case OF_RECONFIG_ADD_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	case OF_RECONFIG_REMOVE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		prop = pr->prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	case OF_RECONFIG_UPDATE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		prop = pr->prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		old_prop = pr->old_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return OF_RECONFIG_NO_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	is_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	status_state = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	old_status_state = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	prev_state = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	new_state = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (prop && !strcmp(prop->name, "status")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		is_status = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		status_state = !strcmp(prop->value, "okay") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			       !strcmp(prop->value, "ok");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (old_prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			old_status_state = !strcmp(old_prop->value, "okay") ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 					   !strcmp(old_prop->value, "ok");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	case OF_RECONFIG_ATTACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		prev_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		/* -1 & 0 status either missing or okay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		new_state = status_state != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	case OF_RECONFIG_DETACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		/* -1 & 0 status either missing or okay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		prev_state = status_state != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		new_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	case OF_RECONFIG_ADD_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		if (is_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			/* no status property -> enabled (legacy) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			prev_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			new_state = status_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	case OF_RECONFIG_REMOVE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		if (is_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			prev_state = status_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			/* no status property -> enabled (legacy) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			new_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	case OF_RECONFIG_UPDATE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		if (is_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			prev_state = old_status_state != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			new_state = status_state != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (prev_state == new_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return OF_RECONFIG_NO_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return new_state ? OF_RECONFIG_CHANGE_ADD : OF_RECONFIG_CHANGE_REMOVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) EXPORT_SYMBOL_GPL(of_reconfig_get_state_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int of_property_notify(int action, struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		       struct property *prop, struct property *oldprop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct of_reconfig_data pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	/* only call notifiers if the node is attached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (!of_node_is_attached(np))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	pr.dn = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	pr.prop = prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	pr.old_prop = oldprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return of_reconfig_notify(action, &pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static void __of_attach_node(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	const __be32 *phandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	int sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (!of_node_check_flag(np, OF_OVERLAY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		np->name = __of_get_property(np, "name", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		if (!np->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			np->name = "<NULL>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		phandle = __of_get_property(np, "phandle", &sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if (!phandle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			phandle = __of_get_property(np, "linux,phandle", &sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (IS_ENABLED(CONFIG_PPC_PSERIES) && !phandle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			phandle = __of_get_property(np, "ibm,phandle", &sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		if (phandle && (sz >= 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			np->phandle = be32_to_cpup(phandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			np->phandle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	np->child = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	np->sibling = np->parent->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	np->parent->child = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	of_node_clear_flag(np, OF_DETACHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * of_attach_node() - Plug a device node into the tree and global list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int of_attach_node(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct of_reconfig_data rd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	memset(&rd, 0, sizeof(rd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	rd.dn = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	mutex_lock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	raw_spin_lock_irqsave(&devtree_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	__of_attach_node(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	__of_attach_node_sysfs(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, &rd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void __of_detach_node(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct device_node *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (WARN_ON(of_node_check_flag(np, OF_DETACHED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	parent = np->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (WARN_ON(!parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (parent->child == np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		parent->child = np->sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		struct device_node *prevsib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		for (prevsib = np->parent->child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		     prevsib->sibling != np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		     prevsib = prevsib->sibling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		prevsib->sibling = np->sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	of_node_set_flag(np, OF_DETACHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/* race with of_find_node_by_phandle() prevented by devtree_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	__of_phandle_cache_inv_entry(np->phandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  * of_detach_node() - "Unplug" a node from the device tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int of_detach_node(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct of_reconfig_data rd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	memset(&rd, 0, sizeof(rd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	rd.dn = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	mutex_lock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	raw_spin_lock_irqsave(&devtree_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	__of_detach_node(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	__of_detach_node_sysfs(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	of_reconfig_notify(OF_RECONFIG_DETACH_NODE, &rd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) EXPORT_SYMBOL_GPL(of_detach_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static void property_list_free(struct property *prop_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct property *prop, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	for (prop = prop_list; prop != NULL; prop = next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		next = prop->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		kfree(prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		kfree(prop->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		kfree(prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * of_node_release() - release a dynamically allocated node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * @kref: kref element of the node to be released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * In of_node_put() this function is passed to kref_put() as the destructor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) void of_node_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	struct device_node *node = kobj_to_device_node(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	/* We should never be releasing nodes that haven't been detached. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (!of_node_check_flag(node, OF_DETACHED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		pr_err("ERROR: Bad of_node_put() on %pOF\n", node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (!of_node_check_flag(node, OF_DYNAMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (of_node_check_flag(node, OF_OVERLAY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		if (!of_node_check_flag(node, OF_OVERLAY_FREE_CSET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			/* premature refcount of zero, do not free memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			pr_err("ERROR: memory leak before free overlay changeset,  %pOF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			       node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		 * If node->properties non-empty then properties were added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		 * to this node either by different overlay that has not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		 * yet been removed, or by a non-overlay mechanism.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		if (node->properties)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			pr_err("ERROR: %s(), unexpected properties in %pOF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			       __func__, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	property_list_free(node->properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	property_list_free(node->deadprops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	fwnode_links_purge(of_fwnode_handle(node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	kfree(node->full_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	kfree(node->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	kfree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  * __of_prop_dup - Copy a property dynamically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  * @prop:	Property to copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  * @allocflags:	Allocation flags (typically pass GFP_KERNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * Copy a property by dynamically allocating the memory of both the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * property structure and the property name & contents. The property's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * flags have the OF_DYNAMIC bit set so that we can differentiate between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * dynamically allocated properties and not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * Returns the newly allocated property or NULL on out of memory error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	struct property *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	new = kzalloc(sizeof(*new), allocflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if (!new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	 * NOTE: There is no check for zero length value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	 * In case of a boolean property, this will allocate a value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	 * of zero bytes. We do this to work around the use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	 * of of_get_property() calls on boolean values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	new->name = kstrdup(prop->name, allocflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	new->value = kmemdup(prop->value, prop->length, allocflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	new->length = prop->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	if (!new->name || !new->value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	/* mark the property as dynamic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	of_property_set_flag(new, OF_DYNAMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	kfree(new->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	kfree(new->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  * __of_node_dup() - Duplicate or create an empty device node dynamically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  * @np:		if not NULL, contains properties to be duplicated in new node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  * @full_name:	string value to be duplicated into new node's full_name field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  * Create a device tree node, optionally duplicating the properties of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * another node.  The node data are dynamically allocated and all the node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * flags have the OF_DYNAMIC & OF_DETACHED bits set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  * Returns the newly allocated node or NULL on out of memory error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct device_node *__of_node_dup(const struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 				  const char *full_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	node = kzalloc(sizeof(*node), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	node->full_name = kstrdup(full_name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	if (!node->full_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		kfree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	of_node_set_flag(node, OF_DYNAMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	of_node_set_flag(node, OF_DETACHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	of_node_init(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	/* Iterate over and duplicate all properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	if (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		struct property *pp, *new_pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		for_each_property_of_node(np, pp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			new_pp = __of_prop_dup(pp, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			if (!new_pp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 				goto err_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			if (__of_add_property(node, new_pp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 				kfree(new_pp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 				kfree(new_pp->value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 				kfree(new_pp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 				goto err_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  err_prop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	of_node_put(node); /* Frees the node and properties */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static void __of_changeset_entry_destroy(struct of_changeset_entry *ce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (ce->action == OF_RECONFIG_ATTACH_NODE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	    of_node_check_flag(ce->np, OF_OVERLAY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		if (kref_read(&ce->np->kobj.kref) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 			pr_err("ERROR: memory leak, expected refcount 1 instead of %d, of_node_get()/of_node_put() unbalanced - destroy cset entry: attach overlay node %pOF\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 			       kref_read(&ce->np->kobj.kref), ce->np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 			of_node_set_flag(ce->np, OF_OVERLAY_FREE_CSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	of_node_put(ce->np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	list_del(&ce->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	kfree(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static void __of_changeset_entry_dump(struct of_changeset_entry *ce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	switch (ce->action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	case OF_RECONFIG_ADD_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	case OF_RECONFIG_REMOVE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	case OF_RECONFIG_UPDATE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		pr_debug("cset<%p> %-15s %pOF/%s\n", ce, action_names[ce->action],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			ce->np, ce->prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	case OF_RECONFIG_ATTACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	case OF_RECONFIG_DETACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		pr_debug("cset<%p> %-15s %pOF\n", ce, action_names[ce->action],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 			ce->np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static inline void __of_changeset_entry_dump(struct of_changeset_entry *ce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	/* empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static void __of_changeset_entry_invert(struct of_changeset_entry *ce,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 					  struct of_changeset_entry *rce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	memcpy(rce, ce, sizeof(*rce));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	switch (ce->action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	case OF_RECONFIG_ATTACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		rce->action = OF_RECONFIG_DETACH_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	case OF_RECONFIG_DETACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		rce->action = OF_RECONFIG_ATTACH_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	case OF_RECONFIG_ADD_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		rce->action = OF_RECONFIG_REMOVE_PROPERTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	case OF_RECONFIG_REMOVE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		rce->action = OF_RECONFIG_ADD_PROPERTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	case OF_RECONFIG_UPDATE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		rce->old_prop = ce->prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		rce->prop = ce->old_prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		/* update was used but original property did not exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		if (!rce->prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 			rce->action = OF_RECONFIG_REMOVE_PROPERTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			rce->prop = ce->prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static int __of_changeset_entry_notify(struct of_changeset_entry *ce,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		bool revert)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	struct of_reconfig_data rd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	struct of_changeset_entry ce_inverted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (revert) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		__of_changeset_entry_invert(ce, &ce_inverted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		ce = &ce_inverted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	switch (ce->action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	case OF_RECONFIG_ATTACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	case OF_RECONFIG_DETACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		memset(&rd, 0, sizeof(rd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		rd.dn = ce->np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		ret = of_reconfig_notify(ce->action, &rd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	case OF_RECONFIG_ADD_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	case OF_RECONFIG_REMOVE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	case OF_RECONFIG_UPDATE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		ret = of_property_notify(ce->action, ce->np, ce->prop, ce->old_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		pr_err("invalid devicetree changeset action: %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			(int)ce->action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		pr_err("changeset notifier error @%pOF\n", ce->np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static int __of_changeset_entry_apply(struct of_changeset_entry *ce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	struct property *old_prop, **propp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	__of_changeset_entry_dump(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	raw_spin_lock_irqsave(&devtree_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	switch (ce->action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	case OF_RECONFIG_ATTACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		__of_attach_node(ce->np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	case OF_RECONFIG_DETACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		__of_detach_node(ce->np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	case OF_RECONFIG_ADD_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		/* If the property is in deadprops then it must be removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 			if (*propp == ce->prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 				*propp = ce->prop->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 				ce->prop->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		ret = __of_add_property(ce->np, ce->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 			pr_err("changeset: add_property failed @%pOF/%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 				ce->np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 				ce->prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	case OF_RECONFIG_REMOVE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		ret = __of_remove_property(ce->np, ce->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 			pr_err("changeset: remove_property failed @%pOF/%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 				ce->np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 				ce->prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	case OF_RECONFIG_UPDATE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		/* If the property is in deadprops then it must be removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 			if (*propp == ce->prop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 				*propp = ce->prop->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 				ce->prop->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		ret = __of_update_property(ce->np, ce->prop, &old_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 			pr_err("changeset: update_property failed @%pOF/%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 				ce->np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 				ce->prop->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	raw_spin_unlock_irqrestore(&devtree_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	switch (ce->action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	case OF_RECONFIG_ATTACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		__of_attach_node_sysfs(ce->np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	case OF_RECONFIG_DETACH_NODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		__of_detach_node_sysfs(ce->np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	case OF_RECONFIG_ADD_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		/* ignore duplicate names */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		__of_add_property_sysfs(ce->np, ce->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	case OF_RECONFIG_REMOVE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		__of_remove_property_sysfs(ce->np, ce->prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	case OF_RECONFIG_UPDATE_PROPERTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		__of_update_property_sysfs(ce->np, ce->prop, ce->old_prop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static inline int __of_changeset_entry_revert(struct of_changeset_entry *ce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	struct of_changeset_entry ce_inverted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	__of_changeset_entry_invert(ce, &ce_inverted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	return __of_changeset_entry_apply(&ce_inverted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)  * of_changeset_init - Initialize a changeset for use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)  * @ocs:	changeset pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)  * Initialize a changeset structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) void of_changeset_init(struct of_changeset *ocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	memset(ocs, 0, sizeof(*ocs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	INIT_LIST_HEAD(&ocs->entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) EXPORT_SYMBOL_GPL(of_changeset_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)  * of_changeset_destroy - Destroy a changeset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)  * @ocs:	changeset pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)  * Destroys a changeset. Note that if a changeset is applied,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)  * its changes to the tree cannot be reverted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) void of_changeset_destroy(struct of_changeset *ocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	struct of_changeset_entry *ce, *cen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		__of_changeset_entry_destroy(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) EXPORT_SYMBOL_GPL(of_changeset_destroy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)  * Apply the changeset entries in @ocs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)  * If apply fails, an attempt is made to revert the entries that were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)  * successfully applied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)  * If multiple revert errors occur then only the final revert error is reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)  * Returns 0 on success, a negative error value in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)  * If a revert error occurs, it is returned in *ret_revert.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) int __of_changeset_apply_entries(struct of_changeset *ocs, int *ret_revert)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	struct of_changeset_entry *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	int ret, ret_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	pr_debug("changeset: applying...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	list_for_each_entry(ce, &ocs->entries, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		ret = __of_changeset_entry_apply(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 			pr_err("Error applying changeset (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 			list_for_each_entry_continue_reverse(ce, &ocs->entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 							     node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 				ret_tmp = __of_changeset_entry_revert(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 				if (ret_tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 					*ret_revert = ret_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)  * Returns 0 on success, a negative error value in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)  * If multiple changeset entry notification errors occur then only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)  * final notification error is reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) int __of_changeset_apply_notify(struct of_changeset *ocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	struct of_changeset_entry *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	int ret = 0, ret_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	pr_debug("changeset: emitting notifiers.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	/* drop the global lock while emitting notifiers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	list_for_each_entry(ce, &ocs->entries, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		ret_tmp = __of_changeset_entry_notify(ce, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 		if (ret_tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 			ret = ret_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	mutex_lock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	pr_debug("changeset: notifiers sent.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)  * Returns 0 on success, a negative error value in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)  * If a changeset entry apply fails, an attempt is made to revert any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)  * previous entries in the changeset.  If any of the reverts fails,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)  * that failure is not reported.  Thus the state of the device tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)  * is unknown if an apply error occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) static int __of_changeset_apply(struct of_changeset *ocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	int ret, ret_revert = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	ret = __of_changeset_apply_entries(ocs, &ret_revert);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 		ret = __of_changeset_apply_notify(ocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)  * of_changeset_apply - Applies a changeset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)  * @ocs:	changeset pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)  * Applies a changeset to the live tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)  * Any side-effects of live tree state changes are applied here on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)  * success, like creation/destruction of devices and side-effects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)  * like creation of sysfs properties and directories.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)  * Returns 0 on success, a negative error value in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)  * On error the partially applied effects are reverted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) int of_changeset_apply(struct of_changeset *ocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	mutex_lock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	ret = __of_changeset_apply(ocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) EXPORT_SYMBOL_GPL(of_changeset_apply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)  * Revert the changeset entries in @ocs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)  * If revert fails, an attempt is made to re-apply the entries that were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)  * successfully removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)  * If multiple re-apply errors occur then only the final apply error is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)  * reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)  * Returns 0 on success, a negative error value in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)  * If an apply error occurs, it is returned in *ret_apply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) int __of_changeset_revert_entries(struct of_changeset *ocs, int *ret_apply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	struct of_changeset_entry *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	int ret, ret_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	pr_debug("changeset: reverting...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	list_for_each_entry_reverse(ce, &ocs->entries, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 		ret = __of_changeset_entry_revert(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 			pr_err("Error reverting changeset (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 			list_for_each_entry_continue(ce, &ocs->entries, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 				ret_tmp = __of_changeset_entry_apply(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 				if (ret_tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 					*ret_apply = ret_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)  * If multiple changeset entry notification errors occur then only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)  * final notification error is reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) int __of_changeset_revert_notify(struct of_changeset *ocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	struct of_changeset_entry *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	int ret = 0, ret_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 	pr_debug("changeset: emitting notifiers.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	/* drop the global lock while emitting notifiers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	list_for_each_entry_reverse(ce, &ocs->entries, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 		ret_tmp = __of_changeset_entry_notify(ce, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 		if (ret_tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 			ret = ret_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	mutex_lock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	pr_debug("changeset: notifiers sent.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) static int __of_changeset_revert(struct of_changeset *ocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	int ret, ret_reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	ret_reply = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 	ret = __of_changeset_revert_entries(ocs, &ret_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 		ret = __of_changeset_revert_notify(ocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)  * of_changeset_revert - Reverts an applied changeset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)  * @ocs:	changeset pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)  * Reverts a changeset returning the state of the tree to what it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)  * was before the application.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)  * Any side-effects like creation/destruction of devices and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)  * removal of sysfs properties and directories are applied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)  * Returns 0 on success, a negative error value in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) int of_changeset_revert(struct of_changeset *ocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 	mutex_lock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	ret = __of_changeset_revert(ocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	mutex_unlock(&of_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) EXPORT_SYMBOL_GPL(of_changeset_revert);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)  * of_changeset_action - Add an action to the tail of the changeset list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)  * @ocs:	changeset pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)  * @action:	action to perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)  * @np:		Pointer to device node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)  * @prop:	Pointer to property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)  * On action being one of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)  * + OF_RECONFIG_ATTACH_NODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)  * + OF_RECONFIG_DETACH_NODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)  * + OF_RECONFIG_ADD_PROPERTY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)  * + OF_RECONFIG_REMOVE_PROPERTY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)  * + OF_RECONFIG_UPDATE_PROPERTY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)  * Returns 0 on success, a negative error value in case of an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) int of_changeset_action(struct of_changeset *ocs, unsigned long action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 		struct device_node *np, struct property *prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 	struct of_changeset_entry *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 	ce = kzalloc(sizeof(*ce), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 	if (!ce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 	/* get a reference to the node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 	ce->action = action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 	ce->np = of_node_get(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 	ce->prop = prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 	if (action == OF_RECONFIG_UPDATE_PROPERTY && prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) 		ce->old_prop = of_find_property(np, prop->name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) 	/* add it to the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 	list_add_tail(&ce->node, &ocs->entries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) EXPORT_SYMBOL_GPL(of_changeset_action);