From ce12a39bed483008683438962b3a605374e6f803 Mon Sep 17 00:00:00 2001 From: Yichong Chen Date: Tue, 28 Jul 2026 12:29:23 +0800 Subject: [PATCH] exfat: free new directory cluster if zeroing fails exfat_alloc_new_dir() allocates a cluster for a new directory before zeroing it. If exfat_zeroed_cluster() fails, the function returns the error but leaves the allocated cluster in use. Free the newly allocated cluster before returning the zeroing error. Signed-off-by: Yichong Chen Signed-off-by: Namjae Jeon --- fs/exfat/dir.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 4fd4ec52b8c0..8d2ae6e33cbf 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -299,7 +299,13 @@ int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu) if (ret) return ret; - return exfat_zeroed_cluster(inode, clu->dir); + ret = exfat_zeroed_cluster(inode, clu->dir); + if (ret) { + exfat_free_cluster(inode, clu); + return ret; + } + + return 0; } int exfat_calc_num_entries(struct exfat_uni_name *p_uniname)