Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ofisa of_compatible() is a hokey API (returning -1 f...



details:   https://anonhg.NetBSD.org/src/rev/4d98b5d16985
branches:  trunk
changeset: 958783:4d98b5d16985
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Jan 19 14:39:20 2021 +0000

description:
of_compatible() is a hokey API (returning -1 for no match) and nothing
here relies on its reverse-index return value semantics, so just use
of_match_compat_data() instead.

diffstat:

 sys/dev/ofisa/atppc_ofisa.c |  16 ++++++++++------
 sys/dev/ofisa/com_ofisa.c   |  15 +++++++++------
 sys/dev/ofisa/ess_ofisa.c   |  26 +++++++++++---------------
 sys/dev/ofisa/if_cs_ofisa.c |  22 +++++++++++-----------
 sys/dev/ofisa/joy_ofisa.c   |  18 ++++++++----------
 sys/dev/ofisa/lpt_ofisa.c   |  15 +++++++++------
 sys/dev/ofisa/ofisa.c       |  16 +++++++++-------
 sys/dev/ofisa/sb_ofisa.c    |  34 +++++++++++++++-------------------
 sys/dev/ofisa/wdc_ofisa.c   |  15 +++++++++------
 9 files changed, 91 insertions(+), 86 deletions(-)

diffs (truncated from 414 to 300 lines):

diff -r 75621f232abd -r 4d98b5d16985 sys/dev/ofisa/atppc_ofisa.c
--- a/sys/dev/ofisa/atppc_ofisa.c       Tue Jan 19 14:35:30 2021 +0000
+++ b/sys/dev/ofisa/atppc_ofisa.c       Tue Jan 19 14:39:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atppc_ofisa.c,v 1.10 2008/04/28 20:23:54 martin Exp $ */
+/* $NetBSD: atppc_ofisa.c,v 1.11 2021/01/19 14:39:20 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atppc_ofisa.c,v 1.10 2008/04/28 20:23:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atppc_ofisa.c,v 1.11 2021/01/19 14:39:20 thorpej Exp $");
 
 #include "opt_atppc.h"
 
@@ -73,6 +73,12 @@
        bus_size_t);
 static void atppc_ofisa_dma_free(device_t, void **, bus_addr_t *,
        bus_size_t);
+
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "pnpPNP,401" },
+       { 0 }
+};
+
 /*
  * atppc_ofisa_match: autoconf(9) match routine
  */
@@ -80,11 +86,9 @@
 atppc_ofisa_match(device_t parent, cfdata_t match, void *aux)
 {
        struct ofisa_attach_args *aa = aux;
-       static const char *const compatible_strings[] = { "pnpPNP,401", NULL };
-       int rv = 0;
+       int rv;
 
-       if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
-               rv = 5;
+       rv = of_match_compat_data(aa->oba.oba_phandle, compat_data) ? 5 : 0;
 #ifdef _LPT_OFISA_MD_MATCH
        if (!rv)
                rv = lpt_ofisa_md_match(parent, match, aux);
diff -r 75621f232abd -r 4d98b5d16985 sys/dev/ofisa/com_ofisa.c
--- a/sys/dev/ofisa/com_ofisa.c Tue Jan 19 14:35:30 2021 +0000
+++ b/sys/dev/ofisa/com_ofisa.c Tue Jan 19 14:39:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: com_ofisa.c,v 1.16 2018/12/08 17:46:14 thorpej Exp $   */
+/*     $NetBSD: com_ofisa.c,v 1.17 2021/01/19 14:39:20 thorpej Exp $   */
 
 /*
  * Copyright 1997, 1998
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com_ofisa.c,v 1.16 2018/12/08 17:46:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_ofisa.c,v 1.17 2021/01/19 14:39:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -68,15 +68,18 @@
 CFATTACH_DECL_NEW(com_ofisa, sizeof(struct com_ofisa_softc),
     com_ofisa_probe, com_ofisa_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "pnpPNP,501" },
+       { 0 }
+};
+
 int
 com_ofisa_probe(device_t parent, cfdata_t cf, void *aux)
 {
        struct ofisa_attach_args *aa = aux;
-       static const char *const compatible_strings[] = { "pnpPNP,501", NULL };
-       int rv = 0;
+       int rv;
 
-       if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
-               rv = 5;
+       rv = of_match_compat_data(aa->oba.oba_phandle, compat_data) ? 5 : 0;
 #ifdef _COM_OFISA_MD_MATCH
        if (!rv)
                rv = com_ofisa_md_match(parent, cf, aux);
diff -r 75621f232abd -r 4d98b5d16985 sys/dev/ofisa/ess_ofisa.c
--- a/sys/dev/ofisa/ess_ofisa.c Tue Jan 19 14:35:30 2021 +0000
+++ b/sys/dev/ofisa/ess_ofisa.c Tue Jan 19 14:39:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ess_ofisa.c,v 1.28 2019/05/08 13:40:18 isaki Exp $     */
+/*     $NetBSD: ess_ofisa.c,v 1.29 2021/01/19 14:39:20 thorpej Exp $   */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ess_ofisa.c,v 1.28 2019/05/08 13:40:18 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ess_ofisa.c,v 1.29 2021/01/19 14:39:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -56,24 +56,20 @@
 CFATTACH_DECL_NEW(ess_ofisa, sizeof(struct ess_softc),
     ess_ofisa_match, ess_ofisa_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "ESST,es1887-codec" },      /* ESS 1887 */
+       { .compat = "ESST,es1888-codec" },      /* ESS 1888 */
+       { .compat = "ESST,es888-codec" },       /* ESS 888 */
+       { 0 }
+};
+
 int
 ess_ofisa_match(device_t parent, cfdata_t cf, void *aux)
 {
        struct ofisa_attach_args *aa = aux;
-       static const char *const compatible_strings[] = {
-               "ESST,es1887-codec",            /* ESS 1887 */
-               "ESST,es1888-codec",            /* ESS 1888 */
-               "ESST,es888-codec",             /* ESS 888 */
-               NULL,
-       };
-       int rv = 0;
 
-       /* XXX table */
-       if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) {
-               rv = 10;
-       }
-
-       return (rv);
+                                                       /* beat generic SB */
+       return of_match_compat_data(aa->oba.oba_phandle, compat_data) ? 10 : 0;
 }
 
 void
