From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751474AbdJEQLj (ORCPT ); Thu, 5 Oct 2017 12:11:39 -0400 Received: from smtprelay0082.hostedemail.com ([216.40.44.82]:60041 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751094AbdJEQLh (ORCPT ); Thu, 5 Oct 2017 12:11:37 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:2689:2693:2828:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:5007:6119:7576:7903:8660:10004:10400:10848:11026:11232:11658:11914:12043:12048:12438:12740:12895:13069:13148:13230:13311:13357:13439:13894:14659:14721:21080:21451:21627:30034:30054:30090: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:3,LUA_SUMMARY:none X-HE-Tag: spoon24_8223f7dcf5831 X-Filterd-Recvd-Size: 3055 Message-ID: <1507219892.4434.29.camel@perches.com> Subject: Re: [PATCH] rsi: fix integer overflow warning From: Joe Perches To: David Laight , Arnd Bergmann , Kalle Valo , Prameela Rani Garnepudi , Amitkumar Karwar Cc: Pavani Muthyala , Karun Eagalapati , "linux-wireless@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Date: Thu, 05 Oct 2017 09:11:32 -0700 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6DD008ACEE@AcuExch.aculab.com> References: <20171005120547.328687-1-arnd@arndb.de> <1507205947.4434.23.camel@perches.com> <063D6719AE5E284EB5DD2968C1650D6DD008ACEE@AcuExch.aculab.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 On Thu, 2017-10-05 at 15:12 +0000, David Laight wrote: > From: Joe Perches > > Sent: 05 October 2017 13:19 > > On Thu, 2017-10-05 at 14:05 +0200, Arnd Bergmann wrote: > > > gcc produces a harmless warning about a recently introduced > > > signed integer overflow: > > > > > > drivers/net/wireless/rsi/rsi_91x_hal.c: In function 'rsi_prepare_mgmt_desc': > > > include/uapi/linux/swab.h:13:15: error: integer overflow in expression [-Werror=overflow] > > > (((__u16)(x) & (__u16)0x00ffU) << 8) | \ > > > ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ > > > include/uapi/linux/swab.h:104:2: note: in expansion of macro '___constant_swab16' > > > ___constant_swab16(x) : \ > > > ^~~~~~~~~~~~~~~~~~ > > > include/uapi/linux/byteorder/big_endian.h:34:43: note: in expansion of macro '__swab16' > > > #define __cpu_to_le16(x) ((__force __le16)__swab16((x))) > > > > [] > > > > > The problem is that the 'mask' value is a signed integer that gets > > > turned into a negative number when truncated to 16 bits. Making it > > > an unsigned constant avoids this. > > > > I would expect there are more of these. > > > > Perhaps this define in include/uapi/linux/swab.h: > > > > #define __swab16(x) \ > > (__builtin_constant_p((__u16)(x)) ? \ > > ___constant_swab16(x) : \ > > __fswab16(x)) > > > > should be > > > > #define __swab16(x) \ > > (__builtin_constant_p((__u16)(x)) ? \ > > ___constant_swab16((__u16)(x)) : \ > > __fswab16((__u16)(x))) > > You probably don't want the cast in the call to __fswab16() since > that is likely to generate an explicit and with 0xffff. > You will likely also get one if the argument is _u16 (not unsigned int). It would just an explicit vs implicit cast as __fswab16 is a static inline with a __u16 argument