From 0f5da3c539a221063e5b22583f59b4064529f2f2 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Mon, 12 Feb 2024 23:58:26 -0500 Subject: [PATCH] vfs: eliminte writes to NULL error code pointers --- fs/vfs.c | 8 ++++---- include/kernel/common.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/vfs.c b/fs/vfs.c index 459ef51..3a16111 100644 --- a/fs/vfs.c +++ b/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); diff --git a/include/kernel/common.h b/include/kernel/common.h index 092e87d..3bc9819 100644 --- a/include/kernel/common.h +++ b/include/kernel/common.h @@ -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)