]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - arch/powerpc/platforms/pseries/of_helpers.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/string.h>
4 #include <linux/slab.h>
7 #include "of_helpers.h"
10 * pseries_of_derive_parent - basically like dirname(1)
11 * @path: the full_name of a node to be added to the tree
13 * Returns the node which should be the parent of the node
14 * described by path. E.g., for path = "/foo/bar", returns
15 * the node with full_name = "/foo".
17 struct device_node
*pseries_of_derive_parent(const char *path
)
19 struct device_node
*parent
;
20 char *parent_path
= "/";
23 /* We do not want the trailing '/' character */
24 tail
= kbasename(path
) - 1;
26 /* reject if path is "/" */
27 if (!strcmp(path
, "/"))
28 return ERR_PTR(-EINVAL
);
31 parent_path
= kstrndup(path
, tail
- path
, GFP_KERNEL
);
33 return ERR_PTR(-ENOMEM
);
35 parent
= of_find_node_by_path(parent_path
);
36 if (strcmp(parent_path
, "/"))
38 return parent
? parent
: ERR_PTR(-EINVAL
);