From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FAKE_REPLY_C,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 737B9C4360C for ; Fri, 27 Sep 2019 12:39:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4719C217D9 for ; Fri, 27 Sep 2019 12:39:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569587956; bh=uPN9RyW4YW0TDfK8hXhtBneW2YpzqT6rO2P64YR4jtY=; h=Date:From:To:Cc:Subject:In-Reply-To:List-ID:From; b=a3L8EcvdDNcOXlHiDX6hmH7WRlLQLJBtx+9bcwrfiL68y4sy8lvLXjOKNq6hmF4Re 3FiZmnyZdw6JC672N4SJwAyWNtO2D1Nj0j3763BPqO3PzZ05ZU7mCPv4V0nCO4EfS9 cq0/iPwIbdgMDVX+azjCUTwZrV0mAx/qQzddzuL8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726251AbfI0MjP (ORCPT ); Fri, 27 Sep 2019 08:39:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:44970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbfI0MjP (ORCPT ); Fri, 27 Sep 2019 08:39:15 -0400 Received: from localhost (173-25-179-30.client.mchsi.com [173.25.179.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B22220673; Fri, 27 Sep 2019 12:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569587954; bh=uPN9RyW4YW0TDfK8hXhtBneW2YpzqT6rO2P64YR4jtY=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=NRxnvfmzKHdgaIuyshJwcS0iwIlp5AAK4eN8sypPK8Ovxr4/eroGgPG1+r5sQRX7A 3KFWMi6wdJsgsMRQZWfdUebtvWDnQbLYtSudyqLNLDHco79brtd4IujFXnsszDhK1L GxWTS19cUuSFAcz9fNLMQ7IHk+eLiCOA06ig3lP0= Date: Fri, 27 Sep 2019 07:39:13 -0500 From: Bjorn Helgaas To: Andy Shevchenko Cc: Russell Currey , Sam Bobroff , Oliver O'Halloran , linuxppc-dev@lists.ozlabs.org, linux-pci@vger.kernel.org Subject: Re: [PATCH v1 1/2] PCI/AER: Use for_each_set_bit() Message-ID: <20190927123913.GA32321@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190827151823.75312-1-andriy.shevchenko@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Tue, Aug 27, 2019 at 06:18:22PM +0300, Andy Shevchenko wrote: > This simplifies and standardizes slot manipulation code > by using for_each_set_bit() library function. > > Signed-off-by: Andy Shevchenko > --- > drivers/pci/pcie/aer.c | 19 ++++++++----------- > 1 file changed, 8 insertions(+), 11 deletions(-) > > diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c > index b45bc47d04fe..f883f81d759a 100644 > --- a/drivers/pci/pcie/aer.c > +++ b/drivers/pci/pcie/aer.c > @@ -15,6 +15,7 @@ > #define pr_fmt(fmt) "AER: " fmt > #define dev_fmt pr_fmt > > +#include > #include > #include > #include > @@ -657,7 +658,8 @@ const struct attribute_group aer_stats_attr_group = { > static void pci_dev_aer_stats_incr(struct pci_dev *pdev, > struct aer_err_info *info) > { > - int status, i, max = -1; > + unsigned long status = info->status & ~info->mask; > + int i, max = -1; > u64 *counter = NULL; > struct aer_stats *aer_stats = pdev->aer_stats; > > @@ -682,10 +684,8 @@ static void pci_dev_aer_stats_incr(struct pci_dev *pdev, > break; > } > > - status = (info->status & ~info->mask); > - for (i = 0; i < max; i++) > - if (status & (1 << i)) > - counter[i]++; > + for_each_set_bit(i, &status, max) I applied this, but I confess to being a little ambivalent. It's arguably a little easier to read, but it's not nearly as efficient (not a great concern here) and more importantly much harder to verify that it's correct because you have to chase through for_each_set_bit(), find_first_bit(), _ffs(), etc, etc. No doubt it's great for bitmaps of arbitrary size, but for a simple 32-bit register I'm a little hesitant. But I applied it anyway. > + counter[i]++; > } > > static void pci_rootport_aer_stats_incr(struct pci_dev *pdev, > @@ -717,14 +717,11 @@ static void __print_tlp_header(struct pci_dev *dev, > static void __aer_print_error(struct pci_dev *dev, > struct aer_err_info *info) > { > - int i, status; > + unsigned long status = info->status & ~info->mask; > const char *errmsg = NULL; > - status = (info->status & ~info->mask); > - > - for (i = 0; i < 32; i++) { > - if (!(status & (1 << i))) > - continue; > + int i; > > + for_each_set_bit(i, &status, 32) { > if (info->severity == AER_CORRECTABLE) > errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ? > aer_correctable_error_string[i] : NULL; > -- > 2.23.0.rc1 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, FAKE_REPLY_C,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B0CDC4360C for ; Fri, 27 Sep 2019 12:41:48 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D085220673 for ; Fri, 27 Sep 2019 12:41:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="NRxnvfmz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D085220673 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46fryc4LShzDr28 for ; Fri, 27 Sep 2019 22:41:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=kernel.org (client-ip=198.145.29.99; helo=mail.kernel.org; envelope-from=helgaas@kernel.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="NRxnvfmz"; dkim-atps=neutral Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46frvn6XqrzDqv3 for ; Fri, 27 Sep 2019 22:39:17 +1000 (AEST) Received: from localhost (173-25-179-30.client.mchsi.com [173.25.179.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B22220673; Fri, 27 Sep 2019 12:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569587954; bh=uPN9RyW4YW0TDfK8hXhtBneW2YpzqT6rO2P64YR4jtY=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=NRxnvfmzKHdgaIuyshJwcS0iwIlp5AAK4eN8sypPK8Ovxr4/eroGgPG1+r5sQRX7A 3KFWMi6wdJsgsMRQZWfdUebtvWDnQbLYtSudyqLNLDHco79brtd4IujFXnsszDhK1L GxWTS19cUuSFAcz9fNLMQ7IHk+eLiCOA06ig3lP0= Date: Fri, 27 Sep 2019 07:39:13 -0500 From: Bjorn Helgaas To: Andy Shevchenko Subject: Re: [PATCH v1 1/2] PCI/AER: Use for_each_set_bit() Message-ID: <20190927123913.GA32321@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190827151823.75312-1-andriy.shevchenko@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sam Bobroff , linuxppc-dev@lists.ozlabs.org, Oliver O'Halloran , linux-pci@vger.kernel.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, Aug 27, 2019 at 06:18:22PM +0300, Andy Shevchenko wrote: > This simplifies and standardizes slot manipulation code > by using for_each_set_bit() library function. > > Signed-off-by: Andy Shevchenko > --- > drivers/pci/pcie/aer.c | 19 ++++++++----------- > 1 file changed, 8 insertions(+), 11 deletions(-) > > diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c > index b45bc47d04fe..f883f81d759a 100644 > --- a/drivers/pci/pcie/aer.c > +++ b/drivers/pci/pcie/aer.c > @@ -15,6 +15,7 @@ > #define pr_fmt(fmt) "AER: " fmt > #define dev_fmt pr_fmt > > +#include > #include > #include > #include > @@ -657,7 +658,8 @@ const struct attribute_group aer_stats_attr_group = { > static void pci_dev_aer_stats_incr(struct pci_dev *pdev, > struct aer_err_info *info) > { > - int status, i, max = -1; > + unsigned long status = info->status & ~info->mask; > + int i, max = -1; > u64 *counter = NULL; > struct aer_stats *aer_stats = pdev->aer_stats; > > @@ -682,10 +684,8 @@ static void pci_dev_aer_stats_incr(struct pci_dev *pdev, > break; > } > > - status = (info->status & ~info->mask); > - for (i = 0; i < max; i++) > - if (status & (1 << i)) > - counter[i]++; > + for_each_set_bit(i, &status, max) I applied this, but I confess to being a little ambivalent. It's arguably a little easier to read, but it's not nearly as efficient (not a great concern here) and more importantly much harder to verify that it's correct because you have to chase through for_each_set_bit(), find_first_bit(), _ffs(), etc, etc. No doubt it's great for bitmaps of arbitrary size, but for a simple 32-bit register I'm a little hesitant. But I applied it anyway. > + counter[i]++; > } > > static void pci_rootport_aer_stats_incr(struct pci_dev *pdev, > @@ -717,14 +717,11 @@ static void __print_tlp_header(struct pci_dev *dev, > static void __aer_print_error(struct pci_dev *dev, > struct aer_err_info *info) > { > - int i, status; > + unsigned long status = info->status & ~info->mask; > const char *errmsg = NULL; > - status = (info->status & ~info->mask); > - > - for (i = 0; i < 32; i++) { > - if (!(status & (1 << i))) > - continue; > + int i; > > + for_each_set_bit(i, &status, 32) { > if (info->severity == AER_CORRECTABLE) > errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ? > aer_correctable_error_string[i] : NULL; > -- > 2.23.0.rc1 >