From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752262AbdKUNBd convert rfc822-to-8bit (ORCPT ); Tue, 21 Nov 2017 08:01:33 -0500 Received: from smtp-out4.electric.net ([192.162.216.195]:56774 "EHLO smtp-out4.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752126AbdKUNBc (ORCPT ); Tue, 21 Nov 2017 08:01:32 -0500 From: David Laight To: "'Niklas Cassel'" , Kishon Vijay Abraham I , Lorenzo Pieralisi , Bjorn Helgaas CC: Niklas Cassel , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] PCI: endpoint: use ffz() instead of find_first_zero_bit() Thread-Topic: [PATCH] PCI: endpoint: use ffz() instead of find_first_zero_bit() Thread-Index: AQHTX4iIdvZMHjcMYUeWFp7iwt3GjaMe0gjg Date: Tue, 21 Nov 2017 13:01:48 +0000 Message-ID: <5d80ad3162fb4d02aac25f510b94d6c4@AcuMS.aculab.com> References: <20171117094248.15265-1-niklas.cassel@axis.com> In-Reply-To: <20171117094248.15265-1-niklas.cassel@axis.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted 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: 156.67.243.126 X-Env-From: David.Laight@ACULAB.COM X-Proto: esmtps X-Revdns: X-HELO: AcuMS.aculab.com X-TLS: TLSv1.2:ECDHE-RSA-AES256-SHA384:256 X-Authenticated_ID: X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Niklas Cassel > Sent: 17 November 2017 09:43 > find_first_zero_bit()'s parameter 'size' is defined in bits, > not in bytes. > > Calling find_first_zero_bit() with the wrong size unit > will lead to insidious bugs. > > Fix this by using replacing find_first_zero_bit() with ffz(), > since ffz() only works on a single 'unsigned long' and therefore > does not need a size argument. > > Signed-off-by: Niklas Cassel > --- > drivers/pci/endpoint/pci-ep-cfs.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/pci/endpoint/pci-ep-cfs.c b/drivers/pci/endpoint/pci-ep-cfs.c > index 4f74386c1ced..96b984685640 100644 > --- a/drivers/pci/endpoint/pci-ep-cfs.c > +++ b/drivers/pci/endpoint/pci-ep-cfs.c > @@ -108,8 +108,7 @@ static int pci_epc_epf_link(struct config_item *epc_item, > if (ret) > goto err_add_epf; > > - func_no = find_first_zero_bit(&epc_group->function_num_map, > - sizeof(epc_group->function_num_map)); > + func_no = ffz(epc_group->function_num_map); > set_bit(func_no, &epc_group->function_num_map); > epf->func_no = func_no; Is set_bit() now setting the correct bit? I'd guess that: epc_group->function_num_map |= 1ul << func_no; would be more accurate? David