diff mbox series

fs/ext4/inode-test: Fix inode test on 32 bit platforms.

Message ID 20191127185524.40220-1-yzaikin@google.com (mailing list archive)
State Mainlined
Commit 39101b2265440dfe83646a4bfc33015c86f36d71
Headers show
Series fs/ext4/inode-test: Fix inode test on 32 bit platforms. | expand

Commit Message

Iurii Zaikin Nov. 27, 2019, 6:55 p.m. UTC
Fixes the issue caused by the fact that in C in the expression
of the form -1234L only 1234L is the actual literal, the unary
minus is an operation applied to the literal. Which means that
to express the lower bound for the type one has to negate the
upper bound and subtract 1.
Original error:
Expected test_data[i].expected.tv_sec == timestamp.tv_sec, but
test_data[i].expected.tv_sec == -2147483648
timestamp.tv_sec == 2147483648
1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits: msb:1
lower_bound:1 extra_bits: 0
Expected test_data[i].expected.tv_sec == timestamp.tv_sec, but
test_data[i].expected.tv_sec == 2147483648
timestamp.tv_sec == 6442450944
2038-01-19 Lower bound of 32bit <0 timestamp, lo extra sec bit on:
msb:1 lower_bound:1 extra_bits: 1
Expected test_data[i].expected.tv_sec == timestamp.tv_sec, but
test_data[i].expected.tv_sec == 6442450944
timestamp.tv_sec == 10737418240
2174-02-25 Lower bound of 32bit <0 timestamp, hi extra sec bit on:
msb:1 lower_bound:1 extra_bits: 2
not ok 1 - inode_test_xtimestamp_decoding
not ok 1 - ext4_inode_test

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Iurii Zaikin <yzaikin@google.com>
Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 fs/ext4/inode-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.24.0.432.g9d3f5f5b63-goog

Comments

Brendan Higgins Dec. 2, 2019, 4:18 p.m. UTC | #1
On Wed, Nov 27, 2019 at 10:55 AM Iurii Zaikin <yzaikin@google.com> wrote:
>
> Fixes the issue caused by the fact that in C in the expression
> of the form -1234L only 1234L is the actual literal, the unary
> minus is an operation applied to the literal. Which means that
> to express the lower bound for the type one has to negate the
> upper bound and subtract 1.
> Original error:
> Expected test_data[i].expected.tv_sec == timestamp.tv_sec, but
> test_data[i].expected.tv_sec == -2147483648
> timestamp.tv_sec == 2147483648
> 1901-12-13 Lower bound of 32bit < 0 timestamp, no extra bits: msb:1
> lower_bound:1 extra_bits: 0
> Expected test_data[i].expected.tv_sec == timestamp.tv_sec, but
> test_data[i].expected.tv_sec == 2147483648
> timestamp.tv_sec == 6442450944
> 2038-01-19 Lower bound of 32bit <0 timestamp, lo extra sec bit on:
> msb:1 lower_bound:1 extra_bits: 1
> Expected test_data[i].expected.tv_sec == timestamp.tv_sec, but
> test_data[i].expected.tv_sec == 6442450944
> timestamp.tv_sec == 10737418240
> 2174-02-25 Lower bound of 32bit <0 timestamp, hi extra sec bit on:
> msb:1 lower_bound:1 extra_bits: 2
> not ok 1 - inode_test_xtimestamp_decoding
> not ok 1 - ext4_inode_test
>
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Signed-off-by: Iurii Zaikin <yzaikin@google.com>
> Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>

Acked-by: Brendan Higgins <brendanhiggins@google.com>

Thanks for taking care of this so quickly!
diff mbox series

Patch

diff --git a/fs/ext4/inode-test.c b/fs/ext4/inode-test.c
index 92a9da1774aa..bbce1c328d85 100644
--- a/fs/ext4/inode-test.c
+++ b/fs/ext4/inode-test.c
@@ -25,7 +25,7 @@ 
  * For constructing the negative timestamp lower bound value.
  * binary: 10000000 00000000 00000000 00000000
  */
-#define LOWER_MSB_1 (-0x80000000L)
+#define LOWER_MSB_1 (-(UPPER_MSB_0) - 1L)  /* avoid overflow */
 /*
  * For constructing the negative timestamp upper bound value.
  * binary: 11111111 11111111 11111111 11111111