Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030315AbcCQQIt (ORCPT ); Thu, 17 Mar 2016 12:08:49 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:56591 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934944AbcCQQIr (ORCPT ); Thu, 17 Mar 2016 12:08:47 -0400 From: Arnd Bergmann To: Hartley Sweeten Cc: Ian Abbott , Greg Kroah-Hartman , "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2] staging/comedi/dt282x: avoid integer overflow warning Date: Thu, 17 Mar 2016 17:08:34 +0100 Message-ID: <3053856.pfRJflhkJ8@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: References: <1458161501-283680-1-git-send-email-arnd@arndb.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:nF9B0+yx0xn0zjh7QXWhKf/13Lo86QzNw4RFo0bNgAsbs60mikr Oh+N0nsFQsrpZ0ae5c0OijeDvWOE5rgQH6HE7gOcqCiNygpxu3p2yfL13J4AlGsFBjdrZRb Kam4vamAcrGuPsquPoSzjti44s/TKkz7Mg04ME2uzq1fny+1ZUbXYD6zh0u1Th1zExEFzyx tpD1EV3XmD4Lpow6NbkKA== X-UI-Out-Filterresults: notjunk:1;V01:K0:NGrX8frr3/0=:PRbUtpzHl/73kKb/o3pNwP MPMDehuJGahu1ltiWKnn0lIsbGmATvpSi3UuDR+CpLBZws2JRY+gmOydz2mUML8Yx9LNmkmn1 /q5LBFiRFx/+uyG1PgdR72HQVPMDubAhC7H1O1DfoVreFm/8f5Jx0EgEqBlFod0y9jOBWjzcG Doyv6MePADYdzC61be9eRxC1HJJ0l+FFrT8bv9GimcALFIrrEHjRW10PVjZol4XM2CydVQgRs rImUjdEHzOUbeU5gU/mpoWQVNrnIuf52+q5FSK9RmzTexMBsra+MYLLx6O1Il4X1oPjdo0Tj7 5erz2fMI1Pe7qTowL9QM8kBLSl2AbUI6ct1jqnj5cwOb3OZJRHYhcFwx9u+7WMMooRtDMG8Q5 T0xtwY3z+Hsf/BQ1KGszOVb6nef8LVinNOD0FreNiOhSvv57lbxqmERS+8uUqLm/hpZvb4ZPT JiuBxTKa33jt0vvVX4lDf8lA16/xGN66JQ0jGUbXphS9WpevUTVkphjVJsLrJxmYIusffsJ+u Q2IJ3+fsedNEG56/s29kdC/fSGJ8FeKdpt7NKY1CCl5AqlOGKGHHYoX1oq4GZg8epQoAK/bZQ 1uh5JjWvEgjzvcCLe6rMIikf/DoV50B2fxer6JedvFtadl0Xz1kp+ZIqsmn//FgoTjBUpWQdQ Vsrle4MmszSCbgsyb8bYeYQnnzMpFychxmott0sOKyN5DrjdEpwm3TeqZgo+Y62pRVhjZnlbF 5uLCUS1KR92rQzwl Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2078 Lines: 51 On Thursday 17 March 2016 15:47:57 Hartley Sweeten wrote: > On Wednesday, March 16, 2016 1:51 PM, Arnd Bergmann wrote: > > Is this a gcc-6 specific issue? Seems line this warning should be showing > up in a lot of drivers. Yes, I did not see this before moving to gcc-6.0, but this is the only driver I've encountered the warning for, in around 7000 randconfig builds. > > The warning makes sense, though the code is correct as far as I > > can tell. > > > > This disambiguates the operation by making the constant expressions > > we pass here explicitly 'unsigned', which helps to avoid the warning. > > > > As pointed out by Hartley Sweeten, scripts/checkpatch.pl notices that > > the shifts here are rather unreadable, though the suggested BIT() > > macro wouldn't work either. I'm changing it to a hexadecimal notation, > > which hopefully improves readability. I'm leaving the DT2821_CHANCSR_PRESLA > > alone because it seems wrong. > > BIT() should work for the ones pointed out by checpatch.pl. > > I would argue that the hexadecimal notation is still rather unreadable. > These ones make my head hurt... > > -#define DT2821_ADCSR_GS(x) (((x) & 0x3) << 4) > +#define DT2821_ADCSR_GS(x) (0x0030u & ((x) << 4)) > > -#define DT2821_DACSR_YSEL(x) ((x) << 9) > +#define DT2821_DACSR_YSEL(x) (0x7e00u & (x) << 9) > > -#define DT2821_SUPCSR_DS_PIO (0 << 10) > -#define DT2821_SUPCSR_DS_AD_CLK (1 << 10) > -#define DT2821_SUPCSR_DS_DA_CLK (2 << 10) > -#define DT2821_SUPCSR_DS_AD_TRIG (3 << 10) > +#define DT2821_SUPCSR_DS_PIO (0x0c00u & (0u << 10)) > +#define DT2821_SUPCSR_DS_AD_CLK (0x0c00u & (1u << 10)) > +#define DT2821_SUPCSR_DS_DA_CLK (0x0c00u & (2u << 10)) > +#define DT2821_SUPCSR_DS_AD_TRIG (0x0c00u & (3u << 10)) Feel free to come up with a different patch. I've put the patch on my 'submitted' stack for now and will get back to it after 4.7-rc1 if the warning remains. > Also, most of the comedi drivers use the BIT() macro. Are you planning on > changing all of them to use hexadecimal notation? No. Arnd