rtnetlink: check DO_SETLINK_NOTIFY correctly in do_setlink
[linux/fpc-iii.git] / arch / powerpc / platforms / pseries / of_helpers.c
blob2798933c0e38c492ade3876a5aba78cdf09b193e
1 #include <linux/string.h>
2 #include <linux/err.h>
3 #include <linux/slab.h>
4 #include <linux/of.h>
6 #include "of_helpers.h"
8 /**
9 * pseries_of_derive_parent - basically like dirname(1)
10 * @path: the full_name of a node to be added to the tree
12 * Returns the node which should be the parent of the node
13 * described by path. E.g., for path = "/foo/bar", returns
14 * the node with full_name = "/foo".
16 struct device_node *pseries_of_derive_parent(const char *path)
18 struct device_node *parent;
19 char *parent_path = "/";
20 const char *tail;
22 /* We do not want the trailing '/' character */
23 tail = kbasename(path) - 1;
25 /* reject if path is "/" */
26 if (!strcmp(path, "/"))
27 return ERR_PTR(-EINVAL);
29 if (tail > path) {
30 parent_path = kstrndup(path, tail - path, GFP_KERNEL);
31 if (!parent_path)
32 return ERR_PTR(-ENOMEM);
34 parent = of_find_node_by_path(parent_path);
35 if (strcmp(parent_path, "/"))
36 kfree(parent_path);
37 return parent ? parent : ERR_PTR(-EINVAL);