Merge branch 'devicetree/merge' of git://git.kernel.org/pub/scm/linux/kernel/git/glikely/linux
Pull devicetree bugfix from Grant Likely: "One buffer overflow bug that shouldn't be left around" * 'devicetree/merge' of git://git.kernel.org/pub/scm/linux/kernel/git/glikely/linux: of: Fix overflow bug in string property parsing functions
This commit is contained in:
commit
a315780977
4 changed files with 154 additions and 86 deletions
|
|
@ -267,14 +267,12 @@ extern int of_property_read_u64(const struct device_node *np,
|
|||
extern int of_property_read_string(struct device_node *np,
|
||||
const char *propname,
|
||||
const char **out_string);
|
||||
extern int of_property_read_string_index(struct device_node *np,
|
||||
const char *propname,
|
||||
int index, const char **output);
|
||||
extern int of_property_match_string(struct device_node *np,
|
||||
const char *propname,
|
||||
const char *string);
|
||||
extern int of_property_count_strings(struct device_node *np,
|
||||
const char *propname);
|
||||
extern int of_property_read_string_helper(struct device_node *np,
|
||||
const char *propname,
|
||||
const char **out_strs, size_t sz, int index);
|
||||
extern int of_device_is_compatible(const struct device_node *device,
|
||||
const char *);
|
||||
extern int of_device_is_available(const struct device_node *device);
|
||||
|
|
@ -486,15 +484,9 @@ static inline int of_property_read_string(struct device_node *np,
|
|||
return -ENOSYS;
|
||||
}
|
||||
|
||||
static inline int of_property_read_string_index(struct device_node *np,
|
||||
const char *propname, int index,
|
||||
const char **out_string)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
static inline int of_property_count_strings(struct device_node *np,
|
||||
const char *propname)
|
||||
static inline int of_property_read_string_helper(struct device_node *np,
|
||||
const char *propname,
|
||||
const char **out_strs, size_t sz, int index)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
|
@ -667,6 +659,70 @@ static inline int of_property_count_u64_elems(const struct device_node *np,
|
|||
return of_property_count_elems_of_size(np, propname, sizeof(u64));
|
||||
}
|
||||
|
||||
/**
|
||||
* of_property_read_string_array() - Read an array of strings from a multiple
|
||||
* strings property.
|
||||
* @np: device node from which the property value is to be read.
|
||||
* @propname: name of the property to be searched.
|
||||
* @out_strs: output array of string pointers.
|
||||
* @sz: number of array elements to read.
|
||||
*
|
||||
* Search for a property in a device tree node and retrieve a list of
|
||||
* terminated string values (pointer to data, not a copy) in that property.
|
||||
*
|
||||
* If @out_strs is NULL, the number of strings in the property is returned.
|
||||
*/
|
||||
static inline int of_property_read_string_array(struct device_node *np,
|
||||
const char *propname, const char **out_strs,
|
||||
size_t sz)
|
||||
{
|
||||
return of_property_read_string_helper(np, propname, out_strs, sz, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* of_property_count_strings() - Find and return the number of strings from a
|
||||
* multiple strings property.
|
||||
* @np: device node from which the property value is to be read.
|
||||
* @propname: name of the property to be searched.
|
||||
*
|
||||
* Search for a property in a device tree node and retrieve the number of null
|
||||
* terminated string contain in it. Returns the number of strings on
|
||||
* success, -EINVAL if the property does not exist, -ENODATA if property
|
||||
* does not have a value, and -EILSEQ if the string is not null-terminated
|
||||
* within the length of the property data.
|
||||
*/
|
||||
static inline int of_property_count_strings(struct device_node *np,
|
||||
const char *propname)
|
||||
{
|
||||
return of_property_read_string_helper(np, propname, NULL, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* of_property_read_string_index() - Find and read a string from a multiple
|
||||
* strings property.
|
||||
* @np: device node from which the property value is to be read.
|
||||
* @propname: name of the property to be searched.
|
||||
* @index: index of the string in the list of strings
|
||||
* @out_string: pointer to null terminated return string, modified only if
|
||||
* return value is 0.
|
||||
*
|
||||
* Search for a property in a device tree node and retrieve a null
|
||||
* terminated string value (pointer to data, not a copy) in the list of strings
|
||||
* contained in that property.
|
||||
* Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
|
||||
* property does not have a value, and -EILSEQ if the string is not
|
||||
* null-terminated within the length of the property data.
|
||||
*
|
||||
* The out_string pointer is modified only if a valid string can be decoded.
|
||||
*/
|
||||
static inline int of_property_read_string_index(struct device_node *np,
|
||||
const char *propname,
|
||||
int index, const char **output)
|
||||
{
|
||||
int rc = of_property_read_string_helper(np, propname, output, 1, index);
|
||||
return rc < 0 ? rc : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* of_property_read_bool - Findfrom a property
|
||||
* @np: device node from which the property value is to be read.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue