Skip to contentSkip to conversation

fs: exfat: Fix corrupted error code handling in exfat_find_empty_entry()

PATCH Superseded Haotian Zhang 3 participants 5 messages Dec 3, 2025 – Dec 6, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: exfat: Fix corrupted error code handling in exfat_find_empty_entry()

exfat_find_empty_entry() stores the return value of exfat_alloc_cluster() in an unsigned int. When exfat_alloc_cluster() returns a negative errno, it is converted to a large positive value, which corrupts error propagation to the caller.

Change the type of ret to int so that negative errno values are preserved.

Fixes 5f2aa075070c ("exfat: add inode operations")
---
 fs/exfat/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/exfat/namei.c +2 -2
index f5f1c4e8a29f..f2a87ecd79f9 100644
@@ -304,8 +304,8 @@ static int exfat_find_empty_entry(struct inode *inode,
 		struct exfat_chain *p_dir, int num_entries,
 		struct exfat_entry_set_cache *es)
 {
-	int dentry;
-	unsigned int ret, last_clu;
+	int dentry, ret;
+	unsigned int last_clu;
 	loff_t size = 0;
 	struct exfat_chain clu;
 	struct super_block *sb = inode->i_sb;
Signature · 1 line
2.50.1.windows.1
maintainer
#1 lore raw

Hi, Haotian,

Quoted 5 lines · Haotian Zhang

exfat_find_empty_entry() stores the return value of exfat_alloc_cluster() in an unsigned int. When exfat_alloc_cluster() returns a negative errno, it is converted to a large positive value, which corrupts error propagation to the caller.

Have you ever encountered an actual error?
IMO, due to implicit type conversion, it should work as follows, so, I don't think there will be any real issues.

int -> unsigned int -> int

Anyway, it makes sense to modify the type of ret from unsigned int to int. What about changing the title and comment?

Thanks.
SJ

Quoted 25 lines

Change the type of ret to int so that negative errno values are preserved.

Fixes 5f2aa075070c ("exfat: add inode operations")
---
 fs/exfat/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/exfat/namei.c +2 -2
index f5f1c4e8a29f..f2a87ecd79f9 100644
@@ -304,8 +304,8 @@ static int exfat_find_empty_entry(struct inode *inode,
 		struct exfat_chain *p_dir, int num_entries,
 		struct exfat_entry_set_cache *es)
 {
-	int dentry;
-	unsigned int ret, last_clu;
+	int dentry, ret;
+	unsigned int last_clu;
 	loff_t size = 0;
 	struct exfat_chain clu;
 	struct super_block *sb = inode->i_sb;
#2 lore raw

PATCH v2 1/1 fs: exfat: improve error code handling in exfat_find_empty_entry()

In reply to Haotian Zhang

Change the type of 'ret' from unsigned int to int in exfat_find_empty_entry(). Although the implicit type conversion (int -> unsigned int -> int) does not cause actual bugs in practice, using int directly is more appropriate for storing error codes returned by exfat_alloc_cluster().

This improves code clarity and consistency with standard error handling practices.

---
 fs/exfat/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/exfat/namei.c +2 -2
index f5f1c4e8a29f..f2a87ecd79f9 100644
@@ -304,8 +304,8 @@ static int exfat_find_empty_entry(struct inode *inode,
 		struct exfat_chain *p_dir, int num_entries,
 		struct exfat_entry_set_cache *es)
 {
-	int dentry;
-	unsigned int ret, last_clu;
+	int dentry, ret;
+	unsigned int last_clu;
 	loff_t size = 0;
 	struct exfat_chain clu;
 	struct super_block *sb = inode->i_sb;
Signature · 1 line
2.50.1.windows.1
maintainer Reviewed-by on v2 1/1
#3 lore raw

Re: [PATCH v2] fs: exfat: improve error code handling in exfat_find_empty_entry()

Quoted 19 lines · Haotian Zhang

Change the type of 'ret' from unsigned int to int in exfat_find_empty_entry(). Although the implicit type conversion (int -> unsigned int -> int) does not cause actual bugs in practice, using int directly is more appropriate for storing error codes returned by exfat_alloc_cluster().

This improves code clarity and consistency with standard error handling practices.

---
 fs/exfat/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/exfat/namei.c +0 -0
index f5f1c4e8a29f..f2a87ecd79f9 100644

fs/exfat/namei.c static int exfat_find_empty_entry(struct inode *inode, · line 308

Quoted 7 lines
fs/exfat/namei.c +2 -2
@@ -304,8 +304,8 @@ static int exfat_find_empty_entry(struct inode *inode,
 		struct exfat_chain *p_dir, int num_entries,
 		struct exfat_entry_set_cache *es)
 {
-	int dentry;
-	unsigned int ret, last_clu;
+	int dentry, ret;
+	unsigned int last_clu;

The patch looks good to me:

Quoted 3 lines
fs/exfat/namei.c +0 -0
 	loff_t size = 0;
 	struct exfat_chain clu;
 	struct super_block *sb = inode->i_sb;
maintainer Applied
#4 lore raw

Re: [PATCH v2] fs: exfat: improve error code handling in exfat_find_empty_entry()

In reply to Haotian Zhang
Quoted 11 lines · Haotian Zhang

Change the type of 'ret' from unsigned int to int in exfat_find_empty_entry(). Although the implicit type conversion (int -> unsigned int -> int) does not cause actual bugs in practice, using int directly is more appropriate for storing error codes returned by exfat_alloc_cluster().

This improves code clarity and consistency with standard error handling practices.

Applied it to #dev.
Thanks!