Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755394AbbBDMOu (ORCPT ); Wed, 4 Feb 2015 07:14:50 -0500 Received: from smtp-out6.electric.net ([192.162.217.186]:50700 "EHLO smtp-out6.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751149AbbBDMOs convert rfc822-to-8bit (ORCPT ); Wed, 4 Feb 2015 07:14:48 -0500 X-Greylist: delayed 864 seconds by postgrey-1.27 at vger.kernel.org; Wed, 04 Feb 2015 07:14:47 EST From: David Laight To: "'Chen Gang S'" , Joe Perches CC: "marcel@holtmann.org" , "gustavo@padovan.org" , "johan.hedberg@gmail.com" , "David S. Miller" , "linux-bluetooth@vger.kernel.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v2] net: bluetooth: hci_sock: Use 'const void *' instead of 'void *' for 2nd parameter of hci_test_bit() Thread-Topic: [PATCH v2] net: bluetooth: hci_sock: Use 'const void *' instead of 'void *' for 2nd parameter of hci_test_bit() Thread-Index: AQHQP1yEeR6i5TQh3kGdfi5IMQnXPJzgaOLw Date: Wed, 4 Feb 2015 12:13:56 +0000 Message-ID: <063D6719AE5E284EB5DD2968C1650D6D1CADA609@AcuExch.aculab.com> References: <54CFE8BE.5030700@sunrus.com.cn> <1422912017.30476.28.camel@perches.com> <54D0332B.6050701@sunrus.com.cn> <54D03996.1070503@sunrus.com.cn> In-Reply-To: <54D03996.1070503@sunrus.com.cn> 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: 213.249.233.130 X-Env-From: David.Laight@ACULAB.COM X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2322 Lines: 60 From: Gang S > On 2/3/15 10:32, Chen Gang S wrote: > > On 2/3/15 05:20, Joe Perches wrote: > >> On Tue, 2015-02-03 at 05:14 +0800, Chen Gang S wrote: > >>> hci_test_bit() does not modify 2nd parameter, so it is better to let it > >>> be constant, or may cause build warning. The related warning (with > >>> allmodconfig under xtensa): > >> [] > >>> diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c > >> [] > >>> @@ -46,7 +46,7 @@ struct hci_pinfo { > >>> unsigned short channel; > >>> }; > >>> > >>> -static inline int hci_test_bit(int nr, void *addr) > >>> +static inline int hci_test_bit(int nr, const void *addr) > >>> { > >>> return *((__u32 *) addr + (nr >> 5)) & ((__u32) 1 << (nr & 31)); > >>> } > >> > >> It's probably better to use const __u32 * here too, but the > >> real thing I wonder is whether or not there's an issue with > >> one of the 2 uses of this function. > >> > >> One of them passes a unsigned long *, the other a u32 *. > >> > >> $ git grep -w hci_test_bit > >> net/bluetooth/hci_sock.c:static inline int hci_test_bit(int nr, void *addr) > >> net/bluetooth/hci_sock.c: if (!hci_test_bit(flt_event, &flt->event_mask)) > >> net/bluetooth/hci_sock.c: !hci_test_bit(ocf & HCI_FLT_OCF_BITS, > >> net/bluetooth/hci_sock.c- &hci_sec_filter.ocf_mask[ogf])) && > >> > >> hci_sec_filter.ocf_mask is __u32 > >> but flt->event_mask is unsigned long. > >> > >> Any possible issue here on 64-bit systems? > >> > > > > For me, it can not cause issue on 64-bit systems. hci_test_bit() treats > > 'addr' as "__u32 *", and has to use the pointer to do something. > > > > 'event_mask' is intended to type cast to "__u32 *" within 'hci_sock.c'. > So for me, "const __u32 *" is better than "const void *" for 2nd > parameter of hci_test_bit(). > > If what I said above is correct, and also if necessary, I shall patch v3 > for it. How are the bits set in the first place? If the array is ever indexed as long [] then the code above is unlikely to be testing the correct bits. David -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/