From 408f5aa57199ab519a199ca251c0f2667f0499ef Mon Sep 17 00:00:00 2001 From: thorpej Date: Tue, 26 Jun 2018 04:32:35 +0000 Subject: [PATCH] Change device_compatible_match() and iic_compatible_match() to return the weighted match value and take an optional compatible-entry pointer, rather than the other way around. --- sys/dev/i2c/axppmic.c | 8 ++++---- sys/dev/i2c/ds1307.c | 7 +++---- sys/dev/i2c/i2c.c | 27 +++++++++++++-------------- sys/dev/i2c/i2cvar.h | 8 ++++---- sys/kern/subr_autoconf.c | 22 +++++++++++----------- sys/sys/device.h | 9 ++++----- 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/sys/dev/i2c/axppmic.c b/sys/dev/i2c/axppmic.c index e95f913e858f..7a4c57238705 100644 --- a/sys/dev/i2c/axppmic.c +++ b/sys/dev/i2c/axppmic.c @@ -1,4 +1,4 @@ -/* $NetBSD: axppmic.c,v 1.12 2018/06/19 02:08:12 thorpej Exp $ */ +/* $NetBSD: axppmic.c,v 1.13 2018/06/26 04:32:35 thorpej Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.12 2018/06/19 02:08:12 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.13 2018/06/26 04:32:35 thorpej Exp $"); #include #include @@ -694,7 +694,7 @@ static void axppmic_attach(device_t parent, device_t self, void *aux) { struct axppmic_softc *sc = device_private(self); - const struct device_compatible_entry *dce; + const struct device_compatible_entry *dce = NULL; const struct axppmic_config *c; struct axpreg_attach_args aaa; struct i2c_attach_args *ia = aux; @@ -702,7 +702,7 @@ axppmic_attach(device_t parent, device_t self, void *aux) uint32_t irq_mask; void *ih; - dce = iic_compatible_match(ia, axppmic_compat_data, NULL); + (void) iic_compatible_match(ia, axppmic_compat_data, &dce); KASSERT(dce != NULL); c = DEVICE_COMPAT_ENTRY_GET_PTR(dce); diff --git a/sys/dev/i2c/ds1307.c b/sys/dev/i2c/ds1307.c index 5dd48ca7b5fb..e227bda688e4 100644 --- a/sys/dev/i2c/ds1307.c +++ b/sys/dev/i2c/ds1307.c @@ -1,4 +1,4 @@ -/* $NetBSD: ds1307.c,v 1.27 2018/06/18 17:07:07 thorpej Exp $ */ +/* $NetBSD: ds1307.c,v 1.28 2018/06/26 04:32:35 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -36,7 +36,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.27 2018/06/18 17:07:07 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.28 2018/06/26 04:32:35 thorpej Exp $"); #include #include @@ -249,8 +249,7 @@ dsrtc_model_by_compat(const struct i2c_attach_args *ia) const struct dsrtc_model *dm = NULL; const struct device_compatible_entry *dce; - dce = iic_compatible_match(ia, dsrtc_compat_data, NULL); - if (dce != NULL) + if (iic_compatible_match(ia, dsrtc_compat_data, &dce)) dm = DEVICE_COMPAT_ENTRY_GET_PTR(dce); return dm; diff --git a/sys/dev/i2c/i2c.c b/sys/dev/i2c/i2c.c index a048b34fd624..58b73bff3e51 100644 --- a/sys/dev/i2c/i2c.c +++ b/sys/dev/i2c/i2c.c @@ -1,4 +1,4 @@ -/* $NetBSD: i2c.c,v 1.64 2018/06/22 15:52:00 martin Exp $ */ +/* $NetBSD: i2c.c,v 1.65 2018/06/26 04:32:35 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ #endif #include -__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.64 2018/06/22 15:52:00 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.65 2018/06/26 04:32:35 thorpej Exp $"); #include #include @@ -695,22 +695,22 @@ iic_fill_compat(struct i2c_attach_args *ia, const char *compat, size_t len, * Match a device's "compatible" property against the list * of compatible strings provided by the driver. */ -const struct device_compatible_entry * +int iic_compatible_match(const struct i2c_attach_args *ia, const struct device_compatible_entry *compats, - int *match_resultp) + const struct device_compatible_entry **matching_entryp) { - const struct device_compatible_entry *dce; - int match_weight; + int match_result; - dce = device_compatible_match(ia->ia_compat, ia->ia_ncompat, - compats, &match_weight); - if (dce != NULL && match_resultp != NULL) { - *match_resultp = MIN(I2C_MATCH_DIRECT_COMPATIBLE + match_weight, - I2C_MATCH_DIRECT_COMPATIBLE_MAX); + match_result = device_compatible_match(ia->ia_compat, ia->ia_ncompat, + compats, matching_entryp); + if (match_result) { + match_result = + MIN(I2C_MATCH_DIRECT_COMPATIBLE + match_result - 1, + I2C_MATCH_DIRECT_COMPATIBLE_MAX); } - return dce; + return match_result; } /* @@ -735,8 +735,7 @@ iic_use_direct_match(const struct i2c_attach_args *ia, const cfdata_t cf, } if (ia->ia_ncompat > 0 && ia->ia_compat != NULL) { - if (iic_compatible_match(ia, compats, match_resultp) == NULL) - *match_resultp = 0; + *match_resultp = iic_compatible_match(ia, compats, NULL); return true; } diff --git a/sys/dev/i2c/i2cvar.h b/sys/dev/i2c/i2cvar.h index 0a0aa3e87a18..e9c70c74be78 100644 --- a/sys/dev/i2c/i2cvar.h +++ b/sys/dev/i2c/i2cvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: i2cvar.h,v 1.15 2018/06/18 17:07:07 thorpej Exp $ */ +/* $NetBSD: i2cvar.h,v 1.16 2018/06/26 04:32:35 thorpej Exp $ */ /* * Copyright (c) 2003 Wasabi Systems, Inc. @@ -164,9 +164,9 @@ int iicbus_print(void *, const char *); /* * API presented to i2c devices. */ -const struct device_compatible_entry * - iic_compatible_match(const struct i2c_attach_args *, - const struct device_compatible_entry *, int *); +int iic_compatible_match(const struct i2c_attach_args *, + const struct device_compatible_entry *, + const struct device_compatible_entry **); bool iic_use_direct_match(const struct i2c_attach_args *, const cfdata_t, const struct device_compatible_entry *, int *); diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index dac8eb365d4d..7f156329d628 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_autoconf.c,v 1.260 2018/06/19 04:10:51 thorpej Exp $ */ +/* $NetBSD: subr_autoconf.c,v 1.261 2018/06/26 04:32:35 thorpej Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -77,7 +77,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.260 2018/06/19 04:10:51 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.261 2018/06/26 04:32:35 thorpej Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -2302,20 +2302,20 @@ device_compatible_entry_matches(const struct device_compatible_entry *dce, * * Match a driver's "compatible" data against a device's * "compatible" strings. If a match is found, we return - * the matching device_compatible_entry, along with a - * matching weight. + * a weighted match result, and optionally the matching + * entry. */ -const struct device_compatible_entry * +int device_compatible_match(const char **device_compats, int ndevice_compats, const struct device_compatible_entry *driver_compats, - int *match_weightp) + const struct device_compatible_entry **matching_entryp) { const struct device_compatible_entry *dce = NULL; int i, match_weight; if (ndevice_compats == 0 || device_compats == NULL || driver_compats == NULL) - return NULL; + return 0; /* * We take the first match because we start with the most-specific @@ -2329,13 +2329,13 @@ device_compatible_match(const char **device_compats, int ndevice_compats, if (device_compatible_entry_matches(dce, device_compats[i])) { KASSERT(match_weight >= 0); - if (match_weightp) - *match_weightp = match_weight; - return dce; + if (matching_entryp) + *matching_entryp = dce; + return 1 + match_weight; } } } - return NULL; + return 0; } /* diff --git a/sys/sys/device.h b/sys/sys/device.h index 20f67c9aa414..44ce026342bc 100644 --- a/sys/sys/device.h +++ b/sys/sys/device.h @@ -1,4 +1,4 @@ -/* $NetBSD: device.h,v 1.153 2018/06/18 15:36:54 thorpej Exp $ */ +/* $NetBSD: device.h,v 1.154 2018/06/26 04:32:35 thorpej Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -552,10 +552,9 @@ bool device_is_a(device_t, const char *); device_t device_find_by_xname(const char *); device_t device_find_by_driver_unit(const char *, int); -const struct device_compatible_entry * - device_compatible_match(const char **, int, - const struct device_compatible_entry *, - int *); +int device_compatible_match(const char **, int, + const struct device_compatible_entry *, + const struct device_compatible_entry **); bool device_pmf_is_registered(device_t);