Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751475AbbEFPpU (ORCPT ); Wed, 6 May 2015 11:45:20 -0400 Received: from p3plex2out03.prod.phx3.secureserver.net ([184.168.131.16]:54562 "EHLO p3plex2out03.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750930AbbEFPpS (ORCPT ); Wed, 6 May 2015 11:45:18 -0400 From: Hartley Sweeten To: nick , Ian Abbott CC: "gregkh@linuxfoundation.org" , "chase.southwood@gmail.com" , "ebru.akagunduz@gmail.com" , "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" Subject: RE: Question about the function,ni_stc_dma_channel_select_bitfield Thread-Topic: Question about the function,ni_stc_dma_channel_select_bitfield Thread-Index: AQHQh5KtuLnXsSgMFUWyLailQGvtWJ1vH0uAgABScYD//6WfwA== Date: Wed, 6 May 2015 15:45:17 +0000 Message-ID: References: <55495EA8.2090902@gmail.com> <5549DA9B.6030700@mev.co.uk> <554A1FC3.3000409@gmail.com> In-Reply-To: <554A1FC3.3000409@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [184.183.19.121] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id t46FjPet014106 Content-Length: 996 Lines: 25 On Wednesday, May 06, 2015 7:06 AM, nick wrote: > On 2015-05-06 05:10 AM, Ian Abbott wrote: >> On 06/05/15 01:22, nick wrote: >>> Greetings All, >>> I am wondering if in the function,ni_stc_dma_channel_select_bitfield the line: >>> return 1 << channel; >>> is guaranteed to be below the threshold that guarantees us to not overflow on >>> a unsigned 32 integer due to bit wise shifting to the left. >>> Thanks Nick >>> >> >> if (channel < 4) >> return 1 << channel; >> >> So, yes. >> > This should be commented in my option as this is not common knowledge > unless you known the hardware specs really well. If I should send in > a patch adding a comment here please let me known. A comment is not necessary. The code explicitly states that channel (an unsigned var) needs to be < 4 for the bit shift to happen. Hartley ????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?