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 | |
| 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')
| -rw-r--r-- | sys/arch/macppc/dev/awacs.c | 16 | ||||
| -rw-r--r-- | sys/arch/macppc/dev/mediabay.c | 6 | ||||
| -rw-r--r-- | sys/arch/macppc/dev/obio.c | 6 | ||||
| -rw-r--r-- | sys/arch/macppc/dev/pmu.c | 8 | ||||
| -rw-r--r-- | sys/arch/macppc/dev/wdc_obio.c | 6 | ||||
| -rw-r--r-- | sys/arch/macppc/macppc/interrupts.c | 6 | ||||
| -rw-r--r-- | sys/arch/macppc/macppc/machdep.c | 14 | ||||
| -rw-r--r-- | sys/arch/macppc/macppc/pic_heathrow.c | 6 | ||||
| -rw-r--r-- | sys/arch/macppc/macppc/pic_u3_ht.c | 8 | ||||
| -rw-r--r-- | sys/arch/macppc/pci/pci_machdep.c | 6 | ||||
| -rw-r--r-- | sys/dev/ofw/ofw_subr.c | 45 |
11 files changed, 54 insertions, 73 deletions
diff --git a/sys/arch/macppc/dev/awacs.c b/sys/arch/macppc/dev/awacs.c index 45b44305d36..960773d96ca 100644 --- a/sys/arch/macppc/dev/awacs.c +++ b/sys/arch/macppc/dev/awacs.c @@ -1,4 +1,4 @@ -/* $NetBSD: awacs.c,v 1.48 2019/06/08 08:02:37 isaki Exp $ */ +/* $NetBSD: awacs.c,v 1.49 2021/01/26 14:49:41 thorpej Exp $ */ /*- * Copyright (c) 2000 Tsubai Masanari. All rights reserved. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: awacs.c,v 1.48 2019/06/08 08:02:37 isaki Exp $"); +__KERNEL_RCSID(0, "$NetBSD: awacs.c,v 1.49 2021/01/26 14:49:41 thorpej Exp $"); #include <sys/param.h> #include <sys/audioio.h> @@ -373,7 +373,7 @@ awacs_attach(device_t parent, device_t self, void *aux) cv_init(&sc->sc_event, "awacs_wait"); /* check if the chip is a screamer */ - sc->sc_screamer = (of_compatible(ca->ca_node, screamer) != -1); + sc->sc_screamer = of_compatible(ca->ca_node, screamer); if (!sc->sc_screamer) { /* look for 'sound' child node */ int sound_node; @@ -381,8 +381,7 @@ awacs_attach(device_t parent, device_t self, void *aux) sound_node = OF_child(ca->ca_node); while ((sound_node != 0) && (!sc->sc_screamer)) { - sc->sc_screamer = - (of_compatible(sound_node, screamer) != -1); + sc->sc_screamer = of_compatible(sound_node, screamer); sound_node = OF_peer(sound_node); } } @@ -426,7 +425,7 @@ awacs_attach(device_t parent, device_t self, void *aux) */ perch = OF_finddevice("/perch"); root_node = OF_finddevice("/"); - if (of_compatible(root_node, detect_reversed) != -1) { + if (of_compatible(root_node, detect_reversed)) { /* 0x02 is for the microphone jack, high active */ /* @@ -435,8 +434,7 @@ awacs_attach(device_t parent, device_t self, void *aux) */ sc->sc_headphones_mask = 0x8; sc->sc_headphones_in = 0x0; - } else if ((perch != -1) || - (of_compatible(root_node, use_gpio4) != -1)) { + } else if ((perch != -1) || of_compatible(root_node, use_gpio4)) { /* * this is for the beige G3's 'personality card' which uses * yet another wiring of the headphone detect GPIOs @@ -450,7 +448,7 @@ awacs_attach(device_t parent, device_t self, void *aux) sc->sc_headphones_in = 0x8; } - if (of_compatible(root_node, no_parallel_output) != -1) + if (of_compatible(root_node, no_parallel_output)) sc->sc_need_parallel_output = 0; else { sc->sc_need_parallel_output = 1; diff --git a/sys/arch/macppc/dev/mediabay.c b/sys/arch/macppc/dev/mediabay.c index 353c20106f1..b907ba46933 100644 --- a/sys/arch/macppc/dev/mediabay.c +++ b/sys/arch/macppc/dev/mediabay.c @@ -1,4 +1,4 @@ -/* $NetBSD: mediabay.c,v 1.22 2011/07/26 08:36:02 macallan Exp $ */ +/* $NetBSD: mediabay.c,v 1.23 2021/01/26 14:49:41 thorpej Exp $ */ /*- * Copyright (C) 1999 Tsubai Masanari. All rights reserved. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: mediabay.c,v 1.22 2011/07/26 08:36:02 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mediabay.c,v 1.23 2021/01/26 14:49:41 thorpej Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -132,7 +132,7 @@ mediabay_attach(device_t parent, device_t self, void *aux) irq = ca->ca_intr[0]; itype = IST_EDGE; - if (of_compatible(ca->ca_node, mediabay_keylargo) != -1) { + if (of_compatible(ca->ca_node, mediabay_keylargo)) { sc->sc_type = MB_CONTROLLER_KEYLARGO; sc->sc_fcr = sc->sc_addr + 2; } else { diff --git a/sys/arch/macppc/dev/obio.c b/sys/arch/macppc/dev/obio.c index 64a3686bea5..3cbd2e73573 100644 --- a/sys/arch/macppc/dev/obio.c +++ b/sys/arch/macppc/dev/obio.c @@ -1,4 +1,4 @@ -/* $NetBSD: obio.c,v 1.47 2020/10/25 16:39:00 nia Exp $ */ +/* $NetBSD: obio.c,v 1.48 2021/01/26 14:49:41 thorpej Exp $ */ /*- * Copyright (C) 1998 Internet Research Institute, Inc. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.47 2020/10/25 16:39:00 nia Exp $"); +__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.48 2021/01/26 14:49:41 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -368,7 +368,7 @@ obio_setup_gpios(struct obio_softc *sc, int node) char name[32]; int child, use_dfs, cpunode, hiclock; - if (of_compatible(sc->sc_node, keylargo) == -1) + if (! of_compatible(sc->sc_node, keylargo)) return; if (OF_getprop(node, "reg", reg, sizeof(reg)) < 4) diff --git a/sys/arch/macppc/dev/pmu.c b/sys/arch/macppc/dev/pmu.c index 242f8946d53..ae57229025f 100644 --- a/sys/arch/macppc/dev/pmu.c +++ b/sys/arch/macppc/dev/pmu.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmu.c,v 1.34 2020/07/14 08:58:03 martin Exp $ */ +/* $NetBSD: pmu.c,v 1.35 2021/01/26 14:49:41 thorpej Exp $ */ /*- * Copyright (c) 2006 Michael Lorenz @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.34 2020/07/14 08:58:03 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.35 2021/01/26 14:49:41 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -428,10 +428,10 @@ next: } /* attach batteries */ - if (of_compatible(root_node, has_legacy_battery) != -1) { + if (of_compatible(root_node, has_legacy_battery)) { pmu_attach_legacy_battery(sc); - } else if (of_compatible(root_node, has_two_smart_batteries) != -1) { + } else if (of_compatible(root_node, has_two_smart_batteries)) { pmu_attach_smart_battery(sc, 0); pmu_attach_smart_battery(sc, 1); diff --git a/sys/arch/macppc/dev/wdc_obio.c b/sys/arch/macppc/dev/wdc_obio.c index dde436ed14f..7ecc4ef3400 100644 --- a/sys/arch/macppc/dev/wdc_obio.c +++ b/sys/arch/macppc/dev/wdc_obio.c @@ -1,4 +1,4 @@ -/* $NetBSD: wdc_obio.c,v 1.61 2017/10/20 07:06:07 jdolecek Exp $ */ +/* $NetBSD: wdc_obio.c,v 1.62 2021/01/26 14:49:41 thorpej Exp $ */ /*- * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.61 2017/10/20 07:06:07 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.62 2021/01/26 14:49:41 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -107,7 +107,7 @@ wdc_obio_match(device_t parent, cfdata_t match, void *aux) strcmp(ca->ca_name, "ide") == 0) return 1; - if (of_compatible(ca->ca_node, ata_names) >= 0) + if (of_compatible(ca->ca_node, ata_names)) return 1; return 0; diff --git a/sys/arch/macppc/macppc/interrupts.c b/sys/arch/macppc/macppc/interrupts.c index 8db53576f0e..5ebfd7e8aac 100644 --- a/sys/arch/macppc/macppc/interrupts.c +++ b/sys/arch/macppc/macppc/interrupts.c @@ -1,4 +1,4 @@ -/* $NetBSD: interrupts.c,v 1.7 2018/05/11 22:48:38 macallan Exp $ */ +/* $NetBSD: interrupts.c,v 1.8 2021/01/26 14:49:41 thorpej Exp $ */ /*- * Copyright (c) 2007 Michael Lorenz @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: interrupts.c,v 1.7 2018/05/11 22:48:38 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: interrupts.c,v 1.8 2021/01/26 14:49:41 thorpej Exp $"); #include "opt_multiprocessor.h" @@ -81,7 +81,7 @@ init_openpic(int pass_through) aprint_debug("macio: %08x\n", macio); pic = OF_child(macio); - while ((pic != 0) && (of_compatible(pic, compat) == -1)) + while ((pic != 0) && !of_compatible(pic, compat)) pic = OF_peer(pic); aprint_debug("pic: %08x\n", pic); diff --git a/sys/arch/macppc/macppc/machdep.c b/sys/arch/macppc/macppc/machdep.c index 11fff5bb89f..246d9242f87 100644 --- a/sys/arch/macppc/macppc/machdep.c +++ b/sys/arch/macppc/macppc/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.171 2020/07/14 08:55:07 martin Exp $ */ +/* $NetBSD: machdep.c,v 1.172 2021/01/26 14:49:41 thorpej Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.171 2020/07/14 08:55:07 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.172 2021/01/26 14:49:41 thorpej Exp $"); #include "opt_compat_netbsd.h" #include "opt_ddb.h" @@ -411,27 +411,27 @@ add_model_specifics(prop_dictionary_t dict) node = OF_finddevice("/"); - if (of_compatible(node, bl_rev_models) != -1) { + if (of_compatible(node, bl_rev_models)) { prop_dictionary_set_bool(dict, "backlight_level_reverted", 1); } - if (of_compatible(node, clamshell) != -1) { + if (of_compatible(node, clamshell)) { prop_data_t edid; edid = prop_data_create_nocopy(edid_clamshell, sizeof(edid_clamshell)); prop_dictionary_set(dict, "EDID", edid); prop_object_release(edid); } - if (of_compatible(node, pismo) != -1) { + if (of_compatible(node, pismo)) { prop_data_t edid; edid = prop_data_create_nocopy(edid_pismo, sizeof(edid_pismo)); prop_dictionary_set(dict, "EDID", edid); prop_object_release(edid); } - if (of_compatible(node, mini1) != -1) { + if (of_compatible(node, mini1)) { prop_dictionary_set_bool(dict, "dvi-internal", 1); } - if (of_compatible(node, mini2) != -1) { + if (of_compatible(node, mini2)) { prop_dictionary_set_bool(dict, "dvi-external", 1); } } diff --git a/sys/arch/macppc/macppc/pic_heathrow.c b/sys/arch/macppc/macppc/pic_heathrow.c index 3624a1cbcde..3c526b963fe 100644 --- a/sys/arch/macppc/macppc/pic_heathrow.c +++ b/sys/arch/macppc/macppc/pic_heathrow.c @@ -1,4 +1,4 @@ -/* $NetBSD: pic_heathrow.c,v 1.11 2017/06/16 18:48:22 macallan Exp $ */ +/* $NetBSD: pic_heathrow.c,v 1.12 2021/01/26 14:49:41 thorpej Exp $ */ /*- * Copyright (c) 2007 Michael Lorenz @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pic_heathrow.c,v 1.11 2017/06/16 18:48:22 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pic_heathrow.c,v 1.12 2021/01/26 14:49:41 thorpej Exp $"); #include "opt_interrupt.h" @@ -88,7 +88,7 @@ int init_heathrow(void) if (heathrow == -1) return FALSE; - if (of_compatible(heathrow, compat) == -1) + if (! of_compatible(heathrow, compat)) return FALSE; if (OF_getprop(heathrow, "assigned-addresses", reg, sizeof(reg)) != 20) diff --git a/sys/arch/macppc/macppc/pic_u3_ht.c b/sys/arch/macppc/macppc/pic_u3_ht.c index acda2933171..51e91340daf 100644 --- a/sys/arch/macppc/macppc/pic_u3_ht.c +++ b/sys/arch/macppc/macppc/pic_u3_ht.c @@ -1,4 +1,4 @@ -/* $NetBSD: pic_u3_ht.c,v 1.9 2020/07/15 09:58:34 rin Exp $ */ +/* $NetBSD: pic_u3_ht.c,v 1.10 2021/01/26 14:49:41 thorpej Exp $ */ /*- * Copyright (c) 2013 Phileas Fogg * All rights reserved. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pic_u3_ht.c,v 1.9 2020/07/15 09:58:34 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pic_u3_ht.c,v 1.10 2021/01/26 14:49:41 thorpej Exp $"); #include "opt_openpic.h" #include "opt_interrupt.h" @@ -140,11 +140,11 @@ int init_u3_ht(void) if (u4 == -1) return FALSE; - if (of_compatible(u4, u3_compat) == -1) + if (! of_compatible(u4, u3_compat)) return FALSE; pic = OF_child(u4); - while ((pic != 0) && (of_compatible(pic, pic_compat) == -1)) + while ((pic != 0) && !of_compatible(pic, pic_compat)) pic = OF_peer(pic); if ((pic == -1) || (pic == 0)) diff --git a/sys/arch/macppc/pci/pci_machdep.c b/sys/arch/macppc/pci/pci_machdep.c index 432ddef7067..1fb6254f92e 100644 --- a/sys/arch/macppc/pci/pci_machdep.c +++ b/sys/arch/macppc/pci/pci_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.c,v 1.42 2019/03/01 09:25:59 msaitoh Exp $ */ +/* $NetBSD: pci_machdep.c,v 1.43 2021/01/26 14:49:41 thorpej Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. @@ -43,7 +43,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.42 2019/03/01 09:25:59 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.43 2021/01/26 14:49:41 thorpej Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -339,7 +339,7 @@ fix_cardbus_bridge(int node, pci_chipset_tag_t pc, pcitag_t tag) int root_node; root_node = OF_finddevice("/"); - if (of_compatible(root_node, pb3400_compat) != -1) { + if (of_compatible(root_node, pb3400_compat)) { bus_number = cardbus_number; cardbus_number++; 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); } /* |
