Subject: [PATCH] x86: fix -Wsign-compare warnings in uaccess.h

The casts are safe, since those conditions are only evaluated when sz >= 0.

Signed-off-by: Роман Донченко <[email protected]>
---
arch/x86/include/asm/uaccess.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index a8df874..4c47002 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -714,7 +714,7 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
* case, and do only runtime checking for non-constant sizes.
*/

- if (likely(sz < 0 || sz >= n))
+ if (likely(sz < 0 || (unsigned)sz >= n))
n = _copy_from_user(to, from, n);
else if(__builtin_constant_p(n))
copy_from_user_overflow();
@@ -732,7 +732,7 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
might_fault();

/* See the comment in copy_from_user() above. */
- if (likely(sz < 0 || sz >= n))
+ if (likely(sz < 0 || (unsigned)sz >= n))
n = _copy_to_user(to, from, n);
else if(__builtin_constant_p(n))
copy_to_user_overflow();
--
2.3.2


2015-06-27 19:16:39

by Toralf Förster

[permalink] [raw]
Subject: Re: [PATCH] x86: fix -Wsign-compare warnings in uaccess.h

>The casts are safe, since those conditions are only evaluated when sz >= 0.


Wouldn't in this case the condition "sz < 0" be superfluously ?


--
Toralf
pgp key: 7B1A 07F4 EC82 0F90 D4C2 8936 872A E508 0076 E94E

Subject: Re: [PATCH] x86: fix -Wsign-compare warnings in uaccess.h

Toralf Förster <[email protected]> писал в своём письме Sat, 27 Jun
2015 22:16:27 +0300:

>> The casts are safe, since those conditions are only evaluated when sz
>> >= 0.
>
>
> Wouldn't in this case the condition "sz < 0" be superfluously ?

No, sz can be negative. I meant that if sz < 0, then the second halves
won't be evaluated (though even if they did, it wouldn't matter).