[PATCH RESEND] ufs: Fix exception handling in ufs_fill_super()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 22 Mar 2023 21:50:45 +0100

The label “failed” was used to jump to another pointer check despite of
the detail in the implementation of the function “ufs_fill_super”
that it was determined already that a corresponding variable contained
a null pointer because of a failed call of the function “kzalloc”
or “ubh_bread_uspi”.

1. Thus use two additional labels.

2. Delete a redundant check.

3. Omit extra assignments (for the variables “uspi” and “ubh”)
   at the beginning which became unnecessary with this refactoring.


This issue was detected by using the Coccinelle software.

Fixes: f99d49adf527 ("[PATCH] kfree cleanup: fs")
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
 fs/ufs/super.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index 23377c1baed9..017653c36080 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -789,8 +789,6 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
 	unsigned maxsymlen;
 	int ret = -EINVAL;

-	uspi = NULL;
-	ubh = NULL;
 	flags = 0;

 	UFSD("ENTER\n");
@@ -821,7 +819,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
 	ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
 	if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
 		pr_err("wrong mount options\n");
-		goto failed;
+		goto free_sbi;
 	}
 	if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
 		if (!silent)
@@ -836,7 +834,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
 	uspi = kzalloc(sizeof(struct ufs_sb_private_info), GFP_KERNEL);
 	sbi->s_uspi = uspi;
 	if (!uspi)
-		goto failed;
+		goto free_sbi;
 	uspi->s_dirblksize = UFS_SECTOR_SIZE;
 	super_block_offset=UFS_SBLOCK;

@@ -984,13 +982,13 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
 	default:
 		if (!silent)
 			pr_err("unknown ufstype\n");
-		goto failed;
+		goto free_uspi;
 	}

 again:
 	if (!sb_set_blocksize(sb, block_size)) {
 		pr_err("failed to set blocksize\n");
-		goto failed;
+		goto free_uspi;
 	}

 	/*
@@ -1000,7 +998,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
 	ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);

 	if (!ubh)
-            goto failed;
+            goto free_uspi;

 	usb1 = ubh_get_usb_first(uspi);
 	usb2 = ubh_get_usb_second(uspi);
@@ -1291,9 +1289,10 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
 	return 0;

 failed:
-	if (ubh)
-		ubh_brelse_uspi (uspi);
-	kfree (uspi);
+	ubh_brelse_uspi(uspi);
+free_uspi:
+	kfree(uspi);
+free_sbi:
 	kfree(sbi);
 	sb->s_fs_info = NULL;
 	UFSD("EXIT (FAILED)\n");
--
2.40.0






[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux