of/reconfig: Add of_reconfig_get_state_change() of notifier helper.
[firefly-linux-kernel-4.4.55.git] / drivers / of / dynamic.c
1 /*
2  * Support for dynamic device trees.
3  *
4  * On some platforms, the device tree can be manipulated at runtime.
5  * The routines in this section support adding, removing and changing
6  * device tree nodes.
7  */
8
9 #include <linux/of.h>
10 #include <linux/spinlock.h>
11 #include <linux/slab.h>
12 #include <linux/string.h>
13 #include <linux/proc_fs.h>
14
15 #include "of_private.h"
16
17 /**
18  * of_node_get() - Increment refcount of a node
19  * @node:       Node to inc refcount, NULL is supported to simplify writing of
20  *              callers
21  *
22  * Returns node.
23  */
24 struct device_node *of_node_get(struct device_node *node)
25 {
26         if (node)
27                 kobject_get(&node->kobj);
28         return node;
29 }
30 EXPORT_SYMBOL(of_node_get);
31
32 /**
33  * of_node_put() - Decrement refcount of a node
34  * @node:       Node to dec refcount, NULL is supported to simplify writing of
35  *              callers
36  */
37 void of_node_put(struct device_node *node)
38 {
39         if (node)
40                 kobject_put(&node->kobj);
41 }
42 EXPORT_SYMBOL(of_node_put);
43
44 void __of_detach_node_sysfs(struct device_node *np)
45 {
46         struct property *pp;
47
48         BUG_ON(!of_node_is_initialized(np));
49         if (!of_kset)
50                 return;
51
52         /* only remove properties if on sysfs */
53         if (of_node_is_attached(np)) {
54                 for_each_property_of_node(np, pp)
55                         sysfs_remove_bin_file(&np->kobj, &pp->attr);
56                 kobject_del(&np->kobj);
57         }
58
59         /* finally remove the kobj_init ref */
60         of_node_put(np);
61 }
62
63 static BLOCKING_NOTIFIER_HEAD(of_reconfig_chain);
64
65 int of_reconfig_notifier_register(struct notifier_block *nb)
66 {
67         return blocking_notifier_chain_register(&of_reconfig_chain, nb);
68 }
69 EXPORT_SYMBOL_GPL(of_reconfig_notifier_register);
70
71 int of_reconfig_notifier_unregister(struct notifier_block *nb)
72 {
73         return blocking_notifier_chain_unregister(&of_reconfig_chain, nb);
74 }
75 EXPORT_SYMBOL_GPL(of_reconfig_notifier_unregister);
76
77 int of_reconfig_notify(unsigned long action, void *p)
78 {
79         int rc;
80
81         rc = blocking_notifier_call_chain(&of_reconfig_chain, action, p);
82         return notifier_to_errno(rc);
83 }
84
85 /*
86  * of_reconfig_get_state_change()       - Returns new state of device
87  * @action      - action of the of notifier
88  * @arg         - argument of the of notifier
89  *
90  * Returns the new state of a device based on the notifier used.
91  * Returns 0 on device going from enabled to disabled, 1 on device
92  * going from disabled to enabled and -1 on no change.
93  */
94 int of_reconfig_get_state_change(unsigned long action, void *arg)
95 {
96         struct device_node *dn;
97         struct property *prop, *old_prop;
98         struct of_prop_reconfig *pr;
99         int is_status, status_state, old_status_state, prev_state, new_state;
100
101         /* figure out if a device should be created or destroyed */
102         dn = NULL;
103         prop = old_prop = NULL;
104         switch (action) {
105         case OF_RECONFIG_ATTACH_NODE:
106         case OF_RECONFIG_DETACH_NODE:
107                 dn = arg;
108                 prop = of_find_property(dn, "status", NULL);
109                 break;
110         case OF_RECONFIG_ADD_PROPERTY:
111         case OF_RECONFIG_REMOVE_PROPERTY:
112                 pr = arg;
113                 dn = pr->dn;
114                 prop = pr->prop;
115                 break;
116         case OF_RECONFIG_UPDATE_PROPERTY:
117                 pr = arg;
118                 dn = pr->dn;
119                 prop = pr->prop;
120                 old_prop = pr->old_prop;
121                 break;
122         default:
123                 return OF_RECONFIG_NO_CHANGE;
124         }
125
126         is_status = 0;
127         status_state = -1;
128         old_status_state = -1;
129         prev_state = -1;
130         new_state = -1;
131
132         if (prop && !strcmp(prop->name, "status")) {
133                 is_status = 1;
134                 status_state = !strcmp(prop->value, "okay") ||
135                                !strcmp(prop->value, "ok");
136                 if (old_prop)
137                         old_status_state = !strcmp(old_prop->value, "okay") ||
138                                            !strcmp(old_prop->value, "ok");
139         }
140
141         switch (action) {
142         case OF_RECONFIG_ATTACH_NODE:
143                 prev_state = 0;
144                 /* -1 & 0 status either missing or okay */
145                 new_state = status_state != 0;
146                 break;
147         case OF_RECONFIG_DETACH_NODE:
148                 /* -1 & 0 status either missing or okay */
149                 prev_state = status_state != 0;
150                 new_state = 0;
151                 break;
152         case OF_RECONFIG_ADD_PROPERTY:
153                 if (is_status) {
154                         /* no status property -> enabled (legacy) */
155                         prev_state = 1;
156                         new_state = status_state;
157                 }
158                 break;
159         case OF_RECONFIG_REMOVE_PROPERTY:
160                 if (is_status) {
161                         prev_state = status_state;
162                         /* no status property -> enabled (legacy) */
163                         new_state = 1;
164                 }
165                 break;
166         case OF_RECONFIG_UPDATE_PROPERTY:
167                 if (is_status) {
168                         prev_state = old_status_state != 0;
169                         new_state = status_state != 0;
170                 }
171                 break;
172         }
173
174         if (prev_state == new_state)
175                 return OF_RECONFIG_NO_CHANGE;
176
177         return new_state ? OF_RECONFIG_CHANGE_ADD : OF_RECONFIG_CHANGE_REMOVE;
178 }
179 EXPORT_SYMBOL_GPL(of_reconfig_get_state_change);
180
181 int of_property_notify(int action, struct device_node *np,
182                        struct property *prop, struct property *oldprop)
183 {
184         struct of_prop_reconfig pr;
185
186         /* only call notifiers if the node is attached */
187         if (!of_node_is_attached(np))
188                 return 0;
189
190         pr.dn = np;
191         pr.prop = prop;
192         pr.old_prop = oldprop;
193         return of_reconfig_notify(action, &pr);
194 }
195
196 void __of_attach_node(struct device_node *np)
197 {
198         const __be32 *phandle;
199         int sz;
200
201         np->name = __of_get_property(np, "name", NULL) ? : "<NULL>";
202         np->type = __of_get_property(np, "device_type", NULL) ? : "<NULL>";
203
204         phandle = __of_get_property(np, "phandle", &sz);
205         if (!phandle)
206                 phandle = __of_get_property(np, "linux,phandle", &sz);
207         if (IS_ENABLED(PPC_PSERIES) && !phandle)
208                 phandle = __of_get_property(np, "ibm,phandle", &sz);
209         np->phandle = (phandle && (sz >= 4)) ? be32_to_cpup(phandle) : 0;
210
211         np->child = NULL;
212         np->sibling = np->parent->child;
213         np->allnext = np->parent->allnext;
214         np->parent->allnext = np;
215         np->parent->child = np;
216         of_node_clear_flag(np, OF_DETACHED);
217 }
218
219 /**
220  * of_attach_node() - Plug a device node into the tree and global list.
221  */
222 int of_attach_node(struct device_node *np)
223 {
224         unsigned long flags;
225
226         mutex_lock(&of_mutex);
227         raw_spin_lock_irqsave(&devtree_lock, flags);
228         __of_attach_node(np);
229         raw_spin_unlock_irqrestore(&devtree_lock, flags);
230
231         __of_attach_node_sysfs(np);
232         mutex_unlock(&of_mutex);
233
234         of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, np);
235
236         return 0;
237 }
238
239 void __of_detach_node(struct device_node *np)
240 {
241         struct device_node *parent;
242
243         if (WARN_ON(of_node_check_flag(np, OF_DETACHED)))
244                 return;
245
246         parent = np->parent;
247         if (WARN_ON(!parent))
248                 return;
249
250         if (of_allnodes == np)
251                 of_allnodes = np->allnext;
252         else {
253                 struct device_node *prev;
254                 for (prev = of_allnodes;
255                      prev->allnext != np;
256                      prev = prev->allnext)
257                         ;
258                 prev->allnext = np->allnext;
259         }
260
261         if (parent->child == np)
262                 parent->child = np->sibling;
263         else {
264                 struct device_node *prevsib;
265                 for (prevsib = np->parent->child;
266                      prevsib->sibling != np;
267                      prevsib = prevsib->sibling)
268                         ;
269                 prevsib->sibling = np->sibling;
270         }
271
272         of_node_set_flag(np, OF_DETACHED);
273 }
274
275 /**
276  * of_detach_node() - "Unplug" a node from the device tree.
277  *
278  * The caller must hold a reference to the node.  The memory associated with
279  * the node is not freed until its refcount goes to zero.
280  */
281 int of_detach_node(struct device_node *np)
282 {
283         unsigned long flags;
284         int rc = 0;
285
286         mutex_lock(&of_mutex);
287         raw_spin_lock_irqsave(&devtree_lock, flags);
288         __of_detach_node(np);
289         raw_spin_unlock_irqrestore(&devtree_lock, flags);
290
291         __of_detach_node_sysfs(np);
292         mutex_unlock(&of_mutex);
293
294         of_reconfig_notify(OF_RECONFIG_DETACH_NODE, np);
295
296         return rc;
297 }
298
299 /**
300  * of_node_release() - release a dynamically allocated node
301  * @kref: kref element of the node to be released
302  *
303  * In of_node_put() this function is passed to kref_put() as the destructor.
304  */
305 void of_node_release(struct kobject *kobj)
306 {
307         struct device_node *node = kobj_to_device_node(kobj);
308         struct property *prop = node->properties;
309
310         /* We should never be releasing nodes that haven't been detached. */
311         if (!of_node_check_flag(node, OF_DETACHED)) {
312                 pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name);
313                 dump_stack();
314                 return;
315         }
316
317         if (!of_node_check_flag(node, OF_DYNAMIC))
318                 return;
319
320         while (prop) {
321                 struct property *next = prop->next;
322                 kfree(prop->name);
323                 kfree(prop->value);
324                 kfree(prop);
325                 prop = next;
326
327                 if (!prop) {
328                         prop = node->deadprops;
329                         node->deadprops = NULL;
330                 }
331         }
332         kfree(node->full_name);
333         kfree(node->data);
334         kfree(node);
335 }
336
337 /**
338  * __of_prop_dup - Copy a property dynamically.
339  * @prop:       Property to copy
340  * @allocflags: Allocation flags (typically pass GFP_KERNEL)
341  *
342  * Copy a property by dynamically allocating the memory of both the
343  * property stucture and the property name & contents. The property's
344  * flags have the OF_DYNAMIC bit set so that we can differentiate between
345  * dynamically allocated properties and not.
346  * Returns the newly allocated property or NULL on out of memory error.
347  */
348 struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags)
349 {
350         struct property *new;
351
352         new = kzalloc(sizeof(*new), allocflags);
353         if (!new)
354                 return NULL;
355
356         /*
357          * NOTE: There is no check for zero length value.
358          * In case of a boolean property This will allocate a value
359          * of zero bytes. We do this to work around the use
360          * of of_get_property() calls on boolean values.
361          */
362         new->name = kstrdup(prop->name, allocflags);
363         new->value = kmemdup(prop->value, prop->length, allocflags);
364         new->length = prop->length;
365         if (!new->name || !new->value)
366                 goto err_free;
367
368         /* mark the property as dynamic */
369         of_property_set_flag(new, OF_DYNAMIC);
370
371         return new;
372
373  err_free:
374         kfree(new->name);
375         kfree(new->value);
376         kfree(new);
377         return NULL;
378 }
379
380 /**
381  * __of_node_alloc() - Create an empty device node dynamically.
382  * @full_name:  Full name of the new device node
383  * @allocflags: Allocation flags (typically pass GFP_KERNEL)
384  *
385  * Create an empty device tree node, suitable for further modification.
386  * The node data are dynamically allocated and all the node flags
387  * have the OF_DYNAMIC & OF_DETACHED bits set.
388  * Returns the newly allocated node or NULL on out of memory error.
389  */
390 struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags)
391 {
392         struct device_node *node;
393
394         node = kzalloc(sizeof(*node), allocflags);
395         if (!node)
396                 return NULL;
397
398         node->full_name = kstrdup(full_name, allocflags);
399         of_node_set_flag(node, OF_DYNAMIC);
400         of_node_set_flag(node, OF_DETACHED);
401         if (!node->full_name)
402                 goto err_free;
403
404         of_node_init(node);
405
406         return node;
407
408  err_free:
409         kfree(node->full_name);
410         kfree(node);
411         return NULL;
412 }
413
414 static void __of_changeset_entry_destroy(struct of_changeset_entry *ce)
415 {
416         of_node_put(ce->np);
417         list_del(&ce->node);
418         kfree(ce);
419 }
420
421 #ifdef DEBUG
422 static void __of_changeset_entry_dump(struct of_changeset_entry *ce)
423 {
424         switch (ce->action) {
425         case OF_RECONFIG_ADD_PROPERTY:
426                 pr_debug("%p: %s %s/%s\n",
427                         ce, "ADD_PROPERTY   ", ce->np->full_name,
428                         ce->prop->name);
429                 break;
430         case OF_RECONFIG_REMOVE_PROPERTY:
431                 pr_debug("%p: %s %s/%s\n",
432                         ce, "REMOVE_PROPERTY", ce->np->full_name,
433                         ce->prop->name);
434                 break;
435         case OF_RECONFIG_UPDATE_PROPERTY:
436                 pr_debug("%p: %s %s/%s\n",
437                         ce, "UPDATE_PROPERTY", ce->np->full_name,
438                         ce->prop->name);
439                 break;
440         case OF_RECONFIG_ATTACH_NODE:
441                 pr_debug("%p: %s %s\n",
442                         ce, "ATTACH_NODE    ", ce->np->full_name);
443                 break;
444         case OF_RECONFIG_DETACH_NODE:
445                 pr_debug("%p: %s %s\n",
446                         ce, "DETACH_NODE    ", ce->np->full_name);
447                 break;
448         }
449 }
450 #else
451 static inline void __of_changeset_entry_dump(struct of_changeset_entry *ce)
452 {
453         /* empty */
454 }
455 #endif
456
457 static void __of_changeset_entry_invert(struct of_changeset_entry *ce,
458                                           struct of_changeset_entry *rce)
459 {
460         memcpy(rce, ce, sizeof(*rce));
461
462         switch (ce->action) {
463         case OF_RECONFIG_ATTACH_NODE:
464                 rce->action = OF_RECONFIG_DETACH_NODE;
465                 break;
466         case OF_RECONFIG_DETACH_NODE:
467                 rce->action = OF_RECONFIG_ATTACH_NODE;
468                 break;
469         case OF_RECONFIG_ADD_PROPERTY:
470                 rce->action = OF_RECONFIG_REMOVE_PROPERTY;
471                 break;
472         case OF_RECONFIG_REMOVE_PROPERTY:
473                 rce->action = OF_RECONFIG_ADD_PROPERTY;
474                 break;
475         case OF_RECONFIG_UPDATE_PROPERTY:
476                 rce->old_prop = ce->prop;
477                 rce->prop = ce->old_prop;
478                 break;
479         }
480 }
481
482 static void __of_changeset_entry_notify(struct of_changeset_entry *ce, bool revert)
483 {
484         struct of_changeset_entry ce_inverted;
485         int ret;
486
487         if (revert) {
488                 __of_changeset_entry_invert(ce, &ce_inverted);
489                 ce = &ce_inverted;
490         }
491
492         switch (ce->action) {
493         case OF_RECONFIG_ATTACH_NODE:
494         case OF_RECONFIG_DETACH_NODE:
495                 ret = of_reconfig_notify(ce->action, ce->np);
496                 break;
497         case OF_RECONFIG_ADD_PROPERTY:
498         case OF_RECONFIG_REMOVE_PROPERTY:
499         case OF_RECONFIG_UPDATE_PROPERTY:
500                 ret = of_property_notify(ce->action, ce->np, ce->prop, ce->old_prop);
501                 break;
502         default:
503                 pr_err("%s: invalid devicetree changeset action: %i\n", __func__,
504                         (int)ce->action);
505                 return;
506         }
507
508         if (ret)
509                 pr_err("%s: notifier error @%s\n", __func__, ce->np->full_name);
510 }
511
512 static int __of_changeset_entry_apply(struct of_changeset_entry *ce)
513 {
514         struct property *old_prop, **propp;
515         unsigned long flags;
516         int ret = 0;
517
518         __of_changeset_entry_dump(ce);
519
520         raw_spin_lock_irqsave(&devtree_lock, flags);
521         switch (ce->action) {
522         case OF_RECONFIG_ATTACH_NODE:
523                 __of_attach_node(ce->np);
524                 break;
525         case OF_RECONFIG_DETACH_NODE:
526                 __of_detach_node(ce->np);
527                 break;
528         case OF_RECONFIG_ADD_PROPERTY:
529                 /* If the property is in deadprops then it must be removed */
530                 for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) {
531                         if (*propp == ce->prop) {
532                                 *propp = ce->prop->next;
533                                 ce->prop->next = NULL;
534                                 break;
535                         }
536                 }
537
538                 ret = __of_add_property(ce->np, ce->prop);
539                 if (ret) {
540                         pr_err("%s: add_property failed @%s/%s\n",
541                                 __func__, ce->np->full_name,
542                                 ce->prop->name);
543                         break;
544                 }
545                 break;
546         case OF_RECONFIG_REMOVE_PROPERTY:
547                 ret = __of_remove_property(ce->np, ce->prop);
548                 if (ret) {
549                         pr_err("%s: remove_property failed @%s/%s\n",
550                                 __func__, ce->np->full_name,
551                                 ce->prop->name);
552                         break;
553                 }
554                 break;
555
556         case OF_RECONFIG_UPDATE_PROPERTY:
557                 /* If the property is in deadprops then it must be removed */
558                 for (propp = &ce->np->deadprops; *propp; propp = &(*propp)->next) {
559                         if (*propp == ce->prop) {
560                                 *propp = ce->prop->next;
561                                 ce->prop->next = NULL;
562                                 break;
563                         }
564                 }
565
566                 ret = __of_update_property(ce->np, ce->prop, &old_prop);
567                 if (ret) {
568                         pr_err("%s: update_property failed @%s/%s\n",
569                                 __func__, ce->np->full_name,
570                                 ce->prop->name);
571                         break;
572                 }
573                 break;
574         default:
575                 ret = -EINVAL;
576         }
577         raw_spin_unlock_irqrestore(&devtree_lock, flags);
578
579         if (ret)
580                 return ret;
581
582         switch (ce->action) {
583         case OF_RECONFIG_ATTACH_NODE:
584                 __of_attach_node_sysfs(ce->np);
585                 break;
586         case OF_RECONFIG_DETACH_NODE:
587                 __of_detach_node_sysfs(ce->np);
588                 break;
589         case OF_RECONFIG_ADD_PROPERTY:
590                 /* ignore duplicate names */
591                 __of_add_property_sysfs(ce->np, ce->prop);
592                 break;
593         case OF_RECONFIG_REMOVE_PROPERTY:
594                 __of_remove_property_sysfs(ce->np, ce->prop);
595                 break;
596         case OF_RECONFIG_UPDATE_PROPERTY:
597                 __of_update_property_sysfs(ce->np, ce->prop, ce->old_prop);
598                 break;
599         }
600
601         return 0;
602 }
603
604 static inline int __of_changeset_entry_revert(struct of_changeset_entry *ce)
605 {
606         struct of_changeset_entry ce_inverted;
607
608         __of_changeset_entry_invert(ce, &ce_inverted);
609         return __of_changeset_entry_apply(&ce_inverted);
610 }
611
612 /**
613  * of_changeset_init - Initialize a changeset for use
614  *
615  * @ocs:        changeset pointer
616  *
617  * Initialize a changeset structure
618  */
619 void of_changeset_init(struct of_changeset *ocs)
620 {
621         memset(ocs, 0, sizeof(*ocs));
622         INIT_LIST_HEAD(&ocs->entries);
623 }
624
625 /**
626  * of_changeset_destroy - Destroy a changeset
627  *
628  * @ocs:        changeset pointer
629  *
630  * Destroys a changeset. Note that if a changeset is applied,
631  * its changes to the tree cannot be reverted.
632  */
633 void of_changeset_destroy(struct of_changeset *ocs)
634 {
635         struct of_changeset_entry *ce, *cen;
636
637         list_for_each_entry_safe_reverse(ce, cen, &ocs->entries, node)
638                 __of_changeset_entry_destroy(ce);
639 }
640
641 /**
642  * of_changeset_apply - Applies a changeset
643  *
644  * @ocs:        changeset pointer
645  *
646  * Applies a changeset to the live tree.
647  * Any side-effects of live tree state changes are applied here on
648  * sucess, like creation/destruction of devices and side-effects
649  * like creation of sysfs properties and directories.
650  * Returns 0 on success, a negative error value in case of an error.
651  * On error the partially applied effects are reverted.
652  */
653 int of_changeset_apply(struct of_changeset *ocs)
654 {
655         struct of_changeset_entry *ce;
656         int ret;
657
658         /* perform the rest of the work */
659         pr_debug("of_changeset: applying...\n");
660         list_for_each_entry(ce, &ocs->entries, node) {
661                 ret = __of_changeset_entry_apply(ce);
662                 if (ret) {
663                         pr_err("%s: Error applying changeset (%d)\n", __func__, ret);
664                         list_for_each_entry_continue_reverse(ce, &ocs->entries, node)
665                                 __of_changeset_entry_revert(ce);
666                         return ret;
667                 }
668         }
669         pr_debug("of_changeset: applied, emitting notifiers.\n");
670
671         /* drop the global lock while emitting notifiers */
672         mutex_unlock(&of_mutex);
673         list_for_each_entry(ce, &ocs->entries, node)
674                 __of_changeset_entry_notify(ce, 0);
675         mutex_lock(&of_mutex);
676         pr_debug("of_changeset: notifiers sent.\n");
677
678         return 0;
679 }
680
681 /**
682  * of_changeset_revert - Reverts an applied changeset
683  *
684  * @ocs:        changeset pointer
685  *
686  * Reverts a changeset returning the state of the tree to what it
687  * was before the application.
688  * Any side-effects like creation/destruction of devices and
689  * removal of sysfs properties and directories are applied.
690  * Returns 0 on success, a negative error value in case of an error.
691  */
692 int of_changeset_revert(struct of_changeset *ocs)
693 {
694         struct of_changeset_entry *ce;
695         int ret;
696
697         pr_debug("of_changeset: reverting...\n");
698         list_for_each_entry_reverse(ce, &ocs->entries, node) {
699                 ret = __of_changeset_entry_revert(ce);
700                 if (ret) {
701                         pr_err("%s: Error reverting changeset (%d)\n", __func__, ret);
702                         list_for_each_entry_continue(ce, &ocs->entries, node)
703                                 __of_changeset_entry_apply(ce);
704                         return ret;
705                 }
706         }
707         pr_debug("of_changeset: reverted, emitting notifiers.\n");
708
709         /* drop the global lock while emitting notifiers */
710         mutex_unlock(&of_mutex);
711         list_for_each_entry_reverse(ce, &ocs->entries, node)
712                 __of_changeset_entry_notify(ce, 1);
713         mutex_lock(&of_mutex);
714         pr_debug("of_changeset: notifiers sent.\n");
715
716         return 0;
717 }
718
719 /**
720  * of_changeset_action - Perform a changeset action
721  *
722  * @ocs:        changeset pointer
723  * @action:     action to perform
724  * @np:         Pointer to device node
725  * @prop:       Pointer to property
726  *
727  * On action being one of:
728  * + OF_RECONFIG_ATTACH_NODE
729  * + OF_RECONFIG_DETACH_NODE,
730  * + OF_RECONFIG_ADD_PROPERTY
731  * + OF_RECONFIG_REMOVE_PROPERTY,
732  * + OF_RECONFIG_UPDATE_PROPERTY
733  * Returns 0 on success, a negative error value in case of an error.
734  */
735 int of_changeset_action(struct of_changeset *ocs, unsigned long action,
736                 struct device_node *np, struct property *prop)
737 {
738         struct of_changeset_entry *ce;
739
740         ce = kzalloc(sizeof(*ce), GFP_KERNEL);
741         if (!ce) {
742                 pr_err("%s: Failed to allocate\n", __func__);
743                 return -ENOMEM;
744         }
745         /* get a reference to the node */
746         ce->action = action;
747         ce->np = of_node_get(np);
748         ce->prop = prop;
749
750         if (action == OF_RECONFIG_UPDATE_PROPERTY && prop)
751                 ce->old_prop = of_find_property(np, prop->name, NULL);
752
753         /* add it to the list */
754         list_add_tail(&ce->node, &ocs->entries);
755         return 0;
756 }