Skip to contentSkip to conversation

af_key: suppress a warning for 64k pages.

PATCH In review Stephen Rothwell 2 participants 6 messages Oct 31, 2007

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

PATCH 1/1 af_key: suppress a warning for 64k pages.

On PowerPC allmodconfig build we get this:

net/key/af_key.c:400: warning: comparison is always false due to limited range of data type

---
 net/key/af_key.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]
net/key/af_key.c +3 -0
index 7969f8a..7da6c1a 100644
@@ -397,8 +397,11 @@ static inline int verify_sec_ctx_len(void *p)
 	struct sadb_x_sec_ctx *sec_ctx = (struct sadb_x_sec_ctx *)p;
 	int len;
 
+	/* sadb_x_ctx_len is uint16_t */
+#if PAGE_SIZE < (1 << 16)
 	if (sec_ctx->sadb_x_ctx_len > PAGE_SIZE)
 		return -EINVAL;
+#endif
 
 	len = pfkey_sec_ctx_len(sec_ctx);
 
Signature · 1 line
1.5.3.4
maintainer
#1 lore raw

From: Stephen Rothwell <[email protected]>
Date: Wed, 31 Oct 2007 14:59:54 +1100

Quoted 5 lines

On PowerPC allmodconfig build we get this:

net/key/af_key.c:400: warning: comparison is always false due to limited range of data type

...

net/key/af_key.c static inline int verify_sec_ctx_len(void *p) · line 406

Quoted 9 lines
net/key/af_key.c +3 -0
+	/* sadb_x_ctx_len is uint16_t */
+#if PAGE_SIZE < (1 << 16)
 	if (sec_ctx->sadb_x_ctx_len > PAGE_SIZE)
 		return -EINVAL;
+#endif
 
 	len = pfkey_sec_ctx_len(sec_ctx);

I'm not so sure ifdef'ing things up all over the place is the way to solve this. It makes the code ultra ugly.

I think we should retain the check, but modify it so that GCC knows we understand that it's OK if it is always false. Perhaps a simple (u32) cast on the left branch of the comparison is sufficient?

#2 lore raw
Quoted 3 lines · On Tue, 30 Oct 2007 21:08:46 -0700 (PDT) David Miller <[email protected]>…

I'm not so sure ifdef'ing things up all over the place is the way to solve this. It makes the code ultra ugly.

I agree.

Quoted 3 lines

I think we should retain the check, but modify it so that GCC knows we understand that it's OK if it is always false. Perhaps a simple (u32) cast on the left branch of the comparison is sufficient?

Unfortunately, that does not suppress the warning (gcc is getting too smart :-().

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
maintainer
#3 lore raw

From: Stephen Rothwell <[email protected]>
Date: Wed, 31 Oct 2007 15:34:22 +1100

Quoted 7 lines · On Tue, 30 Oct 2007 21:08:46 -0700 (PDT) David Miller <[email protected]>…
Quoted 3 lines

I think we should retain the check, but modify it so that GCC knows we understand that it's OK if it is always false. Perhaps a simple (u32) cast on the left branch of the comparison is sufficient?

Unfortunately, that does not suppress the warning (gcc is getting too smart :-().

It seems if you break the comparison out into a function which takes a u32, that's enough to get rid of the warning.

I can't figure out a way to make this prettier, can you?

#define PAGE_SIZE (64 * 1024)

typedef unsigned int u32;
typedef unsigned short u16;

int compare(u32 val)

{
	if (val >= PAGE_SIZE)
		return -1;
	return 0;
}

int foo(u16 val)
{

#if 1
	return compare(val);
#else
	if (val >= PAGE_SIZE)
		return -1;
	return 0;

#endif
}

#4 lore raw

PATCH 1/1 af_key: suppress a warning for 64k pages.

On PowerPC allmodconfig build we get this:

net/key/af_key.c:400: warning: comparison is always false due to limited range of data type

---
 net/key/af_key.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This version gets rid of the warning without the ugliness of ifdefs.

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]
net/key/af_key.c +2 -2
index 7969f8a..266f112 100644
@@ -395,9 +395,9 @@ static inline int pfkey_sec_ctx_len(struct sadb_x_sec_ctx *sec_ctx)
 static inline int verify_sec_ctx_len(void *p)
 {
 	struct sadb_x_sec_ctx *sec_ctx = (struct sadb_x_sec_ctx *)p;
-	int len;
+	int len = sec_ctx->sadb_x_ctx_len;
 
-	if (sec_ctx->sadb_x_ctx_len > PAGE_SIZE)
+	if (len > PAGE_SIZE)
 		return -EINVAL;
 
 	len = pfkey_sec_ctx_len(sec_ctx);
Signature · 1 line
1.5.3.4