Skip to contentSkip to conversation

ubifs: Adjustments for ubifs_purge_xattrs()

PATCH In review Markus Elfring 2 participants 5 messages Sep 26, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ubifs: Adjustments for ubifs_purge_xattrs()

From: Markus Elfring <[email protected]>
Date: Thu, 26 Sep 2024 11:38:22 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Call iput(xino) only once
Reduce kfree() calls

 fs/ubifs/xattr.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

--
2.46.1

#1 lore raw

PATCH 1/2 ubifs: Call iput(xino) only once in ubifs_purge_xattrs()

From: Markus Elfring <[email protected]>
Date: Thu, 26 Sep 2024 11:05:29 +0200

An iput(xino) call was immediately used after a return value check for a remove_xattr() call in this function implementation. Thus call such a function only once instead directly before the check.

This issue was transformed by using the Coccinelle software.

---
 fs/ubifs/xattr.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/ubifs/xattr.c +1 -3
index f734588b224a..7757959e9f09 100644
@@ -541,16 +541,14 @@ int ubifs_purge_xattrs(struct inode *host)
 
 		clear_nlink(xino);
 		err = remove_xattr(c, host, xino, &nm);
+		iput(xino);
 		if (err) {
 			kfree(pxent);
 			kfree(xent);
-			iput(xino);
 			ubifs_err(c, "cannot remove xattr, error %d", err);
 			goto out_err;
 		}
 
-		iput(xino);
-
 		kfree(pxent);
 		pxent = xent;
 		key_read(c, &xent->key, &key);

--
2.46.1

reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] ubifs: Call iput(xino) only once in ubifs_purge_xattrs()

Quoted 7 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Sep 2024 11:05:29 +0200

An iput(xino) call was immediately used after a return value check for a remove_xattr() call in this function implementation. Thus call such a function only once instead directly before the check.

Quoted 7 lines

This issue was transformed by using the Coccinelle software.

---
  fs/ubifs/xattr.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
Quoted 27 lines
fs/ubifs/xattr.c +1 -4
index f734588b224a..7757959e9f09 100644
@@ -541,16 +541,14 @@ int ubifs_purge_xattrs(struct inode *host)
 
  		clear_nlink(xino);
  		err = remove_xattr(c, host, xino, &nm);
+		iput(xino);
  		if (err) {
  			kfree(pxent);
  			kfree(xent);
-			iput(xino);
  			ubifs_err(c, "cannot remove xattr, error %d", err);
  			goto out_err;
  		}
 
-		iput(xino);
-
  		kfree(pxent);
  		pxent = xent;
  		key_read(c, &xent->key, &key);
--

2.46.1

.

#3 lore raw

PATCH 2/2 ubifs: Reduce kfree() calls in ubifs_purge_xattrs()

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Sep 2024 11:28:48 +0200

Move a pair of kfree() calls behind the label “out_err” so that two statements can be better reused at the end of this function implementation.

---
 fs/ubifs/xattr.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ubifs/xattr.c +2 -4
index 7757959e9f09..a514dc4dc535 100644
@@ -532,8 +532,6 @@ int ubifs_purge_xattrs(struct inode *host)
 			ubifs_err(c, "dead directory entry '%s', error %d",
 				  xent->name, err);
 			ubifs_ro_mode(c, err);
-			kfree(pxent);
-			kfree(xent);
 			goto out_err;
 		}
 
@@ -543,8 +541,6 @@ int ubifs_purge_xattrs(struct inode *host)
 		err = remove_xattr(c, host, xino, &nm);
 		iput(xino);
 		if (err) {
-			kfree(pxent);
-			kfree(xent);
 			ubifs_err(c, "cannot remove xattr, error %d", err);
 			goto out_err;
 		}
@@ -564,6 +560,8 @@ int ubifs_purge_xattrs(struct inode *host)
 	return 0;
 
 out_err:
+	kfree(pxent);
+	kfree(xent);
 	up_write(&ubifs_inode(host)->xattr_sem);
 	return err;
 }

--
2.46.1

reviewer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] ubifs: Reduce kfree() calls in ubifs_purge_xattrs()

Quoted 12 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 26 Sep 2024 11:28:48 +0200

Move a pair of kfree() calls behind the label “out_err” so that two statements can be better reused at the end of this function implementation.

---
  fs/ubifs/xattr.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
Quoted 36 lines
fs/ubifs/xattr.c +2 -5
index 7757959e9f09..a514dc4dc535 100644
@@ -532,8 +532,6 @@ int ubifs_purge_xattrs(struct inode *host)
  			ubifs_err(c, "dead directory entry '%s', error %d",
  				  xent->name, err);
  			ubifs_ro_mode(c, err);
-			kfree(pxent);
-			kfree(xent);
  			goto out_err;
  		}
 
@@ -543,8 +541,6 @@ int ubifs_purge_xattrs(struct inode *host)
  		err = remove_xattr(c, host, xino, &nm);
  		iput(xino);
  		if (err) {
-			kfree(pxent);
-			kfree(xent);
  			ubifs_err(c, "cannot remove xattr, error %d", err);
  			goto out_err;
  		}
@@ -564,6 +560,8 @@ int ubifs_purge_xattrs(struct inode *host)
  	return 0;
 
  out_err:
+	kfree(pxent);
+	kfree(xent);
  	up_write(&ubifs_inode(host)->xattr_sem);
  	return err;
  }
--

2.46.1

.