mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxwell Doose <m32285159@gmail.com>
To: Christian Brauner <brauner@kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>
Cc: Maxwell Doose <m32285159@gmail.com>,
	Jeff Layton <jlayton@kernel.org>, Jan Kara <jack@suse.cz>,
	Kees Cook <kees@kernel.org>, Mateusz Guzik <mjguzik@gmail.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] fs: efs: namei: Use __free() over manual resource management
Date: Sat,  6 Jun 2026 13:18:58 -0500	[thread overview]
Message-ID: <20260606181905.241793-1-m32285159@gmail.com> (raw)

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.

Signed-off-by: Maxwell Doose <m32285159@gmail.com>
---
 fs/efs/namei.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/fs/efs/namei.c b/fs/efs/namei.c
index 38961ee1d1af..ce7794d55e47 100644
--- a/fs/efs/namei.c
+++ b/fs/efs/namei.c
@@ -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;
 }
-- 
2.54.0


             reply	other threads:[~2026-06-06 18:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-06 18:18 Maxwell Doose [this message]
2026-06-07  2:58 ` Maxwell Doose
2026-06-09  9:58   ` Jan Kara
2026-06-09 15:15     ` Maxwell Doose

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260606181905.241793-1-m32285159@gmail.com \
    --to=m32285159@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjguzik@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®