diff options
author | Andrew Goodbody <andrew.goodbody@linaro.org> | 2025-10-03 11:42:52 +0100 |
---|---|---|
committer | Heiko Schocher <hs@nabladev.com> | 2025-10-08 11:36:05 +0200 |
commit | 0cab29ff467e297064a9fc30200347bda06ee0c4 (patch) | |
tree | 39106b56ae5b6e1da79d9606602086483aa01763 | |
parent | 51615eb4f7bcd3367aecdeaea3638058ef5407f3 (diff) |
fs: ubifs: Fix and rework error handling in ubifs_finddir
Add a null check for 'file' before dereferencing it and also rework the
error handling to be a bit more sane.
This issue was found by Smatch.
Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
-rw-r--r-- | fs/ubifs/ubifs.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index 398b076d783..40bad0e7da7 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -420,7 +420,6 @@ out: static int ubifs_finddir(struct super_block *sb, char *dirname, unsigned long root_inum, unsigned long *inum) { - int err; struct qstr nm; union ubifs_key key; struct ubifs_dent_node *dent; @@ -435,8 +434,8 @@ static int ubifs_finddir(struct super_block *sb, char *dirname, dir = kzalloc(sizeof(struct inode), 0); if (!file || !dentry || !dir) { printf("%s: Error, no memory for malloc!\n", __func__); - err = -ENOMEM; - goto out; + ret = -ENOMEM; + goto out_free; } dir->i_sb = sb; @@ -453,7 +452,7 @@ static int ubifs_finddir(struct super_block *sb, char *dirname, nm.name = NULL; dent = ubifs_tnc_next_ent(c, &key, &nm); if (IS_ERR(dent)) { - err = PTR_ERR(dent); + ret = PTR_ERR(dent); goto out; } @@ -481,7 +480,7 @@ static int ubifs_finddir(struct super_block *sb, char *dirname, nm.name = (char *)dent->name; dent = ubifs_tnc_next_ent(c, &key, &nm); if (IS_ERR(dent)) { - err = PTR_ERR(dent); + ret = PTR_ERR(dent); goto out; } @@ -492,11 +491,12 @@ static int ubifs_finddir(struct super_block *sb, char *dirname, } out: - if (err != -ENOENT) - dbg_gen("cannot find next direntry, error %d", err); + if (ret < 0 && ret != -ENOENT) + dbg_gen("cannot find next direntry, error %d", ret); out_free: - kfree(file->private_data); + if (file) + kfree(file->private_data); free(file); free(dentry); free(dir); |