From 31a93d7badb7cdb6ebdade2dd9407d424ad888c0 Mon Sep 17 00:00:00 2001 From: dfr Date: Fri, 14 May 1999 09:13:43 +0000 Subject: Adjust method dispatch to ensure that default methods are called properly. --- sys/kern/subr_bus.c | 9 ++++++++- sys/sys/bus_private.h | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 8224b4a..bdfead6 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: subr_bus.c,v 1.20 1999/05/08 21:59:35 dfr Exp $ + * $Id: subr_bus.c,v 1.21 1999/05/10 17:06:14 dfr Exp $ */ #include @@ -93,6 +93,7 @@ static void device_unregister_oids(device_t dev); /* * Method table handling */ +static int error_method(void); static int next_method_offset = 1; LIST_HEAD(methodlist, method) methods; @@ -114,6 +115,12 @@ register_method(struct device_op_desc *desc) return; } + /* + * Make sure that desc->deflt is always valid to simplify dispatch. + */ + if (!desc->deflt) + desc->deflt = error_method; + for (m = LIST_FIRST(&methods); m; m = LIST_NEXT(m, link)) { if (!strcmp(m->name, desc->name)) { desc->offset = m->offset; diff --git a/sys/sys/bus_private.h b/sys/sys/bus_private.h index cbc2872..770ff6b 100644 --- a/sys/sys/bus_private.h +++ b/sys/sys/bus_private.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bus_private.h,v 1.6 1999/04/16 21:22:54 peter Exp $ + * $Id: bus_private.h,v 1.7 1999/05/10 17:06:11 dfr Exp $ */ #ifndef _SYS_BUS_PRIVATE_H_ @@ -93,15 +93,17 @@ struct device_ops { */ #define DEVOPDESC(OP) (&OP##_##desc) -#define DEVOPOFF(OPS, OP) \ - ((DEVOPDESC(OP)->offset >= OPS->maxoffset \ - || !OPS->methods[DEVOPDESC(OP)->offset]) \ - ? 0 : DEVOPDESC(OP)->offset) - #define DEVOPS(DEV) (DEV->ops) -#define DEVOPMETH(DEV, OP) (DEVOPS(DEV)->methods[DEVOPOFF(DEVOPS(DEV), OP)]) +#define DEVOPMETH(DEV, OP) \ + ((DEVOPDESC(OP)->offset >= DEVOPS(DEV)->maxoffset) \ + ? DEVOPDESC(OP)->deflt \ + : DEVOPS(DEV)->methods[DEVOPDESC(OP)->offset]) + #define DRVOPS(DRV) ((struct device_ops *)DRV->ops) -#define DRVOPMETH(DRV, OP) (DRVOPS(DRV)->methods[DEVOPOFF(DRVOPS(DRV), OP)]) +#define DRVOPMETH(DRV, OP) \ + ((DEVOPDESC(OP)->offset >= DRVOPS(DRV)->maxoffset) \ + ? DEVOPDESC(OP)->deflt \ + : DRVOPS(DRV)->methods[DEVOPDESC(OP)->offset]) /* * Implementation of device. -- cgit v1.1