Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752712AbdFQFXn (ORCPT ); Sat, 17 Jun 2017 01:23:43 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:2668 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750896AbdFQFXm (ORCPT ); Sat, 17 Jun 2017 01:23:42 -0400 X-IronPort-AV: E=Sophos;i="5.39,350,1493676000"; d="scan'208";a="228650030" Date: Sat, 17 Jun 2017 07:23:38 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Joe Perches cc: Frans Klaver , Greg Kroah-Hartman , kernel-janitors , Guenter Roeck , Yueyao Zhu , Rui Miguel Silva , Guru Das Srinagesh , Javier Martinez Canillas , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] In-Reply-To: <1497653077.10546.23.camel@perches.com> Message-ID: References: <20170616174556.2358-1-fransklaver@gmail.com> <1497653077.10546.23.camel@perches.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-1575079896-1497677019=:2045" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1647 Lines: 64 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1575079896-1497677019=:2045 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT On Fri, 16 Jun 2017, Joe Perches wrote: > On Fri, 2017-06-16 at 19:45 +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. > > Thanks for pointing this out. > > There are several instances of this class of error. > > Here's a cocci script to find them. > > This is best used with cocci's --all-includes option like: > > $ spatch --all-includes --very-quiet --sp-file lebe_bitshifts.cocci . > [ many defects...] > > $ cat lebe_bitshifts.cocci > @@ > typedef __le16, __le32, __le64,??__be16, __be32, __be64; > { __le16, __le32, __le64,??__be16, __be32, __be64 } a; > expression b; > @@ > > * a << b > > @@ > { __le16, __le32, __le64,??__be16, __be32, __be64 } a; > expression b; > @@ > > * a <<= b > > @@ > { __le16, __le32, __le64,??__be16, __be32, __be64 } a; > expression b; > @@ > > * a >> b > > @@ > { __le16, __le32, __le64,??__be16, __be32, __be64 } a; > expression b; > @@ > > * a >>= b Is this always a problem? Would it be useful to add this to the scripts in the kernel? julia --8323329-1575079896-1497677019=:2045--