/* 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".  */
static struct device_node* derive_parent(const char *path)
/* 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".  */
static struct device_node* derive_parent(const char *path)
{
	struct device_node *parent = NULL;
	char *parent_path = "/";
	size_t parent_path_len = strrchr(path, '/') - path + 1;
	if (!strcmp(path, "/"))
		return ERR_PTR(-EINVAL);
	if (strrchr(path, '/') != path) {
		parent_path = kmalloc(parent_path_len, GFP_KERNEL);
		if (!parent_path)
			return ERR_PTR(-ENOMEM);
		strlcpy(parent_path, path, parent_path_len);
	}
	parent = of_find_node_by_path(parent_path);
	if (!parent)
		return ERR_PTR(-EINVAL);
	if (strcmp(parent_path, "/"))
		kfree(parent_path);
	return parent;
}