linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: exfat: Fix corrupted error code handling in exfat_find_empty_entry()
@ 2025-12-03  7:08 ` Haotian Zhang
  2025-12-04 11:58   ` Sungjong Seo
  2025-12-05  1:59   ` [PATCH v2] fs: exfat: improve " Haotian Zhang
  0 siblings, 2 replies; 5+ messages in thread
From: Haotian Zhang @ 2025-12-03  7:08 UTC (permalink / raw)
  To: linkinjeon, sj1557.seo, yuezhang.mo
  Cc: linux-fsdevel, linux-kernel, 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.

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

Fixes: 5f2aa075070c ("exfat: add inode operations")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 fs/exfat/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index f5f1c4e8a29f..f2a87ecd79f9 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -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.50.1.windows.1


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

* Re: [PATCH] fs: exfat: Fix corrupted error code handling in exfat_find_empty_entry()
  2025-12-03  7:08 ` [PATCH] fs: exfat: Fix corrupted error code handling in exfat_find_empty_entry() Haotian Zhang
@ 2025-12-04 11:58   ` Sungjong Seo
  2025-12-05  1:59   ` [PATCH v2] fs: exfat: improve " Haotian Zhang
  1 sibling, 0 replies; 5+ messages in thread
From: Sungjong Seo @ 2025-12-04 11:58 UTC (permalink / raw)
  To: Haotian Zhang, linkinjeon, yuezhang.mo; +Cc: linux-fsdevel, linux-kernel

Hi, Haotian,

On 25. 12. 3. 16:08, Haotian Zhang wrote:
> 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

> 
> Change the type of ret to int so that negative errno
> values are preserved.
> 
> Fixes: 5f2aa075070c ("exfat: add inode operations")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
>  fs/exfat/namei.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
> index f5f1c4e8a29f..f2a87ecd79f9 100644
> --- a/fs/exfat/namei.c
> +++ b/fs/exfat/namei.c
> @@ -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;


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

* [PATCH v2] fs: exfat: improve error code handling in exfat_find_empty_entry()
  2025-12-03  7:08 ` [PATCH] fs: exfat: Fix corrupted error code handling in exfat_find_empty_entry() Haotian Zhang
  2025-12-04 11:58   ` Sungjong Seo
@ 2025-12-05  1:59   ` Haotian Zhang
  2025-12-05  6:05     ` Sungjong Seo
  2025-12-06 10:44     ` Namjae Jeon
  1 sibling, 2 replies; 5+ messages in thread
From: Haotian Zhang @ 2025-12-05  1:59 UTC (permalink / raw)
  To: linkinjeon, sj1557.seo, yuezhang.mo
  Cc: linux-fsdevel, linux-kernel, 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.

Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 fs/exfat/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index f5f1c4e8a29f..f2a87ecd79f9 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -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.50.1.windows.1


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

* Re: [PATCH v2] fs: exfat: improve error code handling in exfat_find_empty_entry()
  2025-12-05  1:59   ` [PATCH v2] fs: exfat: improve " Haotian Zhang
@ 2025-12-05  6:05     ` Sungjong Seo
  2025-12-06 10:44     ` Namjae Jeon
  1 sibling, 0 replies; 5+ messages in thread
From: Sungjong Seo @ 2025-12-05  6:05 UTC (permalink / raw)
  To: Haotian Zhang, linkinjeon, yuezhang.mo; +Cc: linux-fsdevel, linux-kernel



On 25. 12. 5. 10:59, Haotian Zhang wrote:
> 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.
> 
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
>  fs/exfat/namei.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
> index f5f1c4e8a29f..f2a87ecd79f9 100644
> --- a/fs/exfat/namei.c
> +++ b/fs/exfat/namei.c
> @@ -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:

Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>

>  	loff_t size = 0;
>  	struct exfat_chain clu;
>  	struct super_block *sb = inode->i_sb;


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

* Re: [PATCH v2] fs: exfat: improve error code handling in exfat_find_empty_entry()
  2025-12-05  1:59   ` [PATCH v2] fs: exfat: improve " Haotian Zhang
  2025-12-05  6:05     ` Sungjong Seo
@ 2025-12-06 10:44     ` Namjae Jeon
  1 sibling, 0 replies; 5+ messages in thread
From: Namjae Jeon @ 2025-12-06 10:44 UTC (permalink / raw)
  To: Haotian Zhang; +Cc: sj1557.seo, yuezhang.mo, linux-fsdevel, linux-kernel

On Fri, Dec 5, 2025 at 10:59 AM Haotian Zhang <vulab@iscas.ac.cn> wrote:
>
> 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.
>
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Applied it to #dev.
Thanks!

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

end of thread, other threads:[~2025-12-06 10:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20251203070828epcas1p219623b1095d4f34a5af5adada269b14f@epcas1p2.samsung.com>
2025-12-03  7:08 ` [PATCH] fs: exfat: Fix corrupted error code handling in exfat_find_empty_entry() Haotian Zhang
2025-12-04 11:58   ` Sungjong Seo
2025-12-05  1:59   ` [PATCH v2] fs: exfat: improve " Haotian Zhang
2025-12-05  6:05     ` Sungjong Seo
2025-12-06 10:44     ` Namjae Jeon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).