diff options
| author | thorpej <thorpej@NetBSD.org> | 2021-01-26 14:49:41 +0000 |
|---|---|---|
| committer | thorpej <thorpej@NetBSD.org> | 2021-01-26 14:49:41 +0000 |
| commit | bab8cb272c239e920addb60dcd4c93049dacd99b (patch) | |
| tree | a7dd5ba939404ab097cb4c86acbdd39367b9542e /sys/dev/ofw | |
| parent | 7702b061e25447a1766d6445357a40b906ec3d00 (diff) | |
There is not much point in of_compatible() returning -1 for "no match"
and >= 0 for "match". Just make it return 0 for "no match" and >0 for
"match" so it can be treated like a boolean expression.
As such of_match_compatible() (a wrapper around of_compatible()) is now
obsolete, and will be removed once all call sites are converted to an
appropriate replacement.
Diffstat (limited to 'sys/dev/ofw')
| -rw-r--r-- | sys/dev/ofw/ofw_subr.c | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/sys/dev/ofw/ofw_subr.c b/sys/dev/ofw/ofw_subr.c index e2d20d98efb..946c21f0548 100644 --- a/sys/dev/ofw/ofw_subr.c +++ b/sys/dev/ofw/ofw_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: ofw_subr.c,v 1.51 2021/01/26 14:09:11 thorpej Exp $ */ +/* $NetBSD: ofw_subr.c,v 1.52 2021/01/26 14:49:41 thorpej Exp $ */ /* * Copyright 1998 @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.51 2021/01/26 14:09:11 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.52 2021/01/26 14:49:41 thorpej Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -80,8 +80,10 @@ of_decode_int(const unsigned char *p) * This routine checks an OFW node's "compatible" entry to see if * it matches any of the provided strings. * - * It should be used when determining whether a driver can drive - * a particular device. + * of_match_compat_data() is the preferred way to perform driver + * compatibility match. However, this routine that deals with + * only strings is useful in some situations and is provided for + * convenience. * * Arguments: * phandle OFW phandle of device to be checked for @@ -91,9 +93,9 @@ of_decode_int(const unsigned char *p) * indicates compatibility. * * Return Value: - * -1 if none of the strings are found in phandle's "compatibility" + * 0 if none of the strings are found in phandle's "compatibility" * property, or the reverse index of the matching string in the - * phandle's "compatibility" property. + * phandle's "compatibility" property plus 1. * * Side Effects: * None. @@ -103,11 +105,11 @@ of_compatible(int phandle, const char * const *strings) { char *prop, propbuf[OFW_MAX_STACK_BUF_SIZE]; const char *cp; - int proplen, match, rv = -1; + int proplen, match = 0; proplen = OF_getproplen(phandle, "compatible"); if (proplen <= 0) { - return -1; + return 0; } prop = kmem_tmpbuf_alloc(proplen, propbuf, sizeof(propbuf), KM_SLEEP); @@ -118,44 +120,25 @@ of_compatible(int phandle, const char * const *strings) for (; (cp = *strings) != NULL; strings++) { if ((match = strlist_match(prop, proplen, cp)) != 0) { - rv = match - 1; break; } } out: kmem_tmpbuf_free(prop, proplen, propbuf); - return rv; + return match; } /* * int of_match_compatible(phandle, strings) * - * This routine checks an OFW node's "compatible" entry to see if - * it matches any of the provided strings. - * - * It should be used when determining whether a driver can drive - * a particular device. - * - * Arguments: - * phandle OFW phandle of device to be checked for - * compatibility. - * strings Array of containing expected "compatibility" - * property values, presence of any of which - * indicates compatibility. - * - * Return Value: - * 0 if none of the strings are found in phandle's "compatibility" - * property, or a positive number based on the reverse index of the - * matching string in the phandle's "compatibility" property, plus 1. - * - * Side Effects: - * None. + * This function is equivalent to of_compatible(), and its use + * is deprecated. */ int of_match_compatible(int phandle, const char * const *strings) { - return of_compatible(phandle, strings) + 1; + return of_compatible(phandle, strings); } /* |
