Module Name: src Committed By: thorpej Date: Tue Jun 26 04:32:35 UTC 2018
Modified Files: src/sys/dev/i2c: axppmic.c ds1307.c i2c.c i2cvar.h src/sys/kern: subr_autoconf.c src/sys/sys: device.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/dev/i2c/axppmic.c cvs rdiff -u -r1.27 -r1.28 src/sys/dev/i2c/ds1307.c cvs rdiff -u -r1.64 -r1.65 src/sys/dev/i2c/i2c.c cvs rdiff -u -r1.15 -r1.16 src/sys/dev/i2c/i2cvar.h cvs rdiff -u -r1.260 -r1.261 src/sys/kern/subr_autoconf.c cvs rdiff -u -r1.153 -r1.154 src/sys/sys/device.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/i2c/axppmic.c diff -u src/sys/dev/i2c/axppmic.c:1.12 src/sys/dev/i2c/axppmic.c:1.13 --- src/sys/dev/i2c/axppmic.c:1.12 Tue Jun 19 02:08:12 2018 +++ src/sys/dev/i2c/axppmic.c Tue Jun 26 04:32:35 2018 @@ -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 <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__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 <sys/param.h> #include <sys/systm.h> @@ -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 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); Index: src/sys/dev/i2c/ds1307.c diff -u src/sys/dev/i2c/ds1307.c:1.27 src/sys/dev/i2c/ds1307.c:1.28 --- src/sys/dev/i2c/ds1307.c:1.27 Mon Jun 18 17:07:07 2018 +++ src/sys/dev/i2c/ds1307.c Tue Jun 26 04:32:35 2018 @@ -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 <sys/cdefs.h> -__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 <sys/param.h> #include <sys/systm.h> @@ -249,8 +249,7 @@ dsrtc_model_by_compat(const struct i2c_a 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; Index: src/sys/dev/i2c/i2c.c diff -u src/sys/dev/i2c/i2c.c:1.64 src/sys/dev/i2c/i2c.c:1.65 --- src/sys/dev/i2c/i2c.c:1.64 Fri Jun 22 15:52:00 2018 +++ src/sys/dev/i2c/i2c.c Tue Jun 26 04:32:35 2018 @@ -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 <sys/cdefs.h> -__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 <sys/param.h> #include <sys/systm.h> @@ -695,22 +695,22 @@ iic_fill_compat(struct i2c_attach_args * * 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_at } 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; } Index: src/sys/dev/i2c/i2cvar.h diff -u src/sys/dev/i2c/i2cvar.h:1.15 src/sys/dev/i2c/i2cvar.h:1.16 --- src/sys/dev/i2c/i2cvar.h:1.15 Mon Jun 18 17:07:07 2018 +++ src/sys/dev/i2c/i2cvar.h Tue Jun 26 04:32:35 2018 @@ -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 *); Index: src/sys/kern/subr_autoconf.c diff -u src/sys/kern/subr_autoconf.c:1.260 src/sys/kern/subr_autoconf.c:1.261 --- src/sys/kern/subr_autoconf.c:1.260 Tue Jun 19 04:10:51 2018 +++ src/sys/kern/subr_autoconf.c Tue Jun 26 04:32:35 2018 @@ -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 <sys/cdefs.h> -__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 st * * 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 **dev 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; } /* Index: src/sys/sys/device.h diff -u src/sys/sys/device.h:1.153 src/sys/sys/device.h:1.154 --- src/sys/sys/device.h:1.153 Mon Jun 18 15:36:54 2018 +++ src/sys/sys/device.h Tue Jun 26 04:32:35 2018 @@ -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);