diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2021-01-29 11:36:45 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2021-01-29 11:36:45 +0000 |
commit | 39b81926fd6acbb8cec9915e9592c098b9dab27f (patch) | |
tree | abe04a7ec706f95874702472978dfb752eecc63b /usr.bin/sndiod | |
parent | 1df4b3fcdb9945f6686d687f86b7af8284049dad (diff) |
Make control clients use struct opt to reach the device
No behavior change. This decreases the number of explicit references
to the dev structure.
Diffstat (limited to 'usr.bin/sndiod')
-rw-r--r-- | usr.bin/sndiod/dev.c | 18 | ||||
-rw-r--r-- | usr.bin/sndiod/dev.h | 6 | ||||
-rw-r--r-- | usr.bin/sndiod/sock.c | 15 |
3 files changed, 21 insertions, 18 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index b476106c081..154eb6ba8c3 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.87 2021/01/29 11:31:28 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.88 2021/01/29 11:36:44 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -1279,7 +1279,7 @@ dev_abort(struct dev *d) d->slot_list = NULL; for (c = ctlslot_array, i = DEV_NCTLSLOT; i > 0; i--, c++) { - if (c->dev != d) + if (c->opt->dev != d) continue; if (c->ops) c->ops->exit(c->arg); @@ -2303,7 +2303,7 @@ slot_read(struct slot *s) * allocate at control slot */ struct ctlslot * -ctlslot_new(struct dev *d, struct ctlops *ops, void *arg) +ctlslot_new(struct opt *o, struct ctlops *ops, void *arg) { struct ctlslot *s; struct ctl *c; @@ -2318,13 +2318,13 @@ ctlslot_new(struct dev *d, struct ctlops *ops, void *arg) break; i++; } - s->dev = d; + s->opt = o; s->self = 1 << i; - if (!dev_ref(d)) + if (!dev_ref(o->dev)) return NULL; s->ops = ops; s->arg = arg; - for (c = d->ctl_list; c != NULL; c = c->next) + for (c = o->dev->ctl_list; c != NULL; c = c->next) c->refs_mask |= s->self; return s; } @@ -2337,7 +2337,7 @@ ctlslot_del(struct ctlslot *s) { struct ctl *c, **pc; - pc = &s->dev->ctl_list; + pc = &s->opt->dev->ctl_list; while ((c = *pc) != NULL) { c->refs_mask &= ~s->self; if (c->refs_mask == 0) { @@ -2347,7 +2347,7 @@ ctlslot_del(struct ctlslot *s) pc = &c->next; } s->ops = NULL; - dev_unref(s->dev); + dev_unref(s->opt->dev); } void @@ -2505,7 +2505,7 @@ dev_ctlsync(struct dev *d) } for (s = ctlslot_array, i = DEV_NCTLSLOT; i > 0; i--, s++) { - if (s->dev == d && s->ops) + if (s->ops && s->opt->dev == d) s->ops->sync(s->arg); } } diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h index baa5f88a24e..019691ab673 100644 --- a/usr.bin/sndiod/dev.h +++ b/usr.bin/sndiod/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.35 2021/01/29 11:31:28 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.36 2021/01/29 11:36:44 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -148,7 +148,7 @@ struct ctl { struct ctlslot { struct ctlops *ops; void *arg; - struct dev *dev; + struct opt *opt; unsigned int self; /* equal to (1 << index) */ unsigned int mode; }; @@ -309,7 +309,7 @@ void slot_detach(struct slot *); * control related functions */ void ctl_log(struct ctl *); -struct ctlslot *ctlslot_new(struct dev *, struct ctlops *, void *); +struct ctlslot *ctlslot_new(struct opt *, struct ctlops *, void *); void ctlslot_del(struct ctlslot *); int dev_setctl(struct dev *, int, int); int dev_onval(struct dev *, int, int); diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c index ad1af1c743d..6e276f96e4e 100644 --- a/usr.bin/sndiod/sock.c +++ b/usr.bin/sndiod/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.39 2021/01/29 11:31:28 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.40 2021/01/29 11:36:44 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * @@ -906,7 +906,10 @@ sock_hello(struct sock *f) } return 0; } - f->ctlslot = ctlslot_new(d, &sock_ctlops, f); + opt = opt_byname(d, p->opt); + if (opt == NULL) + return 0; + f->ctlslot = ctlslot_new(opt, &sock_ctlops, f); if (f->ctlslot == NULL) { if (log_level >= 2) { sock_log(f); @@ -1264,7 +1267,7 @@ sock_execmsg(struct sock *f) if (m->u.ctlsub.desc) { if (!(f->ctlops & SOCK_CTLDESC)) { ctl = f->ctlslot->self; - c = f->ctlslot->dev->ctl_list; + c = f->ctlslot->opt->dev->ctl_list; while (c != NULL) { c->desc_mask |= ctl; c = c->next; @@ -1298,7 +1301,7 @@ sock_execmsg(struct sock *f) sock_close(f); return 0; } - if (!dev_setctl(f->ctlslot->dev, + if (!dev_setctl(f->ctlslot->opt->dev, ntohs(m->u.ctlset.addr), ntohs(m->u.ctlset.val))) { #ifdef DEBUG @@ -1552,7 +1555,7 @@ sock_buildmsg(struct sock *f) desc = f->ctldesc; mask = f->ctlslot->self; size = 0; - pc = &f->ctlslot->dev->ctl_list; + pc = &f->ctlslot->opt->dev->ctl_list; while ((c = *pc) != NULL) { if ((c->desc_mask & mask) == 0 || (c->refs_mask & mask) == 0) { @@ -1609,7 +1612,7 @@ sock_buildmsg(struct sock *f) } if (f->ctlslot && (f->ctlops & SOCK_CTLVAL)) { mask = f->ctlslot->self; - for (c = f->ctlslot->dev->ctl_list; c != NULL; c = c->next) { + for (c = f->ctlslot->opt->dev->ctl_list; c != NULL; c = c->next) { if ((c->val_mask & mask) == 0) continue; c->val_mask &= ~mask; |