vfs: eliminte writes to NULL error code pointers
This commit is contained in:
parent
389ca018d1
commit
0f5da3c539
2 changed files with 9 additions and 4 deletions
8
fs/vfs.c
8
fs/vfs.c
|
|
@ -115,7 +115,7 @@ struct file *vfs_open(const char *pathname, int *err)
|
|||
/* try to open the vnode */
|
||||
struct vnode *new_vnode = slab_alloc(vnode_slab);
|
||||
if (!new_vnode) {
|
||||
*err = -ENOMEM;
|
||||
ATTEMPT_WRITE(err, -ENOMEM);
|
||||
goto out_2;
|
||||
}
|
||||
memset(new_vnode, 0, sizeof(struct vnode));
|
||||
|
|
@ -124,7 +124,7 @@ struct file *vfs_open(const char *pathname, int *err)
|
|||
|
||||
int res = fs->ops->open_vno(fs, new_vnode, entry->inode);
|
||||
if (res < 0) {
|
||||
*err = res;
|
||||
ATTEMPT_WRITE(err, res);
|
||||
slab_free(vnode_slab, new_vnode);
|
||||
goto out_2;
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@ struct file *vfs_open(const char *pathname, int *err)
|
|||
if (new_vnode->flags & VFS_VNO_DIR) {
|
||||
int res = fs->ops->open_dir(new_vnode->fs, new_vnode);
|
||||
if (res < 0) {
|
||||
*err = res;
|
||||
ATTEMPT_WRITE(err, res);
|
||||
slab_free(vnode_slab, new_vnode);
|
||||
goto out_2;
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ struct file *vfs_open(const char *pathname, int *err)
|
|||
}
|
||||
|
||||
if (!found) {
|
||||
*err = -ENOENT;
|
||||
ATTEMPT_WRITE(err, -ENOENT);
|
||||
|
||||
/* clean up */
|
||||
vfs_vnode_dec_ref(cur_vnode);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,11 @@
|
|||
#define PACKED __attribute__((packed))
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#define ATTEMPT_WRITE(_x, _y) \
|
||||
if (_x) { \
|
||||
*(_x) = _y; \
|
||||
}
|
||||
|
||||
#define KB (1024ull)
|
||||
#define MB (KB * KB)
|
||||
#define GB (KB * MB)
|
||||
|
|
|
|||
Loading…
Reference in a new issue