Module Name: src Committed By: thorpej Date: Tue Jan 26 14:49:41 UTC 2021
Modified Files: src/sys/arch/macppc/dev: awacs.c mediabay.c obio.c pmu.c wdc_obio.c src/sys/arch/macppc/macppc: interrupts.c machdep.c pic_heathrow.c pic_u3_ht.c src/sys/arch/macppc/pci: pci_machdep.c src/sys/dev/ofw: ofw_subr.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/sys/arch/macppc/dev/awacs.c cvs rdiff -u -r1.22 -r1.23 src/sys/arch/macppc/dev/mediabay.c cvs rdiff -u -r1.47 -r1.48 src/sys/arch/macppc/dev/obio.c cvs rdiff -u -r1.34 -r1.35 src/sys/arch/macppc/dev/pmu.c cvs rdiff -u -r1.61 -r1.62 src/sys/arch/macppc/dev/wdc_obio.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/macppc/macppc/interrupts.c cvs rdiff -u -r1.171 -r1.172 src/sys/arch/macppc/macppc/machdep.c cvs rdiff -u -r1.11 -r1.12 src/sys/arch/macppc/macppc/pic_heathrow.c cvs rdiff -u -r1.9 -r1.10 src/sys/arch/macppc/macppc/pic_u3_ht.c cvs rdiff -u -r1.42 -r1.43 src/sys/arch/macppc/pci/pci_machdep.c cvs rdiff -u -r1.51 -r1.52 src/sys/dev/ofw/ofw_subr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/macppc/dev/awacs.c diff -u src/sys/arch/macppc/dev/awacs.c:1.48 src/sys/arch/macppc/dev/awacs.c:1.49 --- src/sys/arch/macppc/dev/awacs.c:1.48 Sat Jun 8 08:02:37 2019 +++ src/sys/arch/macppc/dev/awacs.c Tue Jan 26 14:49:41 2021 @@ -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 s 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 s 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 s */ 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 s */ 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 s 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; Index: src/sys/arch/macppc/dev/mediabay.c diff -u src/sys/arch/macppc/dev/mediabay.c:1.22 src/sys/arch/macppc/dev/mediabay.c:1.23 --- src/sys/arch/macppc/dev/mediabay.c:1.22 Tue Jul 26 08:36:02 2011 +++ src/sys/arch/macppc/dev/mediabay.c Tue Jan 26 14:49:41 2021 @@ -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_ 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 { Index: src/sys/arch/macppc/dev/obio.c diff -u src/sys/arch/macppc/dev/obio.c:1.47 src/sys/arch/macppc/dev/obio.c:1.48 --- src/sys/arch/macppc/dev/obio.c:1.47 Sun Oct 25 16:39:00 2020 +++ src/sys/arch/macppc/dev/obio.c Tue Jan 26 14:49:41 2021 @@ -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, 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) Index: src/sys/arch/macppc/dev/pmu.c diff -u src/sys/arch/macppc/dev/pmu.c:1.34 src/sys/arch/macppc/dev/pmu.c:1.35 --- src/sys/arch/macppc/dev/pmu.c:1.34 Tue Jul 14 08:58:03 2020 +++ src/sys/arch/macppc/dev/pmu.c Tue Jan 26 14:49:41 2021 @@ -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); Index: src/sys/arch/macppc/dev/wdc_obio.c diff -u src/sys/arch/macppc/dev/wdc_obio.c:1.61 src/sys/arch/macppc/dev/wdc_obio.c:1.62 --- src/sys/arch/macppc/dev/wdc_obio.c:1.61 Fri Oct 20 07:06:07 2017 +++ src/sys/arch/macppc/dev/wdc_obio.c Tue Jan 26 14:49:41 2021 @@ -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 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; Index: src/sys/arch/macppc/macppc/interrupts.c diff -u src/sys/arch/macppc/macppc/interrupts.c:1.7 src/sys/arch/macppc/macppc/interrupts.c:1.8 --- src/sys/arch/macppc/macppc/interrupts.c:1.7 Fri May 11 22:48:38 2018 +++ src/sys/arch/macppc/macppc/interrupts.c Tue Jan 26 14:49:41 2021 @@ -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); Index: src/sys/arch/macppc/macppc/machdep.c diff -u src/sys/arch/macppc/macppc/machdep.c:1.171 src/sys/arch/macppc/macppc/machdep.c:1.172 --- src/sys/arch/macppc/macppc/machdep.c:1.171 Tue Jul 14 08:55:07 2020 +++ src/sys/arch/macppc/macppc/machdep.c Tue Jan 26 14:49:41 2021 @@ -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 di 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); } } Index: src/sys/arch/macppc/macppc/pic_heathrow.c diff -u src/sys/arch/macppc/macppc/pic_heathrow.c:1.11 src/sys/arch/macppc/macppc/pic_heathrow.c:1.12 --- src/sys/arch/macppc/macppc/pic_heathrow.c:1.11 Fri Jun 16 18:48:22 2017 +++ src/sys/arch/macppc/macppc/pic_heathrow.c Tue Jan 26 14:49:41 2021 @@ -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) Index: src/sys/arch/macppc/macppc/pic_u3_ht.c diff -u src/sys/arch/macppc/macppc/pic_u3_ht.c:1.9 src/sys/arch/macppc/macppc/pic_u3_ht.c:1.10 --- src/sys/arch/macppc/macppc/pic_u3_ht.c:1.9 Wed Jul 15 09:58:34 2020 +++ src/sys/arch/macppc/macppc/pic_u3_ht.c Tue Jan 26 14:49:41 2021 @@ -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)) Index: src/sys/arch/macppc/pci/pci_machdep.c diff -u src/sys/arch/macppc/pci/pci_machdep.c:1.42 src/sys/arch/macppc/pci/pci_machdep.c:1.43 --- src/sys/arch/macppc/pci/pci_machdep.c:1.42 Fri Mar 1 09:25:59 2019 +++ src/sys/arch/macppc/pci/pci_machdep.c Tue Jan 26 14:49:41 2021 @@ -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 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++; Index: src/sys/dev/ofw/ofw_subr.c diff -u src/sys/dev/ofw/ofw_subr.c:1.51 src/sys/dev/ofw/ofw_subr.c:1.52 --- src/sys/dev/ofw/ofw_subr.c:1.51 Tue Jan 26 14:09:11 2021 +++ src/sys/dev/ofw/ofw_subr.c Tue Jan 26 14:49:41 2021 @@ -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 * { 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 * 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); } /*