Skip to contentSkip to conversation

fs: efs: namei: Use __free() over manual resource management

PATCH In review Maxwell Doose 2 participants 4 messages Jun 6 – Jun 9

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: efs: namei: Use __free() over manual resource management

Define a __free() for brelse() called brelease.

The current code uses manual management of the file buffer heads. Remove manual brelse statements and initialize bh with __free(brelease) which removes and modernizes code.

---
 fs/efs/namei.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/efs/namei.c +4 -6
index 38961ee1d1af..ce7794d55e47 100644
@@ -8,15 +8,15 @@
  */
 
 #include <linux/buffer_head.h>
+#include <linux/cleanup.h>
 #include <linux/string.h>
 #include <linux/exportfs.h>
 #include "efs.h"
 
+DEFINE_FREE(brelease, struct buffer_head *, if (_T) brelse(_T))
 
 static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 {
-	struct buffer_head *bh;
-
 	int			slot, namelen;
 	char			*nameptr;
 	struct efs_dir		*dirblock;
@@ -30,7 +30,8 @@ static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 
 	for(block = 0; block < inode->i_blocks; block++) {
 
-		bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
+		struct buffer_head *bh __free(brelease) = sb_bread(inode->i_sb,
+								   bfs_bmap(inode, block));
 		if (!bh) {
 			pr_err("%s(): failed to read dir block %d\n",
 			       __func__, block);
@@ -41,7 +42,6 @@ static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 
 		if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
 			pr_err("%s(): invalid directory block\n", __func__);
-			brelse(bh);
 			return 0;
 		}
 
@@ -53,11 +53,9 @@ static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 
 			if ((namelen == len) && (!memcmp(name, nameptr, len))) {
 				inodenum = be32_to_cpu(dirslot->inode);
-				brelse(bh);
 				return inodenum;
 			}
 		}
-		brelse(bh);
 	}
 	return 0;
 }
Signature · 1 line
2.54.0
#1 lore raw
Quoted 35 lines · Maxwell Doose

Define a __free() for brelse() called brelease.

The current code uses manual management of the file buffer heads. Remove manual brelse statements and initialize bh with __free(brelease) which removes and modernizes code.

---
 fs/efs/namei.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/efs/namei.c +2 -2
index 38961ee1d1af..ce7794d55e47 100644
@@ -8,15 +8,15 @@
  */
 
 #include <linux/buffer_head.h>
+#include <linux/cleanup.h>
 #include <linux/string.h>
 #include <linux/exportfs.h>
 #include "efs.h"
 
+DEFINE_FREE(brelease, struct buffer_head *, if (_T) brelse(_T))
 
 static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 {
-       struct buffer_head *bh;
-
        int                     slot, namelen;
        char                    *nameptr;
        struct efs_dir          *dirblock;

fs/efs/namei.c static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len) · line 34

Quoted 6 lines
fs/efs/namei.c +2 -1
@@ -30,7 +30,8 @@ static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 
        for(block = 0; block < inode->i_blocks; block++) {
 
-               bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
+               struct buffer_head *bh __free(brelease) = sb_bread(inode->i_sb,
+                                                                  bfs_bmap(inode, block));

Made a mistake here while moving :( should be efs_bmap(). Can send a v2 if preferred.

Signature · 2 lines
best regards,
max
Quoted 26 lines
fs/efs/namei.c +0 -4
                if (!bh) {
                        pr_err("%s(): failed to read dir block %d\n",
                               __func__, block);
@@ -41,7 +42,6 @@ static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 
                if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
                        pr_err("%s(): invalid directory block\n", __func__);
-                       brelse(bh);
                        return 0;
                }
 
@@ -53,11 +53,9 @@ static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 
                        if ((namelen == len) && (!memcmp(name, nameptr, len))) {
                                inodenum = be32_to_cpu(dirslot->inode);
-                               brelse(bh);
                                return inodenum;
                        }
                }
-               brelse(bh);
        }
        return 0;
 }
--

2.54.0

