libfdt: Add fdt_path_offset_namelen()

Properties may contain path names which are not NUL-terminated.
For example, the 'stdout-path' property allows the form 'path:options',
where the ':' character terminates the path specifier.

Allow these path names to be used in-place for path descending;
add fdt_path_offset_namelen(), which limits the path name to 'namelen'
characters.

Reimplement fdt_path_offset() as a trivial wrapper.

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
main
Peter Hurley 2015-03-06 10:12:38 -05:00 committed by David Gibson
parent a4b093f736
commit b4150b59ae
3 changed files with 26 additions and 8 deletions

View File

@ -154,9 +154,9 @@ int fdt_subnode_offset(const void *fdt, int parentoffset,
return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name)); return fdt_subnode_offset_namelen(fdt, parentoffset, name, strlen(name));
} }


int fdt_path_offset(const void *fdt, const char *path) int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
{ {
const char *end = path + strlen(path); const char *end = path + namelen;
const char *p = path; const char *p = path;
int offset = 0; int offset = 0;


@ -164,7 +164,7 @@ int fdt_path_offset(const void *fdt, const char *path)


/* see if we have an alias */ /* see if we have an alias */
if (*path != '/') { if (*path != '/') {
const char *q = strchr(path, '/'); const char *q = memchr(path, '/', end - p);


if (!q) if (!q)
q = end; q = end;
@ -177,14 +177,15 @@ int fdt_path_offset(const void *fdt, const char *path)
p = q; p = q;
} }


while (*p) { while (p < end) {
const char *q; const char *q;


while (*p == '/') while (*p == '/') {
p++; p++;
if (! *p) if (p == end)
return offset; return offset;
q = strchr(p, '/'); }
q = memchr(p, '/', end - p);
if (! q) if (! q)
q = end; q = end;


@ -198,6 +199,11 @@ int fdt_path_offset(const void *fdt, const char *path)
return offset; return offset;
} }


int fdt_path_offset(const void *fdt, const char *path)
{
return fdt_path_offset_namelen(fdt, path, strlen(path));
}

const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
{ {
const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset); const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset);

View File

@ -322,6 +322,17 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset,
*/ */
int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name);


/**
* fdt_path_offset_namelen - find a tree node by its full path
* @fdt: pointer to the device tree blob
* @path: full path of the node to locate
* @namelen: number of characters of path to consider
*
* Identical to fdt_path_offset(), but only consider the first namelen
* characters of path as the path name.
*/
int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen);

/** /**
* fdt_path_offset - find a tree node by its full path * fdt_path_offset - find a tree node by its full path
* @fdt: pointer to the device tree blob * @fdt: pointer to the device tree blob

View File

@ -8,6 +8,7 @@ LIBFDT_1.2 {
fdt_get_mem_rsv; fdt_get_mem_rsv;
fdt_subnode_offset_namelen; fdt_subnode_offset_namelen;
fdt_subnode_offset; fdt_subnode_offset;
fdt_path_offset_namelen;
fdt_path_offset; fdt_path_offset;
fdt_get_name; fdt_get_name;
fdt_get_property_namelen; fdt_get_property_namelen;