Skip to contentSkip to conversation

exfat: Fix 2 issues found by static code analysis

PATCH Applied Philipp Hahn 3 participants 9 messages Mar 3 – Mar 5

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

PATCH 1/1 exfat: Fix 2 issues found by static code analysis

Hello,

I'm going through our list of issues found by static code analysis using Klocwork. It found two issues worth fixing:

1. The 1st seems to be a real bug due to C's integer coercion, where the inverted bitmask s_blocksize gets 0 extended.
2. The 2nd might just be a dead variable assignment, but maybe num_clusters is supposed to be returned or stored elsewhere?

I hope my alaysis is correct. If yes, please apply. Thank you.

Philipp Hahn (2):
exfat: Fix bitwise operation having different size
exfat: Drop dead assignment of num_clusters

 fs/exfat/dir.c   | 2 +-
 fs/exfat/inode.c | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 exfat: Fix bitwise operation having different size

cpos has type loff_t (long long), while s_blocksize has type u32. The inversion wil happen on u32, the coercion to s64 happens afterwards and will do 0-left-paddding, resulting in the upper bits getting masked out.

Cast s_blocksize to loff_t before negating it.

Found by static code analysis using Klocwork.

---
 fs/exfat/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/exfat/dir.c +1 -1
index 3a4853693d8bf..e710dd196e2f0 100644
@@ -249,7 +249,7 @@ static int exfat_iterate(struct file *file, struct dir_context *ctx)
 		 */
 		if (err == -EIO) {
 			cpos += 1 << (sb->s_blocksize_bits);
-			cpos &= ~(sb->s_blocksize - 1);
+			cpos &= ~(loff_t)(sb->s_blocksize - 1);
 		}
 
 		err = -EIO;
Signature · 1 line
2.43.0
#2 lore raw

PATCH 1/1 exfat: Drop dead assignment of num_clusters

In reply to Philipp Hahn

num_clusters is not used naywhere afterwards. Remove assignment.

Found by static code analysis using Klocwork.

---
 fs/exfat/inode.c | 1 -
 1 file changed, 1 deletion(-)
fs/exfat/inode.c +0 -1
index 2fb2d2d5d503a..d17ef2f9a7e2b 100644
@@ -213,7 +213,6 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
 					return -EIO;
 		}
 
-		num_clusters += num_to_be_allocated;
 		*clu = new_clu.dir;
 
 		inode->i_blocks += EXFAT_CLU_TO_B(num_to_be_allocated, sbi) >> 9;
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH] exfat: Drop dead assignment of num_clusters

Quoted 1 line

num_clusters is not used naywhere afterwards. …

anywhere?

Regards,
Markus

#4 lore raw

Re: [PATCH] exfat: Drop dead assignment of num_clusters

Hello Markus,

Am Tue, Mar 03, 2026 at 12:50:07PM +0100 schrieb Markus Elfring:

Quoted 3 lines
Quoted 1 line

num_clusters is not used naywhere afterwards. …

anywhere?

Yes, obviously. Thank you for spotting this.

Philipp

#5 lore raw
In reply to Philipp Hahn

By the way:
It can be helpful to number prefixes according to message subjects in patch series.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc2#n711

Quoted 1 line

I'm going through our list of issues found by static code analysis using Klocwork.

Does this tool point any more implementation details out for further development considerations (with other software components)?

Regards,
Markus

#6 lore raw

Hello Markus,

Am Wed, Mar 04, 2026 at 09:40:37AM +0100 schrieb Markus Elfring:

Quoted 3 lines

By the way:
It can be helpful to number prefixes according to message subjects in patch series.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc2#n711

Yes, thank you for the reminder.

Quoted 4 lines
Quoted 1 line

I'm going through our list of issues found by static code analysis using Klocwork.

Does this tool point any more implementation details out for further development considerations (with other software components)?

This was a run on our internal version of exfat, which matches 'github.com/namjaejeon/linux-exfat-oot/for-kernel-version-from-4.1.0'.

Klocwork found no other issues worth fixing in that version.

If my time permits I will run it again on latest 'linux-7.0-rc` respective 'master' to see if anything "new" crept in.

I'll also report any other findings outside of exfat when I find them.

Philipp

#7 lore raw
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I'm going through our list of issues found by static code analysis using Klocwork.

Does this tool point any more implementation details out for further development considerations (with other software components)?

This was a run on our internal version of exfat, which matches 'github.com/namjaejeon/linux-exfat-oot/for-kernel-version-from-4.1.0'.

Thanks for such background information.

Quoted 2 lines

If my time permits I will run it again on latest 'linux-7.0-rc` respective 'master' to see if anything "new" crept in.

It is probably nicer to repeat source code analyses on more recent software revisions occasionally.

Quoted 1 line

I'll also report any other findings outside of exfat when I find them.

I became curious on the aspect on how many development resources you may invest then.

Regards,
Markus

maintainer Applied
#8 lore raw
In reply to Philipp Hahn
Quoted 11 lines · Philipp Hahn

Hello,

I'm going through our list of issues found by static code analysis using Klocwork. It found two issues worth fixing:

1. The 1st seems to be a real bug due to C's integer coercion, where the inverted bitmask s_blocksize gets 0 extended.
2. The 2nd might just be a dead variable assignment, but maybe num_clusters is supposed to be returned or stored elsewhere?

Quoted 5 lines

I hope my alaysis is correct. If yes, please apply. Thank you.

Philipp Hahn (2):
exfat: Fix bitwise operation having different size
exfat: Drop dead assignment of num_clusters

Applied them to #dev.
Thanks!