[PATCH 27/32] fs: ext4: ext_barebox: handle ext_get_inode() errors

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Sep 5 02:55:52 PDT 2022


Static analyzer laments ext_get_inode, which can fail not having its
failure condition checked. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/ext4/ext_barebox.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/fs/ext4/ext_barebox.c b/fs/ext4/ext_barebox.c
index 8f318a49c008..6c7c9885c48f 100644
--- a/fs/ext4/ext_barebox.c
+++ b/fs/ext4/ext_barebox.c
@@ -127,8 +127,8 @@ static struct dentry *ext_lookup(struct inode *dir, struct dentry *dentry,
 
 	if (ino) {
 		inode = ext_get_inode(dir->i_sb, ino);
-
-		d_add(dentry, inode);
+		if (inode)
+			d_add(dentry, inode);
 	}
 
 	return NULL;
@@ -218,6 +218,8 @@ struct inode *ext_get_inode(struct super_block *sb, int ino)
 	node = container_of(inode, struct ext2fs_node, i);
 
 	ret = ext4fs_read_inode(fs->data, ino, &node->inode);
+	if (ret)
+		return NULL;
 
 	inode->i_ino = ino;
 	inode->i_mode = le16_to_cpu(node->inode.mode);
@@ -262,23 +264,27 @@ static int ext_probe(struct device_d *dev)
 
 	ret = fsdev_open_cdev(fsdev);
 	if (ret)
-		goto err_open;
+		goto err;
 
 	fs->cdev = fsdev->cdev;
 
 	ret = ext4fs_mount(fs);
 	if (ret)
-		goto err_mount;
+		goto err;
 
 	sb->s_op = &ext_ops;
 
 	inode = ext_get_inode(sb, 2);
+	if (!inode) {
+		ret = -EINVAL;
+		goto err;
+	}
+
 	sb->s_root = d_make_root(inode);
 
 	return 0;
 
-err_mount:
-err_open:
+err:
 	free(fs);
 
 	return ret;
-- 
2.30.2




More information about the barebox mailing list