diff -r 75621f232abd -r 4d98b5d16985 sys/dev/ofisa/if_cs_ofisa.c
--- a/sys/dev/ofisa/if_cs_ofisa.c       Tue Jan 19 14:35:30 2021 +0000
+++ b/sys/dev/ofisa/if_cs_ofisa.c       Tue Jan 19 14:39:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cs_ofisa.c,v 1.27 2016/12/09 17:18:35 christos Exp $        */
+/*     $NetBSD: if_cs_ofisa.c,v 1.28 2021/01/19 14:39:20 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cs_ofisa.c,v 1.27 2016/12/09 17:18:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cs_ofisa.c,v 1.28 2021/01/19 14:39:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -66,20 +66,20 @@
 CFATTACH_DECL_NEW(cs_ofisa, sizeof(struct cs_softc_isa),
     cs_ofisa_match, cs_ofisa_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "CRUS,CS8900" },
+       /* XXX CS8920, CS8920M? */
+       /* XXX PNP names? */
+       { 0 }
+};
+
 int
 cs_ofisa_match(device_t parent, cfdata_t cf, void *aux)
 {
        struct ofisa_attach_args *aa = aux;
-       static const char *const compatible_strings[] = {
-               "CRUS,CS8900",
-               /* XXX CS8920, CS8920M? */
-               /* XXX PNP names? */
-               NULL,
-       };
-       int rv = 0;
+       int rv;
 
-       if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
-               rv = 5;
+       rv = of_match_compat_data(aa->oba.oba_phandle, compat_data) ? 5 : 0;
 #ifdef _CS_OFISA_MD_MATCH
        if (rv == 0)
                rv = cs_ofisa_md_match(parent, cf, aux);
diff -r 75621f232abd -r 4d98b5d16985 sys/dev/ofisa/joy_ofisa.c
--- a/sys/dev/ofisa/joy_ofisa.c Tue Jan 19 14:35:30 2021 +0000
+++ b/sys/dev/ofisa/joy_ofisa.c Tue Jan 19 14:39:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: joy_ofisa.c,v 1.16 2016/12/09 17:18:35 christos Exp $  */
+/*     $NetBSD: joy_ofisa.c,v 1.17 2021/01/19 14:39:20 thorpej Exp $   */
 
 /*-
  * Copyright (c) 1996, 1998, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: joy_ofisa.c,v 1.16 2016/12/09 17:18:35 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: joy_ofisa.c,v 1.17 2021/01/19 14:39:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -58,19 +58,17 @@
 CFATTACH_DECL_NEW(joy_ofisa, sizeof(struct joy_ofisa_softc),
     joy_ofisa_match, joy_ofisa_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "pnpPNP,b02f" },    /* generic joystick */
+       { 0 }
+};
+
 static int
 joy_ofisa_match(device_t parent, cfdata_t match, void *aux)
 {
        struct ofisa_attach_args *aa = aux;
-       static const char *const compatible_strings[] = {
-               "pnpPNP,b02f",                  /* generic joystick */
-               NULL,
-       };
-       int rv = 0;
 
-       if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
-               rv = 1;
-       return rv;
+       return of_match_compat_data(aa->oba.oba_phandle, compat_data);
 }
 
 static void
