linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH]staging: fbtft: Fix sparse warnings about endianness
@ 2017-02-14  8:53 maomao xu
  2017-02-14 17:18 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: maomao xu @ 2017-02-14  8:53 UTC (permalink / raw)
  To: thomas.petazzoni, noralf, gregkh, devel, linux-kernel; +Cc: maomao xu

    Fixed sparse warnings about endianness. E.g.:

    warning: incorrect type in assignment (different base types)

Signed-off-by: maomao xu <albert008.xu@gmail.com>

diff --git a/drivers/staging/fbtft/fbtft-io.c b/drivers/staging/fbtft/fbtft-io.c
index d868405..ffb9a3b 100644
--- a/drivers/staging/fbtft/fbtft-io.c
+++ b/drivers/staging/fbtft/fbtft-io.c
@@ -71,7 +71,7 @@ int fbtft_write_spi_emulate_9(struct fbtft_par *par, void *buf, size_t len)
 			src++;
 		}
 		tmp |= ((*src & 0x0100) ? 1 : 0);
-		*(u64 *)dst = cpu_to_be64(tmp);
+		*(__be64 *)dst = cpu_to_be64(tmp);
 		dst += 8;
 		*dst++ = (u8)(*src++ & 0x00FF);
 		added++;
-- 
1.7.9.5

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

* Re: [PATCH]staging: fbtft: Fix sparse warnings about endianness
  2017-02-14  8:53 [PATCH]staging: fbtft: Fix sparse warnings about endianness maomao xu
@ 2017-02-14 17:18 ` Greg KH
  2017-02-14 18:57   ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2017-02-14 17:18 UTC (permalink / raw)
  To: maomao xu; +Cc: thomas.petazzoni, noralf, devel, linux-kernel

On Tue, Feb 14, 2017 at 04:53:10PM +0800, maomao xu wrote:
>     Fixed sparse warnings about endianness. E.g.:
> 
>     warning: incorrect type in assignment (different base types)

Why are these lines indented?

> Signed-off-by: maomao xu <albert008.xu@gmail.com>
> 
> diff --git a/drivers/staging/fbtft/fbtft-io.c b/drivers/staging/fbtft/fbtft-io.c
> index d868405..ffb9a3b 100644
> --- a/drivers/staging/fbtft/fbtft-io.c
> +++ b/drivers/staging/fbtft/fbtft-io.c
> @@ -71,7 +71,7 @@ int fbtft_write_spi_emulate_9(struct fbtft_par *par, void *buf, size_t len)
>  			src++;
>  		}
>  		tmp |= ((*src & 0x0100) ? 1 : 0);
> -		*(u64 *)dst = cpu_to_be64(tmp);
> +		*(__be64 *)dst = cpu_to_be64(tmp);

Really?  That seems very odd.  I need a maintainer's ack for this before
I can take it...

thanks,

greg k-h

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

* Re: [PATCH]staging: fbtft: Fix sparse warnings about endianness
  2017-02-14 17:18 ` Greg KH
@ 2017-02-14 18:57   ` Al Viro
  0 siblings, 0 replies; 3+ messages in thread
From: Al Viro @ 2017-02-14 18:57 UTC (permalink / raw)
  To: Greg KH; +Cc: maomao xu, thomas.petazzoni, noralf, devel, linux-kernel

On Tue, Feb 14, 2017 at 09:18:25AM -0800, Greg KH wrote:
> On Tue, Feb 14, 2017 at 04:53:10PM +0800, maomao xu wrote:
> >     Fixed sparse warnings about endianness. E.g.:
> > 
> >     warning: incorrect type in assignment (different base types)
> 
> Why are these lines indented?
> 
> > Signed-off-by: maomao xu <albert008.xu@gmail.com>
> > 
> > diff --git a/drivers/staging/fbtft/fbtft-io.c b/drivers/staging/fbtft/fbtft-io.c
> > index d868405..ffb9a3b 100644
> > --- a/drivers/staging/fbtft/fbtft-io.c
> > +++ b/drivers/staging/fbtft/fbtft-io.c
> > @@ -71,7 +71,7 @@ int fbtft_write_spi_emulate_9(struct fbtft_par *par, void *buf, size_t len)
> >  			src++;
> >  		}
> >  		tmp |= ((*src & 0x0100) ? 1 : 0);
> > -		*(u64 *)dst = cpu_to_be64(tmp);
> > +		*(__be64 *)dst = cpu_to_be64(tmp);
> 
> Really?  That seems very odd.  I need a maintainer's ack for this before
> I can take it...

If anything, I would turn the inner loop into
                tmp = 0;
                for (j = 0; j < 7; j++) {
			tmp <<= 9;
			tmp |= *src++ & 0x1ff;
                }
		tmp <<= 1;
there - the whole thing looks like an obfuscated "take an array of 9-bit
values, each stored in host-endian 16bit, repack them into octets".
Which architecture is that supposed to run on?  Anything that doesn't like
unaligned stores won't be happy with that code...

Another interesting part is that we have size = len / 2 and verify that len
is a multiple of 8.  I.e. that size is only guaranteed to be a multiple
of 4.  Each pass through the outer loop consumes 8 16bit values and decrements
size by 8, so if len is e.g. 24 we'll end up accepting that, get size equal
to 12, pass through the outer loop twice and chew through 32 bytes of buf...

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

end of thread, other threads:[~2017-02-14 18:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-14  8:53 [PATCH]staging: fbtft: Fix sparse warnings about endianness maomao xu
2017-02-14 17:18 ` Greg KH
2017-02-14 18:57   ` Al Viro

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).