From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org
Cc: LKML <linux-kernel@vger.kernel.org>, Gao Xiang <xiang@kernel.org>
Subject: [PATCH] erofs: simplify z_erofs_gbuf_growsize()
Date: Sun, 23 Aug 2026 22:23:05 +0800 [thread overview]
Message-ID: <20260823142306.42533-1-xiang@kernel.org> (raw)
- Use guard(mutex)() to manage gbuf_resize_mutex;
- Nullify tmp_pages after successful allocation, so that the error
path becomes clearer.
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
fs/erofs/zutil.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/fs/erofs/zutil.c b/fs/erofs/zutil.c
index 6b9bfa2ef3b6..960cfe86eeb6 100644
--- a/fs/erofs/zutil.c
+++ b/fs/erofs/zutil.c
@@ -70,12 +70,10 @@ int z_erofs_gbuf_growsize(unsigned int nrpages)
void *ptr, *old_ptr;
int last, i, j;
- mutex_lock(&gbuf_resize_mutex);
+ guard(mutex)(&gbuf_resize_mutex);
/* avoid shrinking gbufs, since no idea how many fses rely on */
- if (nrpages <= z_erofs_gbuf_nrpages) {
- mutex_unlock(&gbuf_resize_mutex);
+ if (nrpages <= z_erofs_gbuf_nrpages)
return 0;
- }
for (i = 0; i < z_erofs_gbuf_count; ++i) {
gbuf = &z_erofs_gbufpool[i];
@@ -89,8 +87,7 @@ int z_erofs_gbuf_growsize(unsigned int nrpages)
tmp_pages[j] = gbuf->pages[j];
do {
last = j;
- j = alloc_pages_bulk(GFP_KERNEL, nrpages,
- tmp_pages);
+ j = alloc_pages_bulk(GFP_KERNEL, nrpages, tmp_pages);
if (last == j)
goto out;
} while (j != nrpages);
@@ -101,24 +98,23 @@ int z_erofs_gbuf_growsize(unsigned int nrpages)
spin_lock(&gbuf->lock);
kfree(gbuf->pages);
- gbuf->pages = tmp_pages;
old_ptr = gbuf->ptr;
+ gbuf->pages = tmp_pages;
gbuf->ptr = ptr;
gbuf->nrpages = nrpages;
spin_unlock(&gbuf->lock);
- if (old_ptr)
- vunmap(old_ptr);
+ vunmap(old_ptr);
+ tmp_pages = NULL;
}
z_erofs_gbuf_nrpages = nrpages;
out:
- if (i < z_erofs_gbuf_count && tmp_pages) {
+ if (unlikely(tmp_pages)) {
for (j = 0; j < nrpages; ++j)
if (tmp_pages[j] && (j >= gbuf->nrpages ||
tmp_pages[j] != gbuf->pages[j]))
__free_page(tmp_pages[j]);
kfree(tmp_pages);
}
- mutex_unlock(&gbuf_resize_mutex);
return i < z_erofs_gbuf_count ? -ENOMEM : 0;
}
--
2.47.3
next reply other threads:[~2026-08-23 14:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-23 14:23 Gao Xiang [this message]
2026-08-24 1:03 ` [PATCH] erofs: simplify z_erofs_gbuf_growsize() Chao Yu
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=20260823142306.42533-1-xiang@kernel.org \
--to=xiang@kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.