Skip to contentSkip to conversation

ext4: Fix comparision of unsigned expression with < 0

RFC PATCH New Lokesh Vutla 2 participants 5 messages Apr 25, 2017 – Apr 26, 2017 ext4 file system

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ext4: Fix comparision of unsigned expression with < 0

In file ext4fs.c funtion ext4fs_read_file() compares an unsigned expression with < 0 like below

	lbaint_t blknr;
	blknr = read_allocated_block(&(node->inode), i);
	if (blknr < 0)
		return -1;

blknr is of type ulong/uint64_t. read_allocated_block() returns long int. So comparing blknr with < 0 will always be false. Instead declare blknr as long int.

---
 fs/ext4/ext4fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4fs.c +1 -1
index 7187dcfb05..081509dbb4 100644
@@ -71,7 +71,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
 	blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
 
 	for (i = lldiv(pos, blocksize); i < blockcnt; i++) {
-		lbaint_t blknr;
+		long int blknr;
 		int blockoff = pos - (blocksize * i);
 		int blockend = blocksize;
 		int skipfirst = 0;
Signature · 1 line
2.11.0
#1 lore raw

RFC PATCH 1/1 ext4: Fix comparision of unsigned expression with < 0

Quoted 23 lines · Lokesh Vutla

In file ext4fs.c funtion ext4fs_read_file() compares an unsigned expression with < 0 like below

	lbaint_t blknr;
	blknr = read_allocated_block(&(node->inode), i);
	if (blknr < 0)
		return -1;

blknr is of type ulong/uint64_t. read_allocated_block() returns long int. So comparing blknr with < 0 will always be false. Instead declare blknr as long int.

---
 fs/ext4/ext4fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4fs.c +0 -0
index 7187dcfb05..081509dbb4 100644

fs/ext4/ext4fs.c int ext4fs_read_file(struct ext2fs_node *node, loff_t pos, · line 77

Quoted 8 lines
fs/ext4/ext4fs.c +1 -1
@@ -71,7 +71,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
 	blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
 
 	for (i = lldiv(pos, blocksize); i < blockcnt; i++) {
-		lbaint_t blknr;
+		long int blknr;
 		int blockoff = pos - (blocksize * i);
 		int blockend = blocksize;
 		int skipfirst = 0;

My only question is, did you catch that by inspection, clang, or a newer than gcc-6.3 warning? Also, fs/ext4/dev.c:63 is a similar problem, if you'd like to non-RFC a v2. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170425/ab14bb56/attachment.sig>
#2 lore raw

RFC PATCH 1/1 ext4: Fix comparision of unsigned expression with < 0

Quoted 26 lines · Tom Rini
Quoted 25 lines · Lokesh Vutla

In file ext4fs.c funtion ext4fs_read_file() compares an unsigned expression with < 0 like below

	lbaint_t blknr;
	blknr = read_allocated_block(&(node->inode), i);
	if (blknr < 0)
		return -1;

blknr is of type ulong/uint64_t. read_allocated_block() returns long int. So comparing blknr with < 0 will always be false. Instead declare blknr as long int.

---
 fs/ext4/ext4fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4fs.c +0 -0
index 7187dcfb05..081509dbb4 100644
@@ -71,7 +71,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
 	blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
 
Quoted 8 lines

fs/ext4/ext4fs.c int ext4fs_read_file(struct ext2fs_node *node, loff_t pos, · line 77

Quoted 6 lines
fs/ext4/ext4fs.c +1 -1
 	for (i = lldiv(pos, blocksize); i < blockcnt; i++) {
-		lbaint_t blknr;
+		long int blknr;
 		int blockoff = pos - (blocksize * i);
 		int blockend = blocksize;
 		int skipfirst = 0;

My only question is, did you catch that by inspection, clang, or a newer

This is reported by Sunita and not sure how she caught it.

Quoted 2 lines

than gcc-6.3 warning? Also, fs/ext4/dev.c:63 is a similar problem, if you'd like to non-RFC a v2. Thanks!

In this case do you want me to drop the check or change lbaint_t to long int and update the argument type cast where ever ext4fs_devread() is called?

Thanks and regards,
Lokesh

#3 lore raw

RFC PATCH 1/1 ext4: Fix comparision of unsigned expression with < 0

Quoted 38 lines · Lokesh Vutla
Quoted 26 lines · Tom Rini
Quoted 25 lines · Lokesh Vutla

In file ext4fs.c funtion ext4fs_read_file() compares an unsigned expression with < 0 like below

	lbaint_t blknr;
	blknr = read_allocated_block(&(node->inode), i);
	if (blknr < 0)
		return -1;

blknr is of type ulong/uint64_t. read_allocated_block() returns long int. So comparing blknr with < 0 will always be false. Instead declare blknr as long int.

---
 fs/ext4/ext4fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4fs.c +0 -0
index 7187dcfb05..081509dbb4 100644
@@ -71,7 +71,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
 	blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
 
Quoted 8 lines

fs/ext4/ext4fs.c int ext4fs_read_file(struct ext2fs_node *node, loff_t pos, · line 77

Quoted 6 lines
fs/ext4/ext4fs.c +1 -1
 	for (i = lldiv(pos, blocksize); i < blockcnt; i++) {
-		lbaint_t blknr;
+		long int blknr;
 		int blockoff = pos - (blocksize * i);
 		int blockend = blocksize;
 		int skipfirst = 0;

My only question is, did you catch that by inspection, clang, or a newer

Quoted 1 line

This is reported by Sunita and not sure how she caught it.

OK. Because if she's got clang used on a TI platform and linking and booting, I'd very much like to hear what else is required, or if nothing, what version of the tools she's using, so I can put that into my CI loop. I didn't have luck when I tried last, but it was a while ago.

Quoted 5 lines
Quoted 2 lines

than gcc-6.3 warning? Also, fs/ext4/dev.c:63 is a similar problem, if you'd like to non-RFC a v2. Thanks!

In this case do you want me to drop the check or change lbaint_t to long int and update the argument type cast where ever ext4fs_devread() is called?

Just drop it I think, thanks.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170426/aaed3226/attachment.sig>
#4 lore raw

RFC PATCH 1/1 ext4: Fix comparision of unsigned expression with < 0

Quoted 39 lines · Tom Rini
Quoted 38 lines · Lokesh Vutla
Quoted 34 lines · Tom Rini
Quoted 23 lines · Lokesh Vutla

In file ext4fs.c funtion ext4fs_read_file() compares an unsigned expression with < 0 like below

	lbaint_t blknr;
	blknr = read_allocated_block(&(node->inode), i);
	if (blknr < 0)
		return -1;

blknr is of type ulong/uint64_t. read_allocated_block() returns long int. So comparing blknr with < 0 will always be false. Instead declare blknr as long int.

---
 fs/ext4/ext4fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ext4fs.c +0 -0
index 7187dcfb05..081509dbb4 100644

fs/ext4/ext4fs.c int ext4fs_read_file(struct ext2fs_node *node, loff_t pos, · line 77

Quoted 8 lines
fs/ext4/ext4fs.c +1 -1
@@ -71,7 +71,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
 	blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
 
 	for (i = lldiv(pos, blocksize); i < blockcnt; i++) {
-		lbaint_t blknr;
+		long int blknr;
 		int blockoff = pos - (blocksize * i);
 		int blockend = blocksize;
 		int skipfirst = 0;

My only question is, did you catch that by inspection, clang, or a newer

Quoted 7 lines
Quoted 1 line

This is reported by Sunita and not sure how she caught it.

OK. Because if she's got clang used on a TI platform and linking and booting, I'd very much like to hear what else is required, or if nothing, what version of the tools she's using, so I can put that into my CI loop. I didn't have luck when I tried last, but it was a while ago.

Sure, Ill update you on this with more details.

Thanks and regards,
Lokesh

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

than gcc-6.3 warning? Also, fs/ext4/dev.c:63 is a similar problem, if you'd like to non-RFC a v2. Thanks!

In this case do you want me to drop the check or change lbaint_t to long int and update the argument type cast where ever ext4fs_devread() is called?

Just drop it I think, thanks.