Make control clients use struct opt to reach the device

This commit is contained in:
Alexandre Ratchov 2021-01-27 14:14:28 +01:00
parent 1e1589d70e
commit a78ec25e07
3 changed files with 18 additions and 15 deletions

View File

@ -1280,7 +1280,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);
@ -2304,7 +2304,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;
@ -2319,13 +2319,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;
}
@ -2338,7 +2338,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) {
@ -2348,7 +2348,7 @@ ctlslot_del(struct ctlslot *s)
pc = &c->next;
}
s->ops = NULL;
dev_unref(s->dev);
dev_unref(s->opt->dev);
}
void
@ -2506,7 +2506,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);
}
}

View File

@ -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);

View File

@ -895,7 +895,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);
@ -1253,7 +1256,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;
@ -1287,7 +1290,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
@ -1541,7 +1544,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) {
@ -1598,7 +1601,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;