From: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com>
To: "zilin@seu.edu.cn" <zilin@seu.edu.cn>
Cc: "jianhao.xu@seu.edu.cn" <jianhao.xu@seu.edu.cn>,
"sougata@tuxera.com" <sougata@tuxera.com>,
"frank.li@vivo.com" <frank.li@vivo.com>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"slava@dubeyko.com" <slava@dubeyko.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"glaubitz@physik.fu-berlin.de" <glaubitz@physik.fu-berlin.de>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: RE: [PATCH] hfsplus: fix held lock freed on hfsplus_fill_super()
Date: Thu, 12 Mar 2026 17:36:38 +0000 [thread overview]
Message-ID: <77a8534a8b7922a1c0cf85f68fd8bda2bd7a61dc.camel@ibm.com> (raw)
In-Reply-To: <20260312021728.446944-1-zilin@seu.edu.cn>
On Thu, 2026-03-12 at 10:17 +0800, Zilin Guan wrote:
> On Wed, Mar 11, 2026 at 09:17:59PM +0000, Viacheslav Dubeyko wrote:
> > On Wed, 2026-03-11 at 19:43 +0800, Zilin Guan wrote:
> > > fs/hfsplus/super.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
> > > index 7229a8ae89f9..f396fee19ab8 100644
> > > --- a/fs/hfsplus/super.c
> > > +++ b/fs/hfsplus/super.c
> > > @@ -569,8 +569,10 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
> > > if (err)
> > > goto out_put_root;
> > > err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID, &str);
> > > - if (unlikely(err < 0))
> > > + if (unlikely(err < 0)) {
> > > + hfs_find_exit(&fd);
> > > goto out_put_root;
> > > + }
> > > if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
> > > hfs_find_exit(&fd);
> > > if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) {
> >
> > Makes sense.
> >
> > Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com>
> >
> > Frankly speaking, I think, potentially, we can introduce static inline function
> > for this code:
> >
> > 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))
> > goto out_put_root;
> > if (!hfs_brec_read(&fd, &entry, sizeof(entry))) {
> > hfs_find_exit(&fd);
> > if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) {
> > err = -EIO;
> > goto out_put_root;
> > }
> > inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
> > if (IS_ERR(inode)) {
> > err = PTR_ERR(inode);
> > goto out_put_root;
> > }
> > sbi->hidden_dir = inode;
> > } else
> > hfs_find_exit(&fd);
> >
> > Because, hiding this code into small function will provide opportunity to call
> > hfs_find_exit() in one place only (as for normal as for erroneous flow).
> >
> > What do you think?
> >
> > Thanks,
> > Slava.
>
> Thanks for the feedback, Slava.
>
> While I see the merit in refactoring this into a helper to centralize the
> cleanup, I’m concerned that doing so wouldn’t actually achieve a single
> hfs_find_exit() call without compromising the resource lifecycle.
>
> In the current logic, we need to call hfs_find_exit(&fd) as early as
> possible—specifically before entering hfsplus_iget(), which might involve
> further I/O or sleeping. If we were to use a single-exit goto pattern in a
> helper function, we would end up holding the search data and its
> associated buffers/locks longer than necessary. To maintain the current
> early-release behavior, we would still be forced to sprinkle multiple
> hfs_find_exit() calls across different branches within that helper anyway,
> which defeats the purpose of the refactoring.
>
> Given that this is a straightforward fix for a specific leak, I believe
> keeping the logic inline preserves the optimal resource release timing
> without adding unnecessary abstraction.
>
I mean really simple solution:
static inline
int hfsplus_get_hidden_dir_entry(struct super_block *sb,
hfsplus_cat_entry *entry)
{
int err = 0;
str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
str.name = HFSP_HIDDENDIR_NAME;
err = hfs_find_init(sbi->cat_tree, &fd);
if (err)
goto finish_logic;
err = hfsplus_cat_build_key(sb, fd.search_key, HFSPLUS_ROOT_CNID,
&str);
if (unlikely(err < 0))
goto free_fd;
err = hfs_brec_read(&fd, entry, sizeof(*entry));
free_fd:
hfs_find_exit(&fd);
finish_logic:
return err;
}
static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
{
<skipped>
err = hfsplus_get_hidden_dir_entry(sb, &entry);
if (err)
goto process_error;
if (entry.type != cpu_to_be16(HFSPLUS_FOLDER)) {
err = -EIO;
goto finish_logic;
}
inode = hfsplus_iget(sb, be32_to_cpu(entry.folder.id));
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
goto finish_logic;
}
sbi->hidden_dir = inode;
<skipped>
}
Does it makes sense to you?
Thanks,
Slava.
next prev parent reply other threads:[~2026-03-12 17:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 11:43 Zilin Guan
2026-03-11 21:17 ` Viacheslav Dubeyko
2026-03-12 2:13 ` Zilin Guan
2026-03-12 2:17 ` [PATCH] hfsplus: fix held lock freed on hfsplus_fill_super() Zilin Guan
2026-03-12 17:36 ` Viacheslav Dubeyko [this message]
2026-03-13 1:49 ` Zilin Guan
2026-03-13 18:38 ` Viacheslav Dubeyko
2026-03-14 3:36 ` Zilin Guan
2026-03-16 22:46 ` Viacheslav Dubeyko
2026-03-17 3:12 ` Zilin Guan
2026-03-17 19:36 ` Viacheslav Dubeyko
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=77a8534a8b7922a1c0cf85f68fd8bda2bd7a61dc.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=sougata@tuxera.com \
--cc=stable@vger.kernel.org \
--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®