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.
This commit is contained in:
parent
65deb9d947
commit
ac2bbfc8cf
@ -38,17 +38,22 @@ devopen(struct open_file *f, const char *fname, const char **file)
|
|||||||
struct devdesc *dev;
|
struct devdesc *dev;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if ((result = archsw.arch_getdev((void *)&dev, fname, file)) == 0) { /* get the device */
|
result = archsw.arch_getdev((void **)&dev, fname, file);
|
||||||
|
if (result)
|
||||||
|
return (result);
|
||||||
|
|
||||||
/* point to device-specific data so that device open can use it */
|
/* point to device-specific data so that device open can use it */
|
||||||
f->f_devdata = dev;
|
f->f_devdata = dev;
|
||||||
if ((result = dev->d_dev->dv_open(f, dev)) == 0) { /* try to open it */
|
result = dev->d_dev->dv_open(f, dev);
|
||||||
|
if (result != 0) {
|
||||||
|
f->f_devdata = NULL;
|
||||||
|
free(dev);
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
/* reference the devsw entry from the open_file structure */
|
/* reference the devsw entry from the open_file structure */
|
||||||
f->f_dev = dev->d_dev;
|
f->f_dev = dev->d_dev;
|
||||||
} else {
|
return (0);
|
||||||
free(dev); /* release the device descriptor */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user