All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Frans Klaver <fransklaver@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Yueyao Zhu <yueyao.zhu@gmail.com>,
	Rui Miguel Silva <rmfrfs@gmail.com>,
	Guru Das Srinagesh <gurooodas@gmail.com>,
	Javier Martinez Canillas <javier@dowhile0.org>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: fusb302: don't bitshift __le16 type
Date: Fri, 16 Jun 2017 11:11:50 -0700	[thread overview]
Message-ID: <20170616181150.GA2004@roeck-us.net> (raw)
In-Reply-To: <20170616174556.2358-1-fransklaver@gmail.com>

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
> 

  reply	other threads:[~2017-06-16 18:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-16 17:45 [PATCH] staging: fusb302: don't bitshift __le16 type Frans Klaver
2017-06-16 18:11 ` Guenter Roeck [this message]
2017-06-16 22:44 ` endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] Joe Perches
2017-06-16 22:44   ` Joe Perches
2017-06-16 22:49   ` [Cocci] [Fwd: endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ]] Joe Perches
2017-06-17  5:23   ` endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] Julia Lawall
2017-06-17  5:23     ` Julia Lawall
2017-06-17  5:50     ` Joe Perches
2017-06-17  5:50       ` Joe Perches
2017-06-17  6:00       ` Julia Lawall
2017-06-17  6:00         ` Julia Lawall
2017-06-17  6:23         ` Joe Perches
2017-06-17  6:23           ` Joe Perches
2017-06-17  6:26           ` Julia Lawall
2017-06-17  6:26             ` Julia Lawall
2017-06-23 22:29   ` Frans Klaver
2017-06-23 22:29     ` Frans Klaver
2017-06-23 23:37     ` Julia Lawall
2017-06-23 23:37       ` Julia Lawall
2017-06-26  8:06       ` Frans Klaver
2017-06-26  8:06         ` Frans Klaver
2017-06-26  9:39         ` Julia Lawall
2017-06-26  9:39           ` Julia Lawall
2017-06-26 20:57       ` Frans Klaver
2017-06-26 20:57         ` Frans Klaver
2017-06-26 21:03         ` Julia Lawall
2017-06-26 21:03           ` Julia Lawall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170616181150.GA2004@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=devel@driverdev.osuosl.org \
    --cc=fransklaver@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gurooodas@gmail.com \
    --cc=javier@dowhile0.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmfrfs@gmail.com \
    --cc=yueyao.zhu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.