2015-10-01 16:46:06 +07:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
|
|
|
|
#include "of_helpers.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pseries_of_derive_parent - basically like dirname(1)
|
|
|
|
* @path: the full_name of a node to be added to the tree
|
|
|
|
*
|
|
|
|
* Returns the node which should be the parent of the node
|
|
|
|
* described by path. E.g., for path = "/foo/bar", returns
|
|
|
|
* the node with full_name = "/foo".
|
|
|
|
*/
|
|
|
|
struct device_node *pseries_of_derive_parent(const char *path)
|
|
|
|
{
|
2015-10-01 16:46:07 +07:00
|
|
|
struct device_node *parent;
|
2015-10-01 16:46:06 +07:00
|
|
|
char *parent_path = "/";
|
2015-10-27 22:46:47 +07:00
|
|
|
const char *tail;
|
|
|
|
|
|
|
|
/* We do not want the trailing '/' character */
|
|
|
|
tail = kbasename(path) - 1;
|
2015-10-01 16:46:06 +07:00
|
|
|
|
|
|
|
/* reject if path is "/" */
|
|
|
|
if (!strcmp(path, "/"))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2015-10-27 22:46:47 +07:00
|
|
|
if (tail > path) {
|
2015-10-01 16:46:09 +07:00
|
|
|
parent_path = kstrndup(path, tail - path, GFP_KERNEL);
|
2015-10-01 16:46:06 +07:00
|
|
|
if (!parent_path)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
parent = of_find_node_by_path(parent_path);
|
|
|
|
if (strcmp(parent_path, "/"))
|
|
|
|
kfree(parent_path);
|
2015-10-01 16:46:07 +07:00
|
|
|
return parent ? parent : ERR_PTR(-EINVAL);
|
2015-10-01 16:46:06 +07:00
|
|
|
}
|