Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1580409 > unrolled thread

[PATCH]staging: fbtft: Fix sparse warnings about endianness

Started bymaomao xu <albert008.xu@gmail.com>
First post2017-02-14 10:00 +0100
Last post2017-02-14 20:00 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH]staging: fbtft: Fix sparse warnings about endianness maomao xu <albert008.xu@gmail.com> - 2017-02-14 10:00 +0100
    Re: [PATCH]staging: fbtft: Fix sparse warnings about endianness Greg KH <gregkh@linuxfoundation.org> - 2017-02-14 18:20 +0100
      Re: [PATCH]staging: fbtft: Fix sparse warnings about endianness Al Viro <viro@ZenIV.linux.org.uk> - 2017-02-14 20:00 +0100

#1580409 — [PATCH]staging: fbtft: Fix sparse warnings about endianness

Frommaomao xu <albert008.xu@gmail.com>
Date2017-02-14 10:00 +0100
Subject[PATCH]staging: fbtft: Fix sparse warnings about endianness
Message-ID<taH7Q-7Yd-9@gated-at.bofh.it>
    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

[toc] | [next] | [standalone]


#1580697

FromGreg KH <gregkh@linuxfoundation.org>
Date2017-02-14 18:20 +0100
Message-ID<taOVI-4DR-13@gated-at.bofh.it>
In reply to#1580409
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

[toc] | [prev] | [next] | [standalone]


#1580759

FromAl Viro <viro@ZenIV.linux.org.uk>
Date2017-02-14 20:00 +0100
Message-ID<taQut-5rZ-11@gated-at.bofh.it>
In reply to#1580697
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...

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web