Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1667958
| From | Guenter Roeck <linux@roeck-us.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] staging: fusb302: don't bitshift __le16 type |
| Date | 2017-06-16 20:20 +0200 |
| Message-ID | <tT40F-3II-13@gated-at.bofh.it> (permalink) |
| References | <tT3nX-3dR-13@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, Jun 16, 2017 at 07:45:56PM +0200, Frans Klaver wrote: > The header field in struct pd_message is declared as an __le16 type. The > data in the message is supposed to be little endian. This means we don't > have to go and shift the individual bytes into position when we're > filling the buffer, we can just copy the contents right away. As an > added benefit we don't get fishy results on big endian systems anymore. > > Signed-off-by: Frans Klaver <fransklaver@gmail.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > drivers/staging/typec/fusb302/fusb302.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/typec/fusb302/fusb302.c b/drivers/staging/typec/fusb302/fusb302.c > index 4a356e509fe4..03a3809d18f0 100644 > --- a/drivers/staging/typec/fusb302/fusb302.c > +++ b/drivers/staging/typec/fusb302/fusb302.c > @@ -1039,8 +1039,8 @@ static int fusb302_pd_send_message(struct fusb302_chip *chip, > } > /* packsym tells the FUSB302 chip that the next X bytes are payload */ > buf[pos++] = FUSB302_TKN_PACKSYM | (len & 0x1F); > - buf[pos++] = msg->header & 0xFF; > - buf[pos++] = (msg->header >> 8) & 0xFF; > + memcpy(&buf[pos], &msg->header, sizeof(msg->header)); > + pos += sizeof(msg->header); > > len -= 2; > memcpy(&buf[pos], msg->payload, len); > -- > 2.13.0 >
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] staging: fusb302: don't bitshift __le16 type Frans Klaver <fransklaver@gmail.com> - 2017-06-16 19:40 +0200
Re: [PATCH] staging: fusb302: don't bitshift __le16 type Guenter Roeck <linux@roeck-us.net> - 2017-06-16 20:20 +0200
endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] Joe Perches <joe@perches.com> - 2017-06-17 00:50 +0200
Re: endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] Julia Lawall <julia.lawall@lip6.fr> - 2017-06-17 07:30 +0200
Re: endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] Joe Perches <joe@perches.com> - 2017-06-17 08:00 +0200
Re: endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] Julia Lawall <julia.lawall@lip6.fr> - 2017-06-17 08:10 +0200
Re: endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] Joe Perches <joe@perches.com> - 2017-06-17 08:30 +0200
Re: endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] Julia Lawall <julia.lawall@lip6.fr> - 2017-06-17 08:30 +0200
csiph-web