summaryrefslogtreecommitdiffstats
path: root/sys/boot
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2006-11-02 00:02:22 +0000
committermarcel <marcel@FreeBSD.org>2006-11-02 00:02:22 +0000
commita1fe87f061cf1a2a79a4796254fb525f5146a2d5 (patch)
tree6864e4193e39838d9c0620e4b655cc416c7caed7 /sys/boot
parentabfeec800f7ea83b4710e561d5d32f92765da464 (diff)
downloadFreeBSD-src-a1fe87f061cf1a2a79a4796254fb525f5146a2d5.zip
FreeBSD-src-a1fe87f061cf1a2a79a4796254fb525f5146a2d5.tar.gz
o Make sure to clear f->f_devdata if d_dev->dv_open() fails. It
would otherwise cause devclose() to free() the memory again. o Refactor devopen() so that it's more readable.
Diffstat (limited to 'sys/boot')
-rw-r--r--sys/boot/common/devopen.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/sys/boot/common/devopen.c b/sys/boot/common/devopen.c
index 28a2fab..7526141 100644
--- a/sys/boot/common/devopen.c
+++ b/sys/boot/common/devopen.c
@@ -35,20 +35,25 @@ __FBSDID("$FreeBSD$");
int
devopen(struct open_file *f, const char *fname, const char **file)
{
- struct devdesc *dev;
- int result;
-
- if ((result = archsw.arch_getdev((void *)&dev, fname, file)) == 0) { /* get the device */
- /* point to device-specific data so that device open can use it */
- f->f_devdata = dev;
- if ((result = dev->d_dev->dv_open(f, dev)) == 0) { /* try to open it */
- /* reference the devsw entry from the open_file structure */
- f->f_dev = dev->d_dev;
- } else {
- free(dev); /* release the device descriptor */
- }
+ struct devdesc *dev;
+ int result;
+
+ result = archsw.arch_getdev((void **)&dev, fname, file);
+ if (result)
+ return (result);
+
+ /* point to device-specific data so that device open can use it */
+ f->f_devdata = dev;
+ result = dev->d_dev->dv_open(f, dev);
+ if (result != 0) {
+ f->f_devdata = NULL;
+ free(dev);
+ return (result);
}
- return(result);
+
+ /* reference the devsw entry from the open_file structure */
+ f->f_dev = dev->d_dev;
+ return (0);
}
int
OpenPOWER on IntegriCloud