All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ext4: simplify 32bit calculation of lblk
@ 2023-04-06  6:44 wuchi
  0 siblings, 0 replies; only message in thread
From: wuchi @ 2023-04-06  6:44 UTC (permalink / raw)
  To: tytso, adilger.kernel, ojaswin, ritesh.list, David.Laight
  Cc: linux-ext4, linux-kernel

commit <ad4fb9cafe100a> (ext4: fix 32bit overflow in ext4_ext_find_goal())
uses value compare to fix 32bit overflow. The resion is that
(block - ext_block) will overflow and cast u32 to u64.
eg: -1(u32) cast to 0xffffffff(u64) which wasn't correct here.
Remove the brackets will solve it simply.

Suggested-by: David Laight <David.Laight@aculab.com>
Signed-off-by: wuchi <wuchi.zero@gmail.com>
---
 fs/ext4/extents.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 3559ea6b0781..254d380ff46e 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -237,10 +237,7 @@ static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode,
 			ext4_fsblk_t ext_pblk = ext4_ext_pblock(ex);
 			ext4_lblk_t ext_block = le32_to_cpu(ex->ee_block);
 
-			if (block > ext_block)
-				return ext_pblk + (block - ext_block);
-			else
-				return ext_pblk - (ext_block - block);
+			return ext_pblk + block - ext_block;
 		}
 
 		/* it looks like index is empty;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-06  6:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06  6:44 [PATCH v2] ext4: simplify 32bit calculation of lblk wuchi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.