diff options
author | 2010-09-08 15:16:22 +0000 | |
---|---|---|
committer | 2010-09-08 15:16:22 +0000 | |
commit | 31efee770aa1c60e31abd5b519f273f319cd9344 (patch) | |
tree | d4ade9ef9877638fd561f4a9eafde6bde1000dbd /sys/kern/subr_disk.c | |
parent | Set rcs_suffixes to default value on initialization. (diff) | |
download | wireguard-openbsd-31efee770aa1c60e31abd5b519f273f319cd9344.tar.xz wireguard-openbsd-31efee770aa1c60e31abd5b519f273f319cd9344.zip |
Introduce a disk_lookup() function which calls device_lookup(), before
verifying that the resulting device is present on the disklist. This
avoids a race whereby the disk driver can be accessed as soon as the
softc has been allocated, but before the disk has completed
initialisation and has called disk_attach() (up until this point
dk_label is still a null pointer).
Cut cd(4), sd(4) and wd(4) across to disk_lookup(). All callers of
disk_attach() need to be tested and cut over in due course.
ok deraadt@ krw@
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r-- | sys/kern/subr_disk.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index abaacf364d1..fbdf1a78d30 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.108 2010/09/08 14:47:12 jsing Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.109 2010/09/08 15:16:22 jsing Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -1394,3 +1394,28 @@ disk_map(char *path, char *mappath, int size, int flags) return 0; } + +/* + * Lookup a disk device and verify that it has completed attaching. + */ +struct device * +disk_lookup(struct cfdriver *cd, int unit) +{ + struct device *dv; + struct disk *dk; + + dv = device_lookup(cd, unit); + if (dv == NULL) + return (NULL); + + TAILQ_FOREACH(dk, &disklist, dk_link) + if (dk->dk_device == dv) + break; + + if (dk == NULL) { + device_unref(dv); + return (NULL); + } + + return (dv); +} |