#2 lore raw
Quoted 37 lines · Maxwell Doose
Quoted 36 lines · Maxwell Doose

Define a __free() for brelse() called brelease.

The current code uses manual management of the file buffer heads. Remove manual brelse statements and initialize bh with __free(brelease) which removes and modernizes code.

---
 fs/efs/namei.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/efs/namei.c +2 -2
index 38961ee1d1af..ce7794d55e47 100644
@@ -8,15 +8,15 @@
  */
 
 #include <linux/buffer_head.h>
+#include <linux/cleanup.h>
 #include <linux/string.h>
 #include <linux/exportfs.h>
 #include "efs.h"
 
+DEFINE_FREE(brelease, struct buffer_head *, if (_T) brelse(_T))
 
 static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 {
-       struct buffer_head *bh;
-
        int                     slot, namelen;
        char                    *nameptr;
        struct efs_dir          *dirblock;
@@ -30,7 +30,8 @@ static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 
Quoted 8 lines

fs/efs/namei.c static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len) · line 34

Quoted 5 lines
fs/efs/namei.c +2 -1
        for(block = 0; block < inode->i_blocks; block++) {
 
-               bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
+               struct buffer_head *bh __free(brelease) = sb_bread(inode->i_sb,
+                                                                  bfs_bmap(inode, block));

Made a mistake here while moving :( should be efs_bmap(). Can send a v2 if preferred.

Well, that happens but that also shows you didn't even try to compile the thing before sending the patch. This is not how the kernel development should work, let alone maintenance... Please test your changes before sending them.

Separate thing is that I don't think changes like this to a dead filesystem as EFS are really useful. So as others have suggested the most useful action you could do for EFS would be to add deprecation notice on kconfig and print deprecation message on mount (like we did with other filesystems we removed). Set the removal date to the end of 2026 and see if some user pops up. Because I suspect nobody used this code for years.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#3 lore raw
Quoted 47 lines · On Tue, 9 Jun 2026 11:58:40 +0200 Jan Kara <[email protected]> wrote:
Quoted 37 lines · Maxwell Doose
Quoted 36 lines · Maxwell Doose

Define a __free() for brelse() called brelease.

The current code uses manual management of the file buffer heads. Remove manual brelse statements and initialize bh with __free(brelease) which removes and modernizes code.

---
 fs/efs/namei.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/efs/namei.c +2 -2
index 38961ee1d1af..ce7794d55e47 100644
@@ -8,15 +8,15 @@
  */
 
 #include <linux/buffer_head.h>
+#include <linux/cleanup.h>
 #include <linux/string.h>
 #include <linux/exportfs.h>
 #include "efs.h"
 
+DEFINE_FREE(brelease, struct buffer_head *, if (_T) brelse(_T))
 
 static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 {
-       struct buffer_head *bh;
-
        int                     slot, namelen;
        char                    *nameptr;
        struct efs_dir          *dirblock;
@@ -30,7 +30,8 @@ static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
 
Quoted 8 lines

fs/efs/namei.c static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len) · line 34

Quoted 5 lines
fs/efs/namei.c +2 -1
        for(block = 0; block < inode->i_blocks; block++) {
 
-               bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
+               struct buffer_head *bh __free(brelease) = sb_bread(inode->i_sb,
+                                                                  bfs_bmap(inode, block));  

Made a mistake here while moving :( should be efs_bmap(). Can send a v2 if preferred.

Quoted 5 lines

Well, that happens but that also shows you didn't even try to compile the thing before sending the patch. This is not how the kernel development should work, let alone maintenance... Please test your changes before sending them.

I did and added the fix for it but I think I forgot to amend my commit :(

Quoted 8 lines

Separate thing is that I don't think changes like this to a dead filesystem as EFS are really useful. So as others have suggested the most useful action you could do for EFS would be to add deprecation notice on kconfig and print deprecation message on mount (like we did with other filesystems we removed). Set the removal date to the end of 2026 and see if some user pops up. Because I suspect nobody used this code for years.

Alright then. If that's the consensus then I can do that.

Signature · 2 lines
best regards,
max