diff -r 75621f232abd -r 4d98b5d16985 sys/dev/ofisa/lpt_ofisa.c
--- a/sys/dev/ofisa/lpt_ofisa.c Tue Jan 19 14:35:30 2021 +0000
+++ b/sys/dev/ofisa/lpt_ofisa.c Tue Jan 19 14:39:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lpt_ofisa.c,v 1.15 2012/10/27 17:18:27 chs Exp $       */
+/*     $NetBSD: lpt_ofisa.c,v 1.16 2021/01/19 14:39:20 thorpej Exp $   */
 
 /*
  * Copyright 1997, 1998
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lpt_ofisa.c,v 1.15 2012/10/27 17:18:27 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lpt_ofisa.c,v 1.16 2021/01/19 14:39:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -68,15 +68,18 @@
 CFATTACH_DECL_NEW(lpt_ofisa, sizeof(struct lpt_ofisa_softc),
     lpt_ofisa_probe, lpt_ofisa_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "pnpPNP,401" },
+       { 0 }
+};
+
 int
 lpt_ofisa_probe(device_t parent, cfdata_t cf, void *aux)
 {
        struct ofisa_attach_args *aa = aux;
-       static const char *const compatible_strings[] = { "pnpPNP,401", NULL };
-       int rv = 0;
+       int rv;
 
-       if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
-               rv = 5;
+       rv = of_match_compat_data(aa->oba.oba_phandle, compat_data) ? 5 : 0;
 #ifdef _LPT_OFISA_MD_MATCH
        if (!rv)
                rv = lpt_ofisa_md_match(parent, cf, aux);
diff -r 75621f232abd -r 4d98b5d16985 sys/dev/ofisa/ofisa.c
--- a/sys/dev/ofisa/ofisa.c     Tue Jan 19 14:35:30 2021 +0000
+++ b/sys/dev/ofisa/ofisa.c     Tue Jan 19 14:39:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofisa.c,v 1.26 2018/09/03 16:29:32 riastradh Exp $     */
+/*     $NetBSD: ofisa.c,v 1.27 2021/01/19 14:39:20 thorpej Exp $       */
 
 /*
  * Copyright 1997, 1998
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofisa.c,v 1.26 2018/09/03 16:29:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofisa.c,v 1.27 2021/01/19 14:39:20 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -75,16 +75,18 @@
        return UNCONF;
 }
 
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "pnpPNP,a00" },
+       { 0 }
+};
+
 int
 ofisamatch(device_t parent, cfdata_t cf, void *aux)



Home | Main Index | Thread Index | Old Index