LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] x86: sparse errors from string_32.h
@ 2008-02-01  6:15 Harvey Harrison
  2008-02-01 10:56 ` Ingo Molnar
  0 siblings, 1 reply; 5+ messages in thread
From: Harvey Harrison @ 2008-02-01  6:15 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: H. Peter Anvin, Thomas Gleixner, LKML

include/asm/string_32.h:216:26: warning: cast truncates bits from constant value (cccccccc becomes cc)
include/asm/string_32.h:219:27: warning: cast truncates bits from constant value (cccccccc becomes cccc)
include/asm/string_32.h:222:27: warning: cast truncates bits from constant value (cccccccc becomes cccc)
include/asm/string_32.h:223:30: warning: cast truncates bits from constant value (cccccccc becomes cc)

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
Ingo, this shows up over and over again during the build, this
doesn't change anything as they are known compile-time constants
at this point, the and-ing just makes the truncation explicit.

If you disagree with this method, no worries.

 include/asm-x86/string_32.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/asm-x86/string_32.h b/include/asm-x86/string_32.h
index 55bfa30..c5d13a8 100644
--- a/include/asm-x86/string_32.h
+++ b/include/asm-x86/string_32.h
@@ -213,14 +213,14 @@ static __always_inline void * __constant_c_and_count_memset(void * s, unsigned l
 		case 0:
 			return s;
 		case 1:
-			*(unsigned char *)s = pattern;
+			*(unsigned char *)s = pattern & 0xff;
 			return s;
 		case 2:
-			*(unsigned short *)s = pattern;
+			*(unsigned short *)s = pattern & 0xffff;
 			return s;
 		case 3:
-			*(unsigned short *)s = pattern;
-			*(2+(unsigned char *)s) = pattern;
+			*(unsigned short *)s = pattern & 0xffff;
+			*(2+(unsigned char *)s) = pattern & 0xff;
 			return s;
 		case 4:
 			*(unsigned long *)s = pattern;
-- 
1.5.4.rc4.1142.gf5a97




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: sparse errors from string_32.h
  2008-02-01  6:15 [PATCH] x86: sparse errors from string_32.h Harvey Harrison
@ 2008-02-01 10:56 ` Ingo Molnar
  2008-02-01 11:07   ` Harvey Harrison
  2008-02-01 18:06   ` H. Peter Anvin
  0 siblings, 2 replies; 5+ messages in thread
From: Ingo Molnar @ 2008-02-01 10:56 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: H. Peter Anvin, Thomas Gleixner, LKML


* Harvey Harrison <harvey.harrison@gmail.com> wrote:

>  		case 1:
> -			*(unsigned char *)s = pattern;
> +			*(unsigned char *)s = pattern & 0xff;

i've applied your fix - but wouldnt it be cleaner to just cast the 
pattern variable to unsigned char instead?

	Ingo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: sparse errors from string_32.h
  2008-02-01 10:56 ` Ingo Molnar
@ 2008-02-01 11:07   ` Harvey Harrison
  2008-02-01 18:06   ` H. Peter Anvin
  1 sibling, 0 replies; 5+ messages in thread
From: Harvey Harrison @ 2008-02-01 11:07 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: H. Peter Anvin, Thomas Gleixner, LKML

On Fri, 2008-02-01 at 11:56 +0100, Ingo Molnar wrote:
> * Harvey Harrison <harvey.harrison@gmail.com> wrote:
> 
> >  		case 1:
> > -			*(unsigned char *)s = pattern;
> > +			*(unsigned char *)s = pattern & 0xff;
> 
> i've applied your fix - but wouldnt it be cleaner to just cast the 
> pattern variable to unsigned char instead?

I'm not sure, I went with this solution because of the explicit length
being tested in the case statements.  The compiler can see it's all
constant at this point anyway...if you want a cast-patch instead, just
ask.

Harvey


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: sparse errors from string_32.h
  2008-02-01 10:56 ` Ingo Molnar
  2008-02-01 11:07   ` Harvey Harrison
@ 2008-02-01 18:06   ` H. Peter Anvin
  2008-02-02  0:40     ` Harvey Harrison
  1 sibling, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2008-02-01 18:06 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Harvey Harrison, Thomas Gleixner, LKML

Ingo Molnar wrote:
> * Harvey Harrison <harvey.harrison@gmail.com> wrote:
> 
>>  		case 1:
>> -			*(unsigned char *)s = pattern;
>> +			*(unsigned char *)s = pattern & 0xff;
> 
> i've applied your fix - but wouldnt it be cleaner to just cast the 
> pattern variable to unsigned char instead?
> 

Even better, since we're talking about fixed bytes, I suggest writing it as:

	*(u8 *)s = (u8)pattern;

Much more compact and the intent is a little bit more obvious.

	-hpa

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86: sparse errors from string_32.h
  2008-02-01 18:06   ` H. Peter Anvin
@ 2008-02-02  0:40     ` Harvey Harrison
  0 siblings, 0 replies; 5+ messages in thread
From: Harvey Harrison @ 2008-02-02  0:40 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: Ingo Molnar, Thomas Gleixner, LKML

On Fri, 2008-02-01 at 10:06 -0800, H. Peter Anvin wrote:
> Ingo Molnar wrote:
> > * Harvey Harrison <harvey.harrison@gmail.com> wrote:
> > 
> >>  		case 1:
> >> -			*(unsigned char *)s = pattern;
> >> +			*(unsigned char *)s = pattern & 0xff;
> > 
> > i've applied your fix - but wouldnt it be cleaner to just cast the 
> > pattern variable to unsigned char instead?
> > 
> 
> Even better, since we're talking about fixed bytes, I suggest writing it as:
> 
> 	*(u8 *)s = (u8)pattern;
> 
> Much more compact and the intent is a little bit more obvious.
> 

While I agree that is cleaner, that will still produce sparse warnings
about a cast truncating bits from a constant value.  I think that
explicit & is necessary (unless the cure is worse than the disease).

Harvey


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-02-02  0:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-01  6:15 [PATCH] x86: sparse errors from string_32.h Harvey Harrison
2008-02-01 10:56 ` Ingo Molnar
2008-02-01 11:07   ` Harvey Harrison
2008-02-01 18:06   ` H. Peter Anvin
2008-02-02  0:40     ` Harvey Harrison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).