From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Subject: Re: [PATCH v8 0/7] Add pci_dev_for_each_resource() helper and update users Date: Mon, 5 Jun 2023 17:04:05 +0300 Message-ID: References: Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685974074; x=1717510074; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=zjA9XYetqLmj2er7YOpXmYqZcR8z8Fh+g5Flt9xdytk=; b=V1qpbe5GCXcEd+WXHjE2Ec4+yeFaghq8tJf9dtaC3jkyU3cCzaltWhl/ 0yBrMSrDL6PrLWPfMkwu8ZQIJlzqliPZE5xKanBO+8dzTb8l7sM4c4FdX 2P1sbRmKVO54MnkxedJW4W/mSeBPHkKvg3RSv1pCF+reZqNb8BhkjOvMT FOsFncTrSHbTEmQrs79O7ZFmG4OMncKlgBIRFpp3CrFSOC6wEYtYSlDYP nwG871Y1qA7zQorEVJvOE7xdEhFlaKqY0DXjK/GInYwtgPxHoNjZDFw0V s2CHloMK1bWA8cvcvXBOh/F0Wb4hg46X5NHVJRNj0VQlnmDjZPhpB77Gv A==; Content-Disposition: inline In-Reply-To: List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+glppe-linuxppc-embedded-2=m.gmane-mx.org@lists.ozlabs.org Sender: "Linuxppc-dev" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Bjorn Helgaas Cc: Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rich Felker , linux-sh@vger.kernel.org, linux-pci@vger.kernel.org, Dominik Brodowski , linux-mips@vger.kernel.org, Bjorn Helgaas , Andrew Lunn , Jonas Gorski , sparclinux@vger.kernel.org, Stefano Stabellini , Yoshinori Sato , Gregory Clement , "Rafael J. Wysocki" , Russell King , linux-acpi@vger.kernel.org, Miguel Ojeda , xen-devel@lists.xenproject.org, Matt Turner , Anatolij Gustschin , Sebastian Hesselbarth , Arn d Bergmann , Niklas Schnelle , Richard Henderson On Wed, May 31, 2023 at 04:30:28PM -0500, Bjorn Helgaas wrote: > On Wed, May 31, 2023 at 08:48:35PM +0200, Jonas Gorski wrote: ... > > Looking at the code I understand where coverity is coming from: > > > > #define __pci_dev_for_each_res0(dev, res, ...) \ > > for (unsigned int __b = 0; \ > > res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \ > > __b++) > > > > res will be assigned before __b is checked for being less than > > PCI_NUM_RESOURCES, making it point to behind the array at the end of > > the last loop iteration. > > > > Rewriting the test expression as > > > > __b < PCI_NUM_RESOURCES && (res = pci_resource_n(dev, __b)); > > > > should avoid the (coverity) warning by making use of lazy evaluation. > > > > It probably makes the code slightly less performant as res will now be > > checked for being not NULL (which will always be true), but I doubt it > > will be significant (or in any hot paths). > > Thanks a lot for looking into this! I think you're right, and I think > the rewritten expression is more logical as well. Do you want to post > a patch for it? Gimme some time, I was on a long leave and now it's a pile to handle. -- With Best Regards, Andy Shevchenko 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0001CC7EE2C for ; Mon, 5 Jun 2023 14:08:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234277AbjFEOIU (ORCPT ); Mon, 5 Jun 2023 10:08:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234298AbjFEOH7 (ORCPT ); Mon, 5 Jun 2023 10:07:59 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C8F2E5C; Mon, 5 Jun 2023 07:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685974071; x=1717510071; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=zjA9XYetqLmj2er7YOpXmYqZcR8z8Fh+g5Flt9xdytk=; b=O96WqxzlUCNQyd33mgmV+U+gO7Lgr+/55QF6BKqVKFY53MIvHhzdcl4N xdGbsU6vvWdH65EhEc1Dup08XLUzSGM/ENIdjVfI38q1DmbrtZ7RqIXSU XFhU8HQpR0b9EMsblU4xIi2zBUPnZaOK6MXv7t6Th5nf7GVtcKncqMWRs 2pA+rVgzMjtJx8OUe2PgpIprtmvCUcz6OINPgM06ruHWparvphAN7ftf2 GODvFHSgy+5VSlcBcv7oGKlEdMT2nWOvsjhUn0zTnzNTLi57F2vd8qIMa fuMqRNsqppppAcn0BAHJHrQ7FODn+RVT8PBKus4oetqfPBskfYs5StpT2 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="335993888" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="335993888" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 07:04:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="882915325" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="882915325" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga005.jf.intel.com with ESMTP; 05 Jun 2023 07:04:09 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1q6AoX-001O9h-1D; Mon, 05 Jun 2023 17:04:05 +0300 Date: Mon, 5 Jun 2023 17:04:05 +0300 From: Andy Shevchenko To: Bjorn Helgaas Cc: Jonas Gorski , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Rich Felker , linux-sh@vger.kernel.org, Dominik Brodowski , Andrew Lunn , sparclinux@vger.kernel.org, Stefano Stabellini , Yoshinori Sato , Gregory Clement , "Rafael J. Wysocki" , Russell King , linux-acpi@vger.kernel.org, Miguel Ojeda , xen-devel@lists.xenproject.org, Matt Turner , Anatolij Gustschin , Sebastian Hesselbarth , Arnd Bergmann , Niklas Schnelle , Richard Henderson , Nicholas Piggin , Ivan Kokshaysky , John Paul Adrian Glaubitz , Bjorn Helgaas , Mika Westerberg , linux-arm-kernel@lists.infradead.org, Juergen Gross , Thomas Bogendoerfer , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , linuxppc-dev@lists.ozlabs.org, Randy Dunlap , linux-mips@vger.kernel.org, Oleksandr Tyshchenko , linux-alpha@vger.kernel.org, Pali =?iso-8859-1?Q?Roh=E1r?= , "David S. Miller" , "Maciej W. Rozycki" Subject: Re: [PATCH v8 0/7] Add pci_dev_for_each_resource() helper and update users Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Wed, May 31, 2023 at 04:30:28PM -0500, Bjorn Helgaas wrote: > On Wed, May 31, 2023 at 08:48:35PM +0200, Jonas Gorski wrote: ... > > Looking at the code I understand where coverity is coming from: > > > > #define __pci_dev_for_each_res0(dev, res, ...) \ > > for (unsigned int __b = 0; \ > > res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \ > > __b++) > > > > res will be assigned before __b is checked for being less than > > PCI_NUM_RESOURCES, making it point to behind the array at the end of > > the last loop iteration. > > > > Rewriting the test expression as > > > > __b < PCI_NUM_RESOURCES && (res = pci_resource_n(dev, __b)); > > > > should avoid the (coverity) warning by making use of lazy evaluation. > > > > It probably makes the code slightly less performant as res will now be > > checked for being not NULL (which will always be true), but I doubt it > > will be significant (or in any hot paths). > > Thanks a lot for looking into this! I think you're right, and I think > the rewritten expression is more logical as well. Do you want to post > a patch for it? Gimme some time, I was on a long leave and now it's a pile to handle. -- With Best Regards, Andy Shevchenko 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 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA3BDC7EE23 for ; Mon, 5 Jun 2023 14:08:44 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4QZb7H2zhkz3f7F for ; Tue, 6 Jun 2023 00:08:43 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=V1qpbe5G; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.helo=mga12.intel.com (client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=andriy.shevchenko@linux.intel.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=V1qpbe5G; dkim-atps=neutral Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (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 4QZb6L33vlz3dxf for ; Tue, 6 Jun 2023 00:07:52 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685974074; x=1717510074; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=zjA9XYetqLmj2er7YOpXmYqZcR8z8Fh+g5Flt9xdytk=; b=V1qpbe5GCXcEd+WXHjE2Ec4+yeFaghq8tJf9dtaC3jkyU3cCzaltWhl/ 0yBrMSrDL6PrLWPfMkwu8ZQIJlzqliPZE5xKanBO+8dzTb8l7sM4c4FdX 2P1sbRmKVO54MnkxedJW4W/mSeBPHkKvg3RSv1pCF+reZqNb8BhkjOvMT FOsFncTrSHbTEmQrs79O7ZFmG4OMncKlgBIRFpp3CrFSOC6wEYtYSlDYP nwG871Y1qA7zQorEVJvOE7xdEhFlaKqY0DXjK/GInYwtgPxHoNjZDFw0V s2CHloMK1bWA8cvcvXBOh/F0Wb4hg46X5NHVJRNj0VQlnmDjZPhpB77Gv A==; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="335993892" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="335993892" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 07:04:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="882915325" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="882915325" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga005.jf.intel.com with ESMTP; 05 Jun 2023 07:04:09 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1q6AoX-001O9h-1D; Mon, 05 Jun 2023 17:04:05 +0300 Date: Mon, 5 Jun 2023 17:04:05 +0300 From: Andy Shevchenko To: Bjorn Helgaas Subject: Re: [PATCH v8 0/7] Add pci_dev_for_each_resource() helper and update users Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo 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: Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rich Felker , linux-sh@vger.kernel.org, linux-pci@vger.kernel.org, Dominik Brodowski , linux-mips@vger.kernel.org, Bjorn Helgaas , Andrew Lunn , Jonas Gorski , sparclinux@vger.kernel.org, Stefano Stabellini , Yoshinori Sato , Gregory Clement , "Rafael J. Wysocki" , Russell King , linux-acpi@vger.kernel.org, Miguel Ojeda , xen-devel@lists.xenproject.org, Matt Turner , Anatolij Gustschin , Sebastian Hesselbarth , Arnd Bergmann , Niklas Schnelle , Richard Henderson , Nicholas Piggin , Ivan Kokshaysky , John Paul Adrian Glaubitz , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Mika Westerberg , linux-arm-kernel@lists.infradead.org, Juergen Gross , Thomas Bogendoerfer , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , Pali =?iso-8859-1?Q?Roh=E1r?= , Randy Dunlap , linux-kernel@vger.kernel.org, Oleksandr Tyshchenko , linux-alpha@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, "David S. Miller" , "Maciej W. Rozycki" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Wed, May 31, 2023 at 04:30:28PM -0500, Bjorn Helgaas wrote: > On Wed, May 31, 2023 at 08:48:35PM +0200, Jonas Gorski wrote: ... > > Looking at the code I understand where coverity is coming from: > > > > #define __pci_dev_for_each_res0(dev, res, ...) \ > > for (unsigned int __b = 0; \ > > res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \ > > __b++) > > > > res will be assigned before __b is checked for being less than > > PCI_NUM_RESOURCES, making it point to behind the array at the end of > > the last loop iteration. > > > > Rewriting the test expression as > > > > __b < PCI_NUM_RESOURCES && (res = pci_resource_n(dev, __b)); > > > > should avoid the (coverity) warning by making use of lazy evaluation. > > > > It probably makes the code slightly less performant as res will now be > > checked for being not NULL (which will always be true), but I doubt it > > will be significant (or in any hot paths). > > Thanks a lot for looking into this! I think you're right, and I think > the rewritten expression is more logical as well. Do you want to post > a patch for it? Gimme some time, I was on a long leave and now it's a pile to handle. -- With Best Regards, Andy Shevchenko 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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8919C77B73 for ; Mon, 5 Jun 2023 14:08:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a0cDPiClEzjpeVNi4UCP8YMw4jmYqtH6Ky99gefrjBI=; b=2hfGgVxQQ3BpKk +ZbUxRD2eh3L1jMSh3nHQYS4hZ9ATOmrPE5EjocF0TTUuokTS3iz5pYM9w6TEyXfTSuEiDE0hkqvc AqOKXRF362U2ksgisNXAOt4VpwIyEfDMGDmmskSDsYDjQQEMOBUa8iEksSaomO+aYDujvlsUJmF8M qpKhYcCeQFBXFTXWDrqV9a8gJFgPEGKiarkViqx2ZJ/f6lQm6ky5YREbToxs3gD8U9e6yAPr/Qy3M Qj3JzjrGTDqIeQQ0uhT3VHmECDvla5Z7Y11T4j45kUsL5lCDCw5Non+tt83Z63rIgY/8IoW9ftNLg JbIyf8H+bllADgXCn4bA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6AsF-00FjKX-2F; Mon, 05 Jun 2023 14:07:55 +0000 Received: from mga12.intel.com ([192.55.52.136]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6AsC-00FjJG-2h for linux-arm-kernel@lists.infradead.org; Mon, 05 Jun 2023 14:07:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685974072; x=1717510072; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=zjA9XYetqLmj2er7YOpXmYqZcR8z8Fh+g5Flt9xdytk=; b=HcTVvY5z44/fV6vkXCMgBdmW1cEmeinz6+QdLqUT4x0C9Iteb6yaxbok Ax1FrLK0lLeVXs3z1AP8rXBSywLJlnEYKwvHhGB3dkghwSv8yUmURJnYd sCqtPDBKeGXZfGJWiMJD8wbDSgwj0pWZLBskCQuYwSd/W3hiZIrZaT1r6 k0HvopRo0LVQZHvIxFsoPbnyQjrovE0vlKbsfo8bzCNOy9UDC2RTCOIo0 3qiDK2P5j9nWaL0hDR8GC9Uw4tYnmAE3USQMxQrsip6PygfzLEDs8GGCd DK5b5nRVfzr83DuzZdqu2f2mbt1wq0Y+YJl+8s5+KBqKkrOi1NwUy92Cw g==; X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="335993891" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="335993891" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2023 07:04:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10732"; a="882915325" X-IronPort-AV: E=Sophos;i="6.00,217,1681196400"; d="scan'208";a="882915325" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga005.jf.intel.com with ESMTP; 05 Jun 2023 07:04:09 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1q6AoX-001O9h-1D; Mon, 05 Jun 2023 17:04:05 +0300 Date: Mon, 5 Jun 2023 17:04:05 +0300 From: Andy Shevchenko To: Bjorn Helgaas Cc: Jonas Gorski , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Rich Felker , linux-sh@vger.kernel.org, Dominik Brodowski , Andrew Lunn , sparclinux@vger.kernel.org, Stefano Stabellini , Yoshinori Sato , Gregory Clement , "Rafael J. Wysocki" , Russell King , linux-acpi@vger.kernel.org, Miguel Ojeda , xen-devel@lists.xenproject.org, Matt Turner , Anatolij Gustschin , Sebastian Hesselbarth , Arnd Bergmann , Niklas Schnelle , Richard Henderson , Nicholas Piggin , Ivan Kokshaysky , John Paul Adrian Glaubitz , Bjorn Helgaas , Mika Westerberg , linux-arm-kernel@lists.infradead.org, Juergen Gross , Thomas Bogendoerfer , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , linuxppc-dev@lists.ozlabs.org, Randy Dunlap , linux-mips@vger.kernel.org, Oleksandr Tyshchenko , linux-alpha@vger.kernel.org, Pali =?iso-8859-1?Q?Roh=E1r?= , "David S. Miller" , "Maciej W. Rozycki" Subject: Re: [PATCH v8 0/7] Add pci_dev_for_each_resource() helper and update users Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230605_070753_079618_B65B5D7F X-CRM114-Status: GOOD ( 21.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, May 31, 2023 at 04:30:28PM -0500, Bjorn Helgaas wrote: > On Wed, May 31, 2023 at 08:48:35PM +0200, Jonas Gorski wrote: ... > > Looking at the code I understand where coverity is coming from: > > > > #define __pci_dev_for_each_res0(dev, res, ...) \ > > for (unsigned int __b = 0; \ > > res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \ > > __b++) > > > > res will be assigned before __b is checked for being less than > > PCI_NUM_RESOURCES, making it point to behind the array at the end of > > the last loop iteration. > > > > Rewriting the test expression as > > > > __b < PCI_NUM_RESOURCES && (res = pci_resource_n(dev, __b)); > > > > should avoid the (coverity) warning by making use of lazy evaluation. > > > > It probably makes the code slightly less performant as res will now be > > checked for being not NULL (which will always be true), but I doubt it > > will be significant (or in any hot paths). > > Thanks a lot for looking into this! I think you're right, and I think > the rewritten expression is more logical as well. Do you want to post > a patch for it? Gimme some time, I was on a long leave and now it's a pile to handle. -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel