mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "zilin@seu.edu.cn" <zilin@seu.edu.cn>
Cc: "slava@dubeyko.com" <slava@dubeyko.com>,
	"frank.li@vivo.com" <frank.li@vivo.com>,
	"glaubitz@physik.fu-berlin.de" <glaubitz@physik.fu-berlin.de>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"jianhao.xu@seu.edu.cn" <jianhao.xu@seu.edu.cn>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re: [PATCH v4 2/2] hfsplus: extract hidden directory search into a helper function
Date: Tue, 24 Mar 2026 00:17:41 +0000	[thread overview]
Message-ID: <da6150e9de2574a88190935faa10b0d19fdb4db7.camel@ibm.com> (raw)
In-Reply-To: <20260321080130.1292216-3-zilin@seu.edu.cn>

On Sat, 2026-03-21 at 16:01 +0800, Zilin Guan wrote:
> In hfsplus_fill_super(), the process of looking up the hidden directory
> involves initializing a catalog search, building a search key, reading
> the b-tree record, and releasing the search data.
> 
> Currently, this logic is open-coded directly within the main superblock
> initialization routine. This makes hfsplus_fill_super() quite lengthy
> and its error handling paths less straightforward.
> 
> Extract the hidden directory search sequence into a new helper function,
> hfsplus_get_hidden_dir_entry(). This improves overall code readability,
> cleanly encapsulates the hfs_find_data lifecycle, and simplifies the
> error exits in hfsplus_fill_super().
> 
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
> ---
>  fs/hfsplus/super.c | 44 ++++++++++++++++++++++++++++++++------------
>  1 file changed, 32 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
> index f396fee19ab8..5ea2d1852591 100644
> --- a/fs/hfsplus/super.c
> +++ b/fs/hfsplus/super.c
> @@ -424,12 +424,35 @@ void hfsplus_prepare_volume_header_for_commit(struct hfsplus_vh *vhdr)
>  	vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
>  }
>  
> +static inline int hfsplus_get_hidden_dir_entry(struct super_block *sb,
> +					       const struct qstr *str,
> +					       hfsplus_cat_entry *entry)
> +{
> +	struct hfs_find_data fd;
> +	int err;
> +
> +	err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
> +	if (unlikely(err))
> +		return err;
> +
> +	err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, str);
> +	if (unlikely(err))
> +		goto free_fd;
> +
> +	err = hfs_brec_read(&fd, entry, sizeof(*entry));
> +	if (err)
> +		err = -ENOENT;
> +
> +free_fd:
> +	hfs_find_exit(&fd);
> +	return err;
> +}
> +
>  static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
>  {
>  	struct hfsplus_vh *vhdr;
>  	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
>  	hfsplus_cat_entry entry;
> -	struct hfs_find_data fd;
>  	struct inode *root, *inode;
>  	struct qstr str;
>  	struct nls_table *nls;
> @@ -565,16 +588,14 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
>  
>  	str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
>  	str.name = HFSP_HIDDENDIR_NAME;
> -	err = hfs_find_init(sbi->cat_tree, &fd);
> -	if (err)
> -		goto out_put_root;
> -	err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
> -	if (unlikely(err < 0)) {
> -		hfs_find_exit(&fd);
> +	err = hfsplus_get_hidden_dir_entry(sb, &str, &entry);
> +	if (err == -ENOENT) {
> +		/*
> +		 * Hidden directory is absent or it cannot be read.
> +		 */
> +	} else if (unlikely(err)) {
>  		goto out_put_root;
> -	}
> -	if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
> -		hfs_find_exit(&fd);
> +	} else {
>  		if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) {
>  			err = -EIO;
>  			goto out_put_root;
> @@ -585,8 +606,7 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
>  			goto out_put_root;
>  		}
>  		sbi->hidden_dir = inode;
> -	} else
> -		hfs_find_exit(&fd);
> +	}
>  
>  	if (!sb_rdonly(sb)) {
>  		/*

Looks good.

Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com>

The xfstests didn't revealed any new issues.

Tested-by: Viacheslav Dubeyko <slava@dubeyko.com>

Thanks,
Slava.

      reply	other threads:[~2026-03-24  0:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-21  8:01 [PATCH v4 0/2] hfsplus: fix lock leak and refactor hidden dir search Zilin Guan
2026-03-21  8:01 ` [PATCH v4 1/2] hfsplus: fix held lock freed on hfsplus_fill_super() Zilin Guan
2026-03-24  0:17   ` Viacheslav Dubeyko
2026-03-21  8:01 ` [PATCH v4 2/2] hfsplus: extract hidden directory search into a helper function Zilin Guan
2026-03-24  0:17   ` Viacheslav Dubeyko [this message]

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=da6150e9de2574a88190935faa10b0d19fdb4db7.camel@ibm.com \
    --to=slava.dubeyko@ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=jianhao.xu@seu.edu.cn \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=slava@dubeyko.com \
    --cc=zilin@seu.edu.cn \
    /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®