- Add OF_hasprop() and ofw_bus_has_prop(). These can be used to check

existence of the property.

- Fix ofw_bus_is_compatible{,_strict}() to prevent substring match in the
  compatible string.

Reviewed by:	raj
This commit is contained in:
Hiroki Sato 2012-08-18 11:25:07 +00:00
parent 0437688e08
commit 26ca49652b
4 changed files with 29 additions and 2 deletions

View File

@ -167,7 +167,8 @@ ofw_bus_is_compatible(device_t dev, const char *onecompat)
onelen = strlen(onecompat);
while (len > 0) {
if (strncasecmp(compat, onecompat, onelen) == 0)
if (strlen(compat) == onelen &&
strncasecmp(compat, onecompat, onelen) == 0)
/* Found it. */
return (1);
@ -183,16 +184,30 @@ int
ofw_bus_is_compatible_strict(device_t dev, const char *compatible)
{
const char *compat;
size_t len;
if ((compat = ofw_bus_get_compat(dev)) == NULL)
return (0);
if (strncasecmp(compat, compatible, strlen(compatible)) == 0)
len = strlen(compatible);
if (strlen(compat) == len &&
strncasecmp(compat, compatible, len) == 0)
return (1);
return (0);
}
int
ofw_bus_has_prop(device_t dev, const char *propname)
{
phandle_t node;
if ((node = ofw_bus_get_node(dev)) == -1)
return (0);
return (OF_hasprop(node, propname));
}
#ifndef FDT
void
ofw_bus_setup_iinfo(phandle_t node, struct ofw_bus_iinfo *ii, int intrsz)

View File

@ -74,4 +74,7 @@ void ofw_bus_find_iparent(phandle_t);
int ofw_bus_is_compatible(device_t, const char *);
int ofw_bus_is_compatible_strict(device_t, const char *);
/* Helper routine for checking existence of a prop */
int ofw_bus_has_prop(device_t, const char *);
#endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */

View File

@ -261,6 +261,14 @@ OF_getproplen(phandle_t package, const char *propname)
return (OFW_GETPROPLEN(ofw_obj, package, propname));
}
/* Check existence of a property of a package. */
int
OF_hasprop(phandle_t package, const char *propname)
{
return (OF_getproplen(package, propname) >= 0 ? 1 : 0);
}
/* Get the value of a property of a package. */
ssize_t
OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen)

View File

@ -105,6 +105,7 @@ phandle_t OF_parent(phandle_t node);
ssize_t OF_getproplen(phandle_t node, const char *propname);
ssize_t OF_getprop(phandle_t node, const char *propname, void *buf,
size_t len);
int OF_hasprop(phandle_t node, const char *propname);
ssize_t OF_searchprop(phandle_t node, const char *propname, void *buf,
size_t len);
ssize_t OF_getprop_alloc(phandle_t node, const char *propname,