Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: fusb302: don't bitshift __le16 type

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Frans Klaver and committed by
Greg Kroah-Hartman
b9e8caa7 1877e4ba

+2 -2
+2 -2
drivers/staging/typec/fusb302/fusb302.c
··· 1039 1039 } 1040 1040 /* packsym tells the FUSB302 chip that the next X bytes are payload */ 1041 1041 buf[pos++] = FUSB302_TKN_PACKSYM | (len & 0x1F); 1042 - buf[pos++] = msg->header & 0xFF; 1043 - buf[pos++] = (msg->header >> 8) & 0xFF; 1042 + memcpy(&buf[pos], &msg->header, sizeof(msg->header)); 1043 + pos += sizeof(msg->header); 1044 1044 1045 1045 len -= 2; 1046 1046 memcpy(&buf[pos], msg->payload, len);