Skip to contentSkip to conversation

jfs: avoid -Wtautological-constant-out-of-range-compare warning

PATCH Superseded Arnd Bergmann 3 participants 3 messages Feb 2 JFS filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs: avoid -Wtautological-constant-out-of-range-compare warning

From: Arnd Bergmann <[email protected]>

A recent change for the range check started triggering a clang warning:

fs/jfs/jfs_dtree.c:2906:31: error: result of comparison of constant 128 with expression of type 's8' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

 2906 |                         if (stbl[i] < 0 || stbl[i] >= DTPAGEMAXSLOT) {
      |                                            ~~~~~~~ ^  ~~~~~~~~~~~~~
fs/jfs/jfs_dtree.c:3111:30: error: result of comparison of constant 128 with expression of type 's8' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
 3111 |                 if (stbl[0] < 0 || stbl[0] >= DTPAGEMAXSLOT) {
      |                                    ~~~~~~~ ^  ~~~~~~~~~~~~~

Both the old and the new check were useless, but the previous version apparently did not lead to the warning.

Rephrase this again by adding a cast. The check is still always false, but the compiler shuts up about it.

Fixes cafc6679824a ("jfs: replace hardcoded magic number with DTPAGEMAXSLOT constant")
---
 fs/jfs/jfs_dtree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/jfs/jfs_dtree.c +2 -2
index 0ab83bb7bbdf..e3301e5fa037 100644
@@ -2903,7 +2903,7 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
 		stbl = DT_GETSTBL(p);
 
 		for (i = index; i < p->header.nextindex; i++) {
-			if (stbl[i] < 0 || stbl[i] >= DTPAGEMAXSLOT) {
+			if (stbl[i] < 0 || (unsigned char)stbl[i] >= DTPAGEMAXSLOT) {
 				jfs_err("JFS: Invalid stbl[%d] = %d for inode %ld, block = %lld",
 					i, stbl[i], (long)ip->i_ino, (long long)bn);
 				free_page(dirent_buf);
@@ -3108,7 +3108,7 @@ static int dtReadFirst(struct inode *ip, struct btstack * btstack)
 		/* get the leftmost entry */
 		stbl = DT_GETSTBL(p);
 
-		if (stbl[0] < 0 || stbl[0] >= DTPAGEMAXSLOT) {
+		if (stbl[0] < 0 || (unsigned char)stbl[0] >= DTPAGEMAXSLOT) {
 			DT_PUTPAGE(mp);
 			jfs_error(ip->i_sb, "stbl[0] out of bound\n");
 			return -EIO;
Signature · 1 line
2.39.5
#1 lore raw
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

A recent change for the range check started triggering a clang warning:

fs/jfs/jfs_dtree.c:2906:31: error: result of comparison of constant 128 with expression of type 's8' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

  2906 |                         if (stbl[i] < 0 || stbl[i] >= DTPAGEMAXSLOT) {
       |                                            ~~~~~~~ ^  ~~~~~~~~~~~~~
fs/jfs/jfs_dtree.c:3111:30: error: result of comparison of constant 128 with expression of type 's8' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
  3111 |                 if (stbl[0] < 0 || stbl[0] >= DTPAGEMAXSLOT) {
       |                                    ~~~~~~~ ^  ~~~~~~~~~~~~~
Quoted 5 lines

Both the old and the new check were useless, but the previous version apparently did not lead to the warning.

Rephrase this again by adding a cast. The check is still always false, but the compiler shuts up about it.

I think it would be better to just drop the useless part of these tests.

Shaggy

Quoted 29 lines
Fixes cafc6679824a ("jfs: replace hardcoded magic number with DTPAGEMAXSLOT constant")
---
  fs/jfs/jfs_dtree.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/jfs/jfs_dtree.c +2 -2
index 0ab83bb7bbdf..e3301e5fa037 100644
@@ -2903,7 +2903,7 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
  		stbl = DT_GETSTBL(p);
 
  		for (i = index; i < p->header.nextindex; i++) {
-			if (stbl[i] < 0 || stbl[i] >= DTPAGEMAXSLOT) {
+			if (stbl[i] < 0 || (unsigned char)stbl[i] >= DTPAGEMAXSLOT) {
  				jfs_err("JFS: Invalid stbl[%d] = %d for inode %ld, block = %lld",
  					i, stbl[i], (long)ip->i_ino, (long long)bn);
  				free_page(dirent_buf);
@@ -3108,7 +3108,7 @@ static int dtReadFirst(struct inode *ip, struct btstack * btstack)
  		/* get the leftmost entry */
  		stbl = DT_GETSTBL(p);
 
-		if (stbl[0] < 0 || stbl[0] >= DTPAGEMAXSLOT) {
+		if (stbl[0] < 0 || (unsigned char)stbl[0] >= DTPAGEMAXSLOT) {
  			DT_PUTPAGE(mp);
  			jfs_error(ip->i_sb, "stbl[0] out of bound\n");
  			return -EIO;
#2 lore raw
Quoted 12 lines · Dave Kleikamp
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

A recent change for the range check started triggering a clang warning:

fs/jfs/jfs_dtree.c:2906:31: error: result of comparison of constant 128 with expression of type 's8' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

  2906 |                         if (stbl[i] < 0 || stbl[i] >= DTPAGEMAXSLOT) {
       |                                            ~~~~~~~ ^  ~~~~~~~~~~~~~
fs/jfs/jfs_dtree.c:3111:30: error: result of comparison of constant 128 with expression of type 's8' (aka 'signed char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
  3111 |                 if (stbl[0] < 0 || stbl[0] >= DTPAGEMAXSLOT) {
       |                                    ~~~~~~~ ^  ~~~~~~~~~~~~~
Quoted 7 lines
Quoted 5 lines

Both the old and the new check were useless, but the previous version apparently did not lead to the warning.

Rephrase this again by adding a cast. The check is still always false, but the compiler shuts up about it.

I think it would be better to just drop the useless part of these tests.

Fair enough, sent v2 now.

Arnd