From patchwork Fri Aug 26 18:01:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Ledford X-Patchwork-Id: 9301861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D18E60757 for ; Fri, 26 Aug 2016 18:02:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7518029648 for ; Fri, 26 Aug 2016 18:02:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 692E52964A; Fri, 26 Aug 2016 18:02:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E20B29648 for ; Fri, 26 Aug 2016 18:02:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753132AbcHZSCP (ORCPT ); Fri, 26 Aug 2016 14:02:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40466 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751527AbcHZSCO (ORCPT ); Fri, 26 Aug 2016 14:02:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E55888F227; Fri, 26 Aug 2016 18:02:13 +0000 (UTC) Received: from [172.31.1.2] (ovpn-116-61.rdu2.redhat.com [10.10.116.61]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7QI2C5g032765 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 26 Aug 2016 14:02:12 -0400 Subject: Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. To: Christophe JAILLET , mike.marciniszyn@intel.com, dennis.dalessandro@intel.com, sean.hefty@intel.com, hal.rosenstock@gmail.com References: <1472186949-9025-1-git-send-email-christophe.jaillet@wanadoo.fr> Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org From: Doug Ledford Message-ID: <2c923344-04c8-cdbd-ac06-047027f7a23a@redhat.com> Date: Fri, 26 Aug 2016 14:01:55 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 26 Aug 2016 18:02:14 +0000 (UTC) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 8/26/2016 9:35 AM, Doug Ledford wrote: > On 8/26/2016 12:49 AM, Christophe JAILLET wrote: >> The 2nd parameter of 'find_first_bit' is the number of bits to search. >> In this case, we are passing 'sizeof(unsigned long)' which is likely to >> be 4 or 8. > > If the size can be 4 or 8, then using 64 universally is not correct. > Why not use sizeof() * 8 (or << 3)? Better yet, why not put this patch in the kernel first: typecheck(u64, x); \ then start going around replacing all these hard coded numbers with the use of bitsizeof(). It can be applied not just to the find_first*bit() routines, but to a bunch of other routines too. Just look at include/linux/bitmap.h and any that have nbits as an argument are candidates. diff --git a/include/linux/kernel.h b/include/linux/kernel.h index d96a6118d26a..a8838c87668e 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -52,6 +52,8 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) +#define bitsizeof(x) (sizeof((x)) << 3) + #define u64_to_user_ptr(x) ( \ { \