Explicitly hold a reference to the cdev we have just cloned. This

closes the race where the cdev was reclaimed before it ever made it
back to devfs lookup.
This commit is contained in:
Poul-Henning Kamp 2005-03-31 12:19:44 +00:00
parent c06ac233d7
commit f4f6abcb4e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=144389
16 changed files with 26 additions and 5 deletions

View File

@ -1035,6 +1035,7 @@ targclone(void *arg, char *name, int namelen, struct cdev **dev)
return;
*dev = make_dev(&targ_cdevsw, unit2minor(u), UID_ROOT, GID_WHEEL,
0600, "targ%d", u);
dev_ref(*dev);
(*dev)->si_flags |= SI_CHEAPCLONE;
}

View File

@ -120,6 +120,7 @@ static void coda_fbsd_clone(arg, name, namelen, dev)
return;
*dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u);
dev_ref(*dev);
mnt = malloc(sizeof(struct coda_mntinfo), M_CODA, M_WAITOK|M_ZERO);
LIST_INSERT_HEAD(&coda_mnttbl, mnt, mi_list);
}

View File

@ -875,6 +875,7 @@ fwdev_clone(void *arg, char *name, int namelen, struct cdev **dev)
*dev = make_dev(&firewire_cdevsw, MAKEMINOR(devflag[i], unit, sub),
UID_ROOT, GID_OPERATOR, 0660,
"%s%d.%d", devnames[i], unit, sub);
dev_ref(*dev);
(*dev)->si_flags |= SI_CHEAPCLONE;
dev_depends(sc->dev, *dev);
return;

View File

@ -147,6 +147,7 @@ nmdm_clone(void *arg, char *name, int nameen, struct cdev **dev)
*dev = d1->si_drv2;
else
*dev = d1;
dev_ref(*dev);
}
static void

View File

@ -643,8 +643,10 @@ snp_clone(arg, name, namelen, dev)
if (i)
*dev = make_dev(&snp_cdevsw, unit2minor(u),
UID_ROOT, GID_WHEEL, 0600, "snp%d", u);
if (*dev != NULL)
if (*dev != NULL) {
dev_ref(*dev);
(*dev)->si_flags |= SI_CHEAPCLONE;
}
}
static int

View File

@ -1174,6 +1174,7 @@ dsp_clone(void *arg, char *name, int namelen, struct cdev **dev)
if ((pdev->si_drv1 == NULL) && (pdev->si_drv2 == NULL)) {
*dev = pdev;
dev_ref(*dev);
return;
}
}

View File

@ -494,8 +494,10 @@ mixer_clone(void *arg, char *name, int namelen, struct cdev **dev)
return;
if (strcmp(name, "mixer") == 0) {
sd = devclass_get_softc(pcm_devclass, snd_unit);
if (sd != NULL)
if (sd != NULL) {
*dev = sd->mixer_dev;
dev_ref(*dev);
}
}
}

View File

@ -168,8 +168,10 @@ vkbd_dev_clone(void *arg, char *name, int namelen, struct cdev **dev)
if (clone_create(&vkbd_dev_clones, &vkbd_dev_cdevsw, &unit, dev, 0)) {
*dev = make_dev(&vkbd_dev_cdevsw, unit2minor(unit),
UID_ROOT, GID_WHEEL, 0600, DEVICE_NAME "%d", unit);
if (*dev != NULL)
if (*dev != NULL) {
dev_ref(*dev);
(*dev)->si_flags |= SI_CHEAPCLONE;
}
}
}

View File

@ -120,6 +120,7 @@ static void coda_fbsd_clone(arg, name, namelen, dev)
return;
*dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u);
dev_ref(*dev);
mnt = malloc(sizeof(struct coda_mntinfo), M_CODA, M_WAITOK|M_ZERO);
LIST_INSERT_HEAD(&coda_mnttbl, mnt, mi_list);
}

View File

@ -655,6 +655,7 @@ devfs_lookupx(ap)
devfs_populate(dmp);
dde = devfs_itode(dmp, cdev->si_inode);
dev_rel(cdev);
if (dde == NULL || *dde == NULL || *dde == DE_DELETED)
goto notfound;

View File

@ -710,6 +710,7 @@ pty_clone(void *arg, char *name, int namelen, struct cdev **dev)
return;
*dev = make_dev(&ptc_cdevsw, u,
UID_ROOT, GID_WHEEL, 0666, "pty%c%r", names[u / 32], u % 32);
dev_ref(*dev);
(*dev)->si_flags |= SI_CHEAPCLONE;
return;
}

View File

@ -65,6 +65,7 @@ ctty_clone(void *arg, char *name, int namelen, struct cdev **dev)
*dev = ctty;
else
*dev = curthread->td_proc->p_session->s_ttyvp->v_rdev;
dev_ref(*dev);
}
static void

View File

@ -1605,6 +1605,7 @@ bpf_clone(arg, name, namelen, dev)
return;
*dev = make_dev(&bpf_cdevsw, unit2minor(u), UID_ROOT, GID_WHEEL, 0600,
"bpf%d", u);
dev_ref(*dev);
(*dev)->si_flags |= SI_CHEAPCLONE;
return;
}

View File

@ -253,8 +253,10 @@ tapclone(arg, name, namelen, dev)
if (i) {
*dev = make_dev(&tap_cdevsw, unit2minor(unit | extra),
UID_ROOT, GID_WHEEL, 0600, "%s%d", device_name, unit);
if (*dev != NULL)
if (*dev != NULL) {
dev_ref(*dev);
(*dev)->si_flags |= SI_CHEAPCLONE;
}
}
} /* tapclone */

View File

@ -155,8 +155,10 @@ tunclone(void *arg, char *name, int namelen, struct cdev **dev)
/* No preexisting struct cdev *, create one */
*dev = make_dev(&tun_cdevsw, unit2minor(u),
UID_UUCP, GID_DIALER, 0600, "tun%d", u);
if (*dev != NULL)
if (*dev != NULL) {
dev_ref(*dev);
(*dev)->si_flags |= SI_CHEAPCLONE;
}
}
}

View File

@ -109,6 +109,7 @@ nsmb_dev_clone(void *arg, char *name, int namelen, struct cdev **dev)
return;
*dev = make_dev(&nsmb_cdevsw, unit2minor(u), 0, 0, 0600,
NSMB_NAME"%d", u);
dev_ref(*dev);
}
static int