Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752903AbdFPSL6 (ORCPT ); Fri, 16 Jun 2017 14:11:58 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:48958 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752863AbdFPSLx (ORCPT ); Fri, 16 Jun 2017 14:11:53 -0400 Date: Fri, 16 Jun 2017 11:11:50 -0700 From: Guenter Roeck To: Frans Klaver Cc: Greg Kroah-Hartman , Yueyao Zhu , Rui Miguel Silva , Guru Das Srinagesh , Javier Martinez Canillas , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: fusb302: don't bitshift __le16 type Message-ID: <20170616181150.GA2004@roeck-us.net> References: <20170616174556.2358-1-fransklaver@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170616174556.2358-1-fransklaver@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1348 Lines: 33 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 Reviewed-by: Guenter Roeck > --- > 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 >