The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] erofs: simplify z_erofs_gbuf_growsize()
@ 2026-08-23 14:23 Gao Xiang
  2026-08-24  1:03 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Gao Xiang @ 2026-08-23 14:23 UTC (permalink / raw)
  To: linux-erofs; +Cc: LKML, Gao Xiang

 - 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] erofs: simplify z_erofs_gbuf_growsize()
  2026-08-23 14:23 [PATCH] erofs: simplify z_erofs_gbuf_growsize() Gao Xiang
@ 2026-08-24  1:03 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2026-08-24  1:03 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs; +Cc: chao, LKML

On 8/23/26 22:23, Gao Xiang wrote:
>   - 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>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-24  1:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-23 14:23 [PATCH] erofs: simplify z_erofs_gbuf_growsize() Gao Xiang
2026-08-24  1:03 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox