From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752470AbcHZNgM (ORCPT ); Fri, 26 Aug 2016 09:36:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44482 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751388AbcHZNgK (ORCPT ); Fri, 26 Aug 2016 09:36:10 -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: Date: Fri, 26 Aug 2016 09:35:11 -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: <1472186949-9025-1-git-send-email-christophe.jaillet@wanadoo.fr> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="fnBJqBvUmwftHaOPL5WTj8SdMj05qLgwe" X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 26 Aug 2016 13:35:29 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --fnBJqBvUmwftHaOPL5WTj8SdMj05qLgwe Content-Type: multipart/mixed; boundary="rTnBtUMRQKIIh5h1tUfPTpXfxH5juCXUk" From: Doug Ledford To: Christophe JAILLET , mike.marciniszyn@intel.com, dennis.dalessandro@intel.com, sean.hefty@intel.com, hal.rosenstock@gmail.com Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Message-ID: Subject: Re: [PATCH 1/2] IB/hfi1: Fix a parameter of find_first_bit. References: <1472186949-9025-1-git-send-email-christophe.jaillet@wanadoo.fr> In-Reply-To: <1472186949-9025-1-git-send-email-christophe.jaillet@wanadoo.fr> --rTnBtUMRQKIIh5h1tUfPTpXfxH5juCXUk Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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)? > It is likely that the number of bits of 'port_mask' was expected here. = This > variable is a 'u64', so use 64 instead. >=20 > It has been spotted by the following coccinelle script: > @@ > expression ret, x; >=20 > @@ > * ret =3D \(find_first_bit \| find_first_zero_bit\) (x, sizeof(...)); >=20 > Signed-off-by: Christophe JAILLET > --- > Not sure that using 64 directly is the best option. > Maybe '8 * sizeof(port_mask)' as used in the same file for > 'for_each_set_bit' would be better > --- > drivers/infiniband/hw/hfi1/mad.c | 12 ++++-------- > 1 file changed, 4 insertions(+), 8 deletions(-) >=20 > diff --git a/drivers/infiniband/hw/hfi1/mad.c b/drivers/infiniband/hw/h= fi1/mad.c > index 1263abe01999..2c6c138c41b2 100644 > --- a/drivers/infiniband/hw/hfi1/mad.c > +++ b/drivers/infiniband/hw/hfi1/mad.c > @@ -2632,8 +2632,7 @@ static int pma_get_opa_datacounters(struct opa_pm= a_mad *pmp, > * port the request came in on. > */ > port_mask =3D be64_to_cpu(req->port_select_mask[3]); > - port_num =3D find_first_bit((unsigned long *)&port_mask, > - sizeof(port_mask)); > + port_num =3D find_first_bit((unsigned long *)&port_mask, 64); > =20 > if ((u8)port_num !=3D port) { > pmp->mad_hdr.status |=3D IB_SMP_INVALID_FIELD; > @@ -2836,8 +2835,7 @@ static int pma_get_opa_porterrors(struct opa_pma_= mad *pmp, > * port the request came in on. > */ > port_mask =3D be64_to_cpu(req->port_select_mask[3]); > - port_num =3D find_first_bit((unsigned long *)&port_mask, > - sizeof(port_mask)); > + port_num =3D find_first_bit((unsigned long *)&port_mask, 64); > =20 > if (port_num !=3D port) { > pmp->mad_hdr.status |=3D IB_SMP_INVALID_FIELD; > @@ -3009,8 +3007,7 @@ static int pma_get_opa_errorinfo(struct opa_pma_m= ad *pmp, > * the request came in on. > */ > port_mask =3D be64_to_cpu(req->port_select_mask[3]); > - port_num =3D find_first_bit((unsigned long *)&port_mask, > - sizeof(port_mask)); > + port_num =3D find_first_bit((unsigned long *)&port_mask, 64); > =20 > if (port_num !=3D port) { > pmp->mad_hdr.status |=3D IB_SMP_INVALID_FIELD; > @@ -3246,8 +3243,7 @@ static int pma_set_opa_errorinfo(struct opa_pma_m= ad *pmp, > * the request came in on. > */ > port_mask =3D be64_to_cpu(req->port_select_mask[3]); > - port_num =3D find_first_bit((unsigned long *)&port_mask, > - sizeof(port_mask)); > + port_num =3D find_first_bit((unsigned long *)&port_mask, 64); > =20 > if (port_num !=3D port) { > pmp->mad_hdr.status |=3D IB_SMP_INVALID_FIELD; >=20 --=20 Doug Ledford GPG Key ID: 0E572FDD --rTnBtUMRQKIIh5h1tUfPTpXfxH5juCXUk-- --fnBJqBvUmwftHaOPL5WTj8SdMj05qLgwe Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJXwEWPAAoJELgmozMOVy/dXuUP/0Ov1Px+WSZw+dY9zs/W+ej7 uNl2aMEI44+gsqeP9CbFuDZ82PXgcF/OWnoJMfHVyh5dHYDUNr8Jp7aJp5Pdz4qx xUWPYH66t6GnTERr99x8PYwoHO9yMJ9BnYEFUA8ABZAsjk41dKhWsjXZNUOOQ863 Nyi3HeQ+lkCJLNVRV05pGNrvNiC+prCGt3toe35ZuA58PDbQqS+1Fs7JJGAUR7mE rd8BfmAN2Ef6DZHSteFrwkOjOw/Ee08atjOTI/wPaOkbSItwEByG7INRwB3Q+Z2h e4em55OMN6e60YmsfC7tY5e1SmxuU8zRDFw09LFEb92Z5C9dfdzroKRyT+dPNvDi KPq0i3/yrsqHFH3Y+03fxQTWHGugjFBQrQfUcWksV/yFvzx/L5xK1iTow7tDs27N EriXpnyw+Y15pJo5IzHl0bat6cWzm/v7GLn2APyihGQ9dUc65mSnUf9JS+vWBQ0T Zk+fAl34tTFaxnxvDuGBBOdqHw7zj/rg3YVp7yKbuppg1YGGLwaV5ZkZo59HONBg dNtObKRHY62w4ty6fIfZPZA2OnI/qdvxrOIRXKLnGu9hcEILxdMOAh2ysKpenVro c05IeP5nKkZ6yXZAYNQla3YUtYmro6mtRj0LkdUhRjFo5TaZ0HWtA7j5Nn/SRdkW OTLQR9mU3rpXL4DFPZsn =oxoL -----END PGP SIGNATURE----- --fnBJqBvUmwftHaOPL5WTj8SdMj05qLgwe--