From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751676AbdKUQMR (ORCPT ); Tue, 21 Nov 2017 11:12:17 -0500 Received: from smtprelay0086.hostedemail.com ([216.40.44.86]:57376 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751502AbdKUQMO (ORCPT ); Tue, 21 Nov 2017 11:12:14 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::,RULES_HIT:41:196:355:379:541:599:800:960:966:967:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1622:1711:1730:1747:1777:1792:2196:2199:2393:2525:2553:2560:2563:2682:2685:2828:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3355:3622:3865:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4605:5007:6119:6671:7875:7903:8603:9025:10004:10400:10848:11026:11232:11473:11658:11914:12043:12114:12296:12438:12555:12740:12760:12895:12986:13007:13439:14093:14097:14181:14659:14721:21080:21324:21451:21627:30012:30054:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: owner35_6a7b638574f33 X-Filterd-Recvd-Size: 3894 Message-ID: <1511280730.6989.30.camel@perches.com> Subject: Re: [PATCH] PCI: designware-ep: use ffz() instead of find_first_zero_bit() From: Joe Perches To: Lorenzo Pieralisi , Niklas Cassel Cc: Jingoo Han , Joao Pinto , Bjorn Helgaas , Niklas Cassel , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 21 Nov 2017 08:12:10 -0800 In-Reply-To: <20171117113835.GB21148@red-moon> References: <20171116183438.12613-1-niklas.cassel@axis.com> <20171117113835.GB21148@red-moon> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2017-11-17 at 11:38 +0000, Lorenzo Pieralisi wrote: > Please follow Bjorn's request for patch formatting: > > https://marc.info/?l=linux-pci&m=150905742808166&w=2 > > I would mention in the commit title that this is a fix. > > eg "PCI: designware-ep: Fix find_first_zero_bit() usage" > > On Thu, Nov 16, 2017 at 07:34:38PM +0100, Niklas Cassel wrote: > > find_first_zero_bit()'s parameter 'size' is defined in bits, > > not in bytes. > > > > find_first_zero_bit() was called with bytes rather than bits, > > "was called with size in bytes"... This code also uses set_bit/clear_bit. I suggest not intermixing set_bit/clear_bit calls and ffz on the same object. Use either (&/~/ffz) or (set_bit/clear_bit/find_first_zero_bit) BITS_PER_LONG would work fine for find_first_zero_bit > > which thus defined a too low upper limit, causing > > dw_pcie_ep_inbound_atu() to assign iatu index #4 to both bar 4 > > and bar 5, which made bar 5 overwrite the settings set by bar 4. > > > > ./pcitest.sh > > BAR tests > > BAR0: OKAY > > BAR1: OKAY > > BAR2: OKAY > > BAR3: OKAY > > BAR4: NOT OKAY > > BAR5: OKAY > > Sorry but this example is pretty much useless - either you add > a self-explanatory kernel log or you just remove it. > > > 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 > > We need a Fixes: tag at least, see Bjorn's post above. > > Thanks, > Lorenzo > > > --- > > drivers/pci/dwc/pcie-designware-ep.c | 6 ++---- > > 1 file changed, 2 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/pci/dwc/pcie-designware-ep.c b/drivers/pci/dwc/pcie-designware-ep.c > > index d53d5f168363..ab9a9e160daf 100644 > > --- a/drivers/pci/dwc/pcie-designware-ep.c > > +++ b/drivers/pci/dwc/pcie-designware-ep.c > > @@ -70,8 +70,7 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, enum pci_barno bar, > > u32 free_win; > > struct dw_pcie *pci = to_dw_pcie_from_ep(ep); > > > > - free_win = find_first_zero_bit(&ep->ib_window_map, > > - sizeof(ep->ib_window_map)); > > + free_win = ffz(ep->ib_window_map); > > if (free_win >= ep->num_ib_windows) { > > dev_err(pci->dev, "no free inbound window\n"); > > return -EINVAL; > > @@ -96,8 +95,7 @@ static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, phys_addr_t phys_addr, > > u32 free_win; > > struct dw_pcie *pci = to_dw_pcie_from_ep(ep); > > > > - free_win = find_first_zero_bit(&ep->ob_window_map, > > - sizeof(ep->ob_window_map)); > > + free_win = ffz(ep->ob_window_map); > > if (free_win >= ep->num_ob_windows) { > > dev_err(pci->dev, "no free outbound window\n"); > > return -EINVAL; > > -- > > 2.14.2 > >