From patchwork Wed Sep 14 07:09:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Heimes X-Patchwork-Id: 1677671 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=SIryijwi; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSBLG0VFcz1ynm for ; Wed, 14 Sep 2022 17:10:12 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oYMX1-0007WO-4y; Wed, 14 Sep 2022 07:09:59 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oYMWx-0007VQ-PE for kernel-team@lists.ubuntu.com; Wed, 14 Sep 2022 07:09:55 +0000 Received: from T570.fritz.box (p54abbb95.dip0.t-ipconnect.de [84.171.187.149]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 636B43F122 for ; Wed, 14 Sep 2022 07:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1663139395; bh=bao419aJCurQiryj9//RJT9TfI7OUvAx0mi4Um+mB60=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SIryijwiz+8RQn5BF+NOmpZ47cNDXtSLeM1LNWzF/I8DRzQWrAAShbQa96FTj2MjD sqTmroOhF4p7QXrnSSTAW0g0K7rvAXWMT1yAlmeuWsprLYzJBdPj8RIezwd6OLyz88 Hh76o6eiCLx7vmd89YWUoB3thGx6lf2I7ehciHiaITsmG50Q925lI7dB+kfc0C40RV WZ0ldhyqMJQcA2P8waWtErpK6Kc7B8wZ9ZqkCfOOBHW0GXqBMEDrVOlI+IuDvHIote hZ3yQDq5AqhiQU8tP0lNiJoEYgIvXgBdezqiMk8ChUalWRPVkdahw5Mpzhy0+LnJxZ Hd53WinIKrGKQ== From: frank.heimes@canonical.com To: kernel-team@lists.ubuntu.com Subject: [K][PATCH 2/5] PCI: Split out next_ari_fn() from next_fn() Date: Wed, 14 Sep 2022 09:09:41 +0200 Message-Id: <20220914070944.919437-3-frank.heimes@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220914070944.919437-1-frank.heimes@canonical.com> References: <20220914070944.919437-1-frank.heimes@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Niklas Schnelle BugLink: https://bugs.launchpad.net/bugs/1959542 In commit b1bd58e448f2 ("PCI: Consolidate "next-function" functions") the next_fn() function subsumed the traditional and ARI-based next function determination. This got rid of some needlessly complex function pointer handling but also reduced the separation between these very different methods of finding the next function. With the next_fn() cleaned up a bit we can re-introduce this separation by moving out the ARI handling while sticking with direct function calls. Link: https://lore.kernel.org/r/20220628143100.3228092-3-schnelle@linux.ibm.com Signed-off-by: Niklas Schnelle Signed-off-by: Bjorn Helgaas Reviewed-by: Pierre Morel (cherry picked from commit fbed59ed8781d7eecd7f45cde0188cf24eeb5c38) Signed-off-by: Frank Heimes --- drivers/pci/probe.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b05d0ed83a24..d62885519df3 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2579,26 +2579,31 @@ struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn) } EXPORT_SYMBOL(pci_scan_single_device); -static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn) +static int next_ari_fn(struct pci_bus *bus, struct pci_dev *dev, int fn) { int pos; u16 cap = 0; unsigned int next_fn; - if (pci_ari_enabled(bus)) { - if (!dev) - return -ENODEV; - pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); - if (!pos) - return -ENODEV; + if (!dev) + return -ENODEV; - pci_read_config_word(dev, pos + PCI_ARI_CAP, &cap); - next_fn = PCI_ARI_CAP_NFN(cap); - if (next_fn <= fn) - return -ENODEV; /* protect against malformed list */ + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); + if (!pos) + return -ENODEV; - return next_fn; - } + pci_read_config_word(dev, pos + PCI_ARI_CAP, &cap); + next_fn = PCI_ARI_CAP_NFN(cap); + if (next_fn <= fn) + return -ENODEV; /* protect against malformed list */ + + return next_fn; +} + +static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn) +{ + if (pci_ari_enabled(bus)) + return next_ari_fn(bus, dev, fn); if (fn >= 7) return -ENODEV;