From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Subject: Re: [PATCH 6/7] media: don't do an unsigned int with a 31 bit shift Date: Thu, 29 Aug 2019 10:03:09 -0700 Message-ID: <201908291002.2F67F5ADA@keescook> References: <4a411ba155eb062b6575aba0824123c840806c0b.1566502743.git.mchehab+samsung@kernel.org> <1a78a757b37d2628312e1d56d7a741ba89d42a91.1566502743.git.mchehab+samsung@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1a78a757b37d2628312e1d56d7a741ba89d42a91.1566502743.git.mchehab+samsung@kernel.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org To: Mauro Carvalho Chehab Cc: Kate Stewart , Kamil Debski , Hans Verkuil , Andrzej Hajda , "Lad, Prabhakar" , Bluecherry Maintainers , Krzysztof Kozlowski , Sylwester Nawrocki , Nathan Chancellor , Andrzej Pietrasiewicz , Anton Sviridenko , Ezequiel Garcia , Andrey Utkin , Antti Palosaari , Steve Longerbeam , Ismael Luceno , Linux Media Mailing List , linux-arm-msm@vger.kernel.org, Stanimir Varbanov , Jeongtae Park , linux-samsung-soc@vger.kern List-Id: linux-samsung-soc@vger.kernel.org On Thu, Aug 22, 2019 at 04:39:33PM -0300, Mauro Carvalho Chehab wrote: > Doing something like: > > i32 foo = 1, bar; > > bar = foo << 31; > > has an undefined behavior in C, as warned by cppcheck, as we're > shifting a signed integer. > > Instead, force the numbers to be unsigned, in order to solve this > issue. I also recommend using the BIT() macro, which does the ULing correctly, etc. i.e. instead of: - keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0; + keyup = (gpio & ir->mask_keyup) ? 1UL << 31 : 0; use: - keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0; + keyup = (gpio & ir->mask_keyup) ? BIT(31) : 0; -- Kees Cook