From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B72B130F52A; Fri, 10 Apr 2026 05:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775800284; cv=none; b=XG2dCJDqM8xne98IOzM/5E5hVf1QEEEswIYcV7J+z81Cv4qMoNPW+7zTh/lO9Cg/KDwr3bYc7Q+3abACOYtfF6dKCVh3sZ3ufkej1XSD5PCzfH4skjrTHr0mqKxiY+sxkoBQRcyD8ma8CTivG6XGsb9++f+JNSKb/aOGs50HgwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775800284; c=relaxed/simple; bh=4+W1kd8ovvTGg2a+x1mXoEZZdmh6JcYJxVFeZ3Yu0xQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I/SDcrqIYo0uEM4iyVtvA4MkLhESQx7vyfFT7rNac9atDfYEk3M0JX4BiT8WqBGbBa0UX/fl6dci/1pHF2eSOtaFV6mobmoZuQbaHOaUorsb3ozaRZZq7W0l0QKsya8E5vbrNjmDH5vC+Pd4P8vdFjOzCxWfqqGOEObvxU3+IGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fhcFm+T1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fhcFm+T1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22D21C2BCAF; Fri, 10 Apr 2026 05:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775800284; bh=4+W1kd8ovvTGg2a+x1mXoEZZdmh6JcYJxVFeZ3Yu0xQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fhcFm+T12KNVqPEsauDmvNs2LgfnB15yjv07PjZoD5L2qgLCuSm8jS2fqKePwfwyl hUr7/un8ohQP2ZqR45z2sokFDVsaSUbSep87bcyWUnDxZHhSLTGP+q+Nty/zI7NEK+ i4ss+3NC2srWor8vOMhDUWRTO9EbgSmHxOIc4gIl5C7rb2u9ttihS4qC3G6lEIkqqZ Pu6GtV96b1n3g3IeugY30bB6IJ8PYeXYTvADqUCjuaw0APrUOgMkGPJU7lE+ELXzhx O3DjB98247UHP3RjJNj9CLtkTNsRqiQXVuowSaLVR1XfNIFPlZ2ZLY5JMac9O3gxMs JIwZVi+YpY0Ag== From: =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Bjorn Helgaas , Manivannan Sadhasivam , Lorenzo Pieralisi , Magnus Lindholm , Matt Turner , Richard Henderson , Christophe Leroy , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Dexuan Cui , =?UTF-8?q?Krzysztof=20Ha=C5=82asa?= , Lukas Wunner , "Oliver O'Halloran" , Saurabh Singh Sengar , Shuan He , Srivatsa Bhat , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH 11/20] alpha/PCI: Use BAR index in sysfs attr->private instead of resource pointer Date: Fri, 10 Apr 2026 05:50:31 +0000 Message-ID: <20260410055040.39233-12-kwilczynski@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260410055040.39233-1-kwilczynski@kernel.org> References: <20260410055040.39233-1-kwilczynski@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, Alpha's pci_create_one_attr() stores a resource pointer in attr->private, and pci_mmap_resource() loops through all BARs to find the matching index. Thus, store the BAR index directly in attr->private and retrieve the resource via pci_resource_n(). This eliminates the loop and aligns with the convention used by the generic PCI sysfs code. While at it, add parentheses around the bitwise flag test in pci_mmap_resource() to make the precedence explicit, and to match the preferred style. The PCI core change was first added in the commit dca40b186b75 ("PCI: Use BAR index in sysfs attr->private instead of resource pointer"). Signed-off-by: Krzysztof WilczyƄski --- arch/alpha/kernel/pci-sysfs.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/arch/alpha/kernel/pci-sysfs.c b/arch/alpha/kernel/pci-sysfs.c index 2324720c3e83..c84867ce31f5 100644 --- a/arch/alpha/kernel/pci-sysfs.c +++ b/arch/alpha/kernel/pci-sysfs.c @@ -69,25 +69,20 @@ static int pci_mmap_resource(struct kobject *kobj, struct vm_area_struct *vma, int sparse) { struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); - struct resource *res = attr->private; + int barno = (unsigned long)attr->private; + struct resource *res = pci_resource_n(pdev, barno); enum pci_mmap_state mmap_type; struct pci_bus_region bar; - int i, ret; + int ret; ret = security_locked_down(LOCKDOWN_PCI_ACCESS); if (ret) return ret; - for (i = 0; i < PCI_STD_NUM_BARS; i++) - if (res == &pdev->resource[i]) - break; - if (i >= PCI_STD_NUM_BARS) - return -ENODEV; - - if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start)) + if ((res->flags & IORESOURCE_MEM) && iomem_is_exclusive(res->start)) return -EINVAL; - if (!__pci_mmap_fits(pdev, i, vma, sparse)) + if (!__pci_mmap_fits(pdev, barno, vma, sparse)) return -EINVAL; pcibios_resource_to_bus(pdev->bus, &bar, res); @@ -170,7 +165,7 @@ static int pci_create_one_attr(struct pci_dev *pdev, int num, char *name, res_attr->attr.name = name; res_attr->attr.mode = S_IRUSR | S_IWUSR; res_attr->size = sparse ? size << 5 : size; - res_attr->private = &pdev->resource[num]; + res_attr->private = (void *)(unsigned long)num; return sysfs_create_bin_file(&pdev->dev.kobj, res_attr); } -- 2.53.0