From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751659AbdJEPMM convert rfc822-to-8bit (ORCPT ); Thu, 5 Oct 2017 11:12:12 -0400 Received: from smtp-out4.electric.net ([192.162.216.185]:61489 "EHLO smtp-out4.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751380AbdJEPMK (ORCPT ); Thu, 5 Oct 2017 11:12:10 -0400 From: David Laight To: "'Joe Perches'" , 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" Subject: RE: [PATCH] rsi: fix integer overflow warning Thread-Topic: [PATCH] rsi: fix integer overflow warning Thread-Index: AQHTPdQ9Ga6FZ13PeUW2LLD7TzoQtqLVW/AQ Date: Thu, 5 Oct 2017 15:12:05 +0000 Message-ID: <063D6719AE5E284EB5DD2968C1650D6DD008ACEE@AcuExch.aculab.com> References: <20171005120547.328687-1-arnd@arndb.de> <1507205947.4434.23.camel@perches.com> In-Reply-To: <1507205947.4434.23.camel@perches.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.99.200] Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-Outbound-IP: 156.67.243.126 X-Env-From: David.Laight@ACULAB.COM X-Proto: esmtps X-Revdns: X-HELO: AcuExch.aculab.com X-TLS: TLSv1:AES128-SHA:128 X-Authenticated_ID: X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). David