Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751971AbdFPWon (ORCPT ); Fri, 16 Jun 2017 18:44:43 -0400 Received: from smtprelay0167.hostedemail.com ([216.40.44.167]:45321 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750873AbdFPWol (ORCPT ); Fri, 16 Jun 2017 18:44:41 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:541:960:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3868:3870:3871:4321:4362:5007:9108:10004:10400:10848:11232:11658:11783:11914:12296:12740:12895:13069:13095:13138:13161:13229:13231:13311:13357:13439:13894:14040:14659:14721:21080:21324:21433:21627:30054:30079:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: thumb60_b74c58498702 X-Filterd-Recvd-Size: 2245 Message-ID: <1497653077.10546.23.camel@perches.com> Subject: endian bitshift defects [ was: staging: fusb302: don't bitshift __le16 type ] From: Joe Perches To: Frans Klaver , Greg Kroah-Hartman , kernel-janitors Cc: Guenter Roeck , Yueyao Zhu , Rui Miguel Silva , Guru Das Srinagesh , Javier Martinez Canillas , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Date: Fri, 16 Jun 2017 15:44:37 -0700 In-Reply-To: <20170616174556.2358-1-fransklaver@gmail.com> References: <20170616174556.2358-1-fransklaver@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1121 Lines: 48 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 $