Skip to contentSkip to conversation

exfat: free new directory cluster if zeroing fails

PATCH Applied Yichong Chen 2 participants 2 messages Jul 28 exFAT file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 fs/exfat/dir.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/exfat/dir.c +7 -1
index 4fd4ec52b8c0..8d2ae6e33cbf 100644
@@ -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)
Signature · 1 line
2.51.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Yichong Chen

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.

Applied it to #dev.
Thanks!