From nobody Sat Sep 26 04:29:51 2026 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EDE54A4408 for ; Fri, 4 Sep 2026 13:46:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788529590; cv=none; b=Wu683W8vUV/VA47gXWodAzHwkp+uI1o/+rb2T4V6cpWKdEkZLO7fvL7q2GMesAsCYn74b88gzo5TaFIw+BdZt+0snIK3xdy3jd8yRCrZg+Yx2WOlFJIoHfSlp4e+q7AMbPayEe9KdowdwBzmhe+MQJzzLydxFyx8cWtC65BBOO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788529590; c=relaxed/simple; bh=l7HBFW2oz1K7wlz0Cw/q76k0lqFcEvUDwHaz93CkcFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ec/tx4JzrXfPvMvoPXJFrFY/0TyOBF5m+apZPGGPS7+NclvThXPp7Fd9AZxsH3R76SVCUH2b2VIboUhh2Hdz60fKP9qQjgMrJkC6p2X8hkNcbssZBCSp7GBZ/Rhm4HB3Fu2xJt9rSSg4XDH/TyhEMM4RLfKIMvCcjkYJb8zBWmY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b=Z+px9OyB; arc=none smtp.client-ip=209.85.222.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b="Z+px9OyB" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-92e50a650a0so98663185a.1 for ; Fri, 04 Sep 2026 06:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1788529587; x=1789134387; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=X+Bw04n0AyQYjskAQ/JcmMjfV9T3RjIpfJoearHWcfU=; b=Z+px9OyB3Q3YxOWoirmFuGtw0afVJ5jCKhh9O/Vpn7Jo9GJ1E5p6TRkyfY6vA2/uAD ZbJL1XoZ5Jnmmq0KzQx1LUdt7+/a6QG3kduT5vjQ8uT6IQJXs5/pb+3D79zMrQzTY235 EUIzd26bg64xfstUm4yaWr5zg+/Q1GxfT8VLrfYUSB057r1Rmv5kBcA1ttHllTXZUBOx tcH/9mLIzyW72ZOIQavXwnqJXjKkXMenuW2i8vBSLVlhWkCmyt0YX6LE6QQxK5DQvueO a271Fxrf/YntIY60FXWCc+8O45KRQr6HGDXa/tWrivlCDKQQMWVgeO3Vk51/Bz4h21K+ zp8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788529587; x=1789134387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=X+Bw04n0AyQYjskAQ/JcmMjfV9T3RjIpfJoearHWcfU=; b=Sb/q1GFoeyNPEzAFXXiHMn6ShaJaQ1NUIbqPCfqeDewGfIKb+K9llIkB/W+HV/cE7S YJGqEpmZzAI3y0AWVlcuY4Hi2RNRErwIIHeXUVjJvjpfXd3OD99SQIwswYEn+/f28txy PknMuddsoyBXDyThZaS7qUPyyRRpSc+rAAooqn29aTVnC/qwd8lbU74iZBsLHXdPr4v0 kbVpjZ93qwbihXzNgbJZ6AT+O6/+dGYTQm+EqBvpWLr/y6J7SDSRLaU0LzpqFGThTKMz S7oJ13SxWTZTUDqbXiNQZYODXoDcMunBMqJOiEXQueTqNARoaQgz5uEfTDXCvdatLFvD V2Hg== X-Forwarded-Encrypted: i=1; AKwUvBwHopsiZafcAon9eF0yCD/TJI7uOCeZXxqIktEHbPxDJywxA97PrnSqdfpSqKDSpN+P25fMZXF7G2A1ky4=@vger.kernel.org X-Gm-Message-State: AFuF++mDaR4mlnRtooIoM1gvmHUfAHdRSM/6Y9ocRgQTVEktwLQs+2ua y55licfT1XqQ2D1v53ox78mUtg9Y21tWqeaEP/oAm6JBG9xz5mX9mr6DRVnug90qeYI= X-Gm-Gg: AYBFou0rznDQLvNAOx9PaYfHdnYdb+SmWW9fjzqnVX2v6LL/mFo0rF5+DH/ryqO5pCg +D2aC0kiEuTUugujy5ixoymjrNf16aplh061ddskwygLMsZIOuwtg7BlmM12kCx0UaYH/T0UD4Q g5ndAbENTYWN0h0UOWrjL3PQW9B3hmkpm1ARmFlkXwJepZDWH12NvpJBuw5ksFfx1yT5RNZzCRe a1ZVRaR7hXnqcNybmsf555kUXRiiquk+FSU7EAg570KvY7cXGzylmLuBLXfQETVM69kuhgTP29b np9E+Gkt+lXK2f4uGf1c+Q5wjosS628/dMy5YsRH/xc1SgDhr/AoSYNo4eV3eEVrqK9UlmRM2Oa AqzFsc94mnC0fQV+6kLl0tddFffZMQ7OfO+DQvmIfMlz2JLxb4V+88Lk+ipBHqCCZIeIuBcK00q lmXlGOwWEx6psUTqa/jvmxW1qU2HsLixZ+hhvLxNImWzekY/wwxic5rrbx5yclJtfQ X-Received: by 2002:a05:620a:a0c5:10b0:936:dbf1:f495 with SMTP id af79cd13be357-939802f6e18mr474878385a.1.1788529572210; Fri, 04 Sep 2026 06:46:12 -0700 (PDT) Received: from zippy.localdomain ([73.62.185.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fafc3a7sm211613885a.14.2026.09.04.06.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 06:46:11 -0700 (PDT) From: Alex Elder To: bhelgaas@google.com, robh@kernel.org, saravanak@kernel.org Cc: herve.codina@bootlin.com, daniel@riscstar.com, mohd.anwar@oss.qualcomm.com, lorenzo.bianconi@oss.qualcomm.com, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko Subject: [PATCH v4 1/4] PCI: of: avoid allocations in of_pci_prop_compatible() Date: Fri, 4 Sep 2026 08:46:03 -0500 Message-ID: <20260904134607.1856121-2-elder@riscstar.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260904134607.1856121-1-elder@riscstar.com> References: <20260904134607.1856121-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Three compatible strings are formatted in of_pci_prop_compatible(). Their sizes are known in advance, and the largest is 16 bytes. Rather than dynamically allocating the space for those strings, just set aside a buffer on the stack large enough to hold all three. This avoids a problem that Sashiko pointed out, where an allocation failure would cause subsequent crash because strlen() is called unconditionally in of_changeset_add_prop_string_array(). Reported-by: Sashiko Link: https://lore.kernel.org/sashiko-reviews/a647bd56-7dc8-4fec-9d96-83462= 2054cdf@riscstar.com Signed-off-by: Alex Elder --- v4: - Added this fix to the beginning of the series drivers/pci/of_property.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c index 75a358f73e694..a0632f932b5c6 100644 --- a/drivers/pci/of_property.c +++ b/drivers/pci/of_property.c @@ -324,27 +324,36 @@ static int of_pci_prop_intr_map(struct pci_dev *pdev,= struct of_changeset *ocs, return ret; } =20 +/* The three compatible property strings have max sizes 12+1, 15+1, and 13= +1 */ +#define PROP_SIZE 16 /* Max size of each compatible string */ static int of_pci_prop_compatible(struct pci_dev *pdev, struct of_changeset *ocs, struct device_node *np) { const char *compat_strs[PROP_COMPAT_NUM] =3D { 0 }; + char buf[PROP_COMPAT_NUM * PROP_SIZE] =3D { }; + char bufp =3D buf; int i, ret; =20 - compat_strs[PROP_COMPAT_PCI_VVVV_DDDD] =3D - kasprintf(GFP_KERNEL, "pci%x,%x", pdev->vendor, pdev->device); - compat_strs[PROP_COMPAT_PCICLASS_CCSSPP] =3D - kasprintf(GFP_KERNEL, "pciclass,%06x", pdev->class); - compat_strs[PROP_COMPAT_PCICLASS_CCSS] =3D - kasprintf(GFP_KERNEL, "pciclass,%04x", pdev->class >> 8); + ret =3D snprintf(bufp, PROP_SIZE, "pci%x,%x", pdev->vendor, pdev->device); + if (ret >=3D PROP_SIZE) + return -EINVAL; + compat_strs[PROP_COMPAT_PCI_VVVV_DDDD] =3D bufp; + bufp +=3D ret + 1; =20 - ret =3D of_changeset_add_prop_string_array(ocs, np, "compatible", - compat_strs, PROP_COMPAT_NUM); - for (i =3D 0; i < PROP_COMPAT_NUM; i++) - kfree(compat_strs[i]); + ret =3D snprintf(bufp, PROP_SIZE, "pciclass,%06x", pdev->class); + if (ret >=3D PROP_SIZE) + return -EINVAL; + compat_strs[PROP_COMPAT_PCICLASS_CCSSPP] =3D bufp; + bufp +=3D ret + 1; =20 - return ret; + ret =3D snprintf(bufp, PROP_SIZE, "pciclass,%04x", pdev->class >> 8); + compat_strs[PROP_COMPAT_PCICLASS_CCSS] =3D bufp; + + return of_changeset_add_prop_string_array(ocs, np, "compatible", + compat_strs, PROP_COMPAT_NUM); } +#undef PROP_SIZE =20 int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, struct device_node *np) --=20 2.53.0 From nobody Sat Sep 26 04:29:51 2026 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87EB14A207A for ; Fri, 4 Sep 2026 13:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788529576; cv=none; b=YTXEgBCaO5CSHctUd0M4wiMd7vuiopD+64tROQd/JjKS6y+BYEeb7sTKVbhI9K7+ESjPN5XiXbOd0dlHjak90z6DWYJ6F4T4mDlBTikJlZVqbNYYhGmd0jn6dvwBav8lJ2L1XGHe54EO/aj+pMXONlDzcwHVq/MraBfdtdQMQAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788529576; c=relaxed/simple; bh=qsvHvr0KAaevLVLkT3vf4bhPnfL4fka0jjcShl0SAUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HYefQywe9XS2LzloFW1LHrzYhCOdYvSmZ3uR3tGxfLplxhBZgcbhGYjnidJtapPKjQalegkGJ5/hyDj6rJSsSJ+qCwLTcKG2/lnV1etILsoFBlSpZDR3K9+QCLzyUVguTysWPbM7N5iTrSY3Mg0lk9gs6ppMO6Qm2ROSAoLAO2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b=pLbOPtA0; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b="pLbOPtA0" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-9390f8a1c9eso68596485a.3 for ; Fri, 04 Sep 2026 06:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1788529573; x=1789134373; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2LewW6w2wMuYs1hjrl9EfxjaqOnpI7soa/xK2a7NCBI=; b=pLbOPtA0ajCFEw/z2Ei4jIQVPT4cSFcNKQgxGO0SwpY8anKsWCpM9gHISyCH0FxcYM yKUaMyOKTqo67wQdiWcZuABhvys9EXr1b/G+/3mOVFAtC2ItGC0Ds/+s/ev2XrbIdBJf JdxufQfo/bDAUe4BC0m1Lf1/X74MXRbOAqBNnj3y456NTtdaZIZUezZ8Ne+CRX6T8IBr UNi1jyzy8L9uGkvWju+ZA5GC+zQ8Jv+GvfomVNbK1aWg7BdsWMaDCJvvT/AH2Se1+Ulh 2q6sWiOZfvaJuTvhRGiQlhcTUvC3atBGsOVAZtYU5RtIA/G+fm85fzWSZDFvRkpNqmLY MLRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788529573; x=1789134373; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=2LewW6w2wMuYs1hjrl9EfxjaqOnpI7soa/xK2a7NCBI=; b=abJxFLxZoq9iHt4ocxgs21na1YrPDxH8+c2vx9aSF+R5MgdQFyfKdO2y3u9zr7MKC3 6JMZDtXlsw/8FzdEXBTss4cow5+lo1hFW4BilJJBNpr1OBEoXc51FuwI3b0EyCBQh1/F Cg+tSESk1nyTuHsPQZojt1nAunW6zek/Rn9Gr+Io2GgTdVZYK2/m4osTBf+O4/jCTzfH AZFZp6qkuHnm/2Rg9Tn7HPAQXgL27gs/DmOCcB1ZLr0gznyZ1JRg4Z7B+AMD1T/liaUf InTs+98r1CjcjE8cIJCVEQKc6QiRYDnNfG2Shto+xjl16vihTVD4vQRZU79HSIn2WQxQ QgJg== X-Forwarded-Encrypted: i=1; AKwUvBwm1YVivmBL1dVTD9xE7UcLDPAT3WbfNI4YIRg7CGbfgjIGI5NpqP77eBNtH9z9Ot3hS3898lheqHvQGAA=@vger.kernel.org X-Gm-Message-State: AFuF++kvhC3289KRsnWRrzzOB2FbBzsf9JppiL2FLuujfrpZF6I+/401 8d4GnFjJgIPtFNSRJdSNU4DPFND5s9xjEwo1RNhutnoUVccHE8yG29+EQlrWU3pNfngJ1hv1BU+ duZmb3Kw= X-Gm-Gg: AYBFou0Gup+7ZTAH47w+ruFfpOtg6flUM0S8X0pZPpAOw/1F4wGa4M4mdatoPZNfDHB zwzV+JzfhzdjxjSWlDfY2eyX0/w7I9hoSMCa5pHX/MVoJbVkDUaKeR7jH3uZPPxLJifmKmiaIcg m6d8fcgZoli2slLD14h7S4Bxft9MUlsjOAD7vn5D9f9Lk3l41w2n4M1O6JBTmSTLAr7Pm+ICHmT 3M128aRWfShy2zFsfMWoiBOoGTipSKE1rl5DxFLQNoy89RzW1DiyVVEDMEXJ2+K+QtNupIaizVH r+EaZyxXm51Rp13qU9I6GMVZVadCces5Rybi4HQZCg4znraomo7at5cZsiY0p4TDQVnZkpoAkzG FSJCOSCf3HgL1nNSffrqd/l5v7mN0z/AnfYIgbYKKgLKn9otUa8X5dFDiFMLRKlWHU3NYlWut8b +E/CagdRC09ExpIfJUWZsQGnjhEKRNqQ4divhjjpsGwpxvM613mblQgaweh0FEytI+ X-Received: by 2002:ae9:ee06:0:b0:936:e938:b07a with SMTP id af79cd13be357-9398032898bmr454562185a.8.1788529573342; Fri, 04 Sep 2026 06:46:13 -0700 (PDT) Received: from zippy.localdomain ([73.62.185.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fafc3a7sm211613885a.14.2026.09.04.06.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 06:46:13 -0700 (PDT) From: Alex Elder To: bhelgaas@google.com, robh@kernel.org, saravanak@kernel.org Cc: herve.codina@bootlin.com, daniel@riscstar.com, mohd.anwar@oss.qualcomm.com, lorenzo.bianconi@oss.qualcomm.com, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/4] PCI: of: drop the reg_num argument to of_pci_set_address() Date: Fri, 4 Sep 2026 08:46:04 -0500 Message-ID: <20260904134607.1856121-3-elder@riscstar.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260904134607.1856121-1-elder@riscstar.com> References: <20260904134607.1856121-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The reg_num argument passed to of_pci_set_address() is always zero, so get rid of it. Reviewed-by: Herve Codina Signed-off-by: Alex Elder --- drivers/pci/of_property.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c index a0632f932b5c6..8131aa1b0b3c4 100644 --- a/drivers/pci/of_property.c +++ b/drivers/pci/of_property.c @@ -52,7 +52,7 @@ enum of_pci_prop_compatible { }; =20 static void of_pci_set_address(struct pci_dev *pdev, u32 *prop, u64 addr, - u32 reg_num, u32 flags, bool reloc) + u32 flags, bool reloc) { if (pdev) { prop[0] =3D FIELD_PREP(OF_PCI_ADDR_FIELD_BUS, pdev->bus->number) | @@ -61,7 +61,7 @@ static void of_pci_set_address(struct pci_dev *pdev, u32 = *prop, u64 addr, } else prop[0] =3D 0; =20 - prop[0] |=3D flags | reg_num; + prop[0] |=3D flags; if (!reloc) { prop[0] |=3D OF_PCI_ADDR_FIELD_NONRELOC; prop[1] =3D upper_32_bits(addr); @@ -131,7 +131,7 @@ static int of_pci_prop_ranges(struct pci_dev *pdev, str= uct of_changeset *ocs, continue; =20 val64 =3D pci_bus_address(pdev, &res[j] - pdev->resource); - of_pci_set_address(pdev, rp[i].parent_addr, val64, 0, flags, + of_pci_set_address(pdev, rp[i].parent_addr, val64, flags, false); if (pci_is_bridge(pdev)) { memcpy(rp[i].child_addr, rp[i].parent_addr, @@ -164,7 +164,7 @@ static int of_pci_prop_reg(struct pci_dev *pdev, struct= of_changeset *ocs, struct of_pci_addr_pair reg =3D { 0 }; =20 /* configuration space */ - of_pci_set_address(pdev, reg.phys_addr, 0, 0, 0, true); + of_pci_set_address(pdev, reg.phys_addr, 0, 0, true); =20 return of_changeset_add_prop_u32_array(ocs, np, "reg", (u32 *)®, sizeof(reg) / sizeof(u32)); @@ -467,7 +467,7 @@ static int of_pci_host_bridge_prop_ranges(struct pci_ho= st_bridge *bridge, /* PCI bus address */ val64 =3D res->start; of_pci_set_address(NULL, &ranges[ranges_sz], - val64 - window->offset, 0, flags, false); + val64 - window->offset, flags, false); ranges_sz +=3D OF_PCI_ADDRESS_CELLS; =20 /* Host bus address */ --=20 2.53.0 From nobody Sat Sep 26 04:29:51 2026 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2A2C4A1E05 for ; Fri, 4 Sep 2026 13:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788529578; cv=none; b=S9sccHqLDTJvXB0Mx4RsS6DddpAUMVtCpy7Kl0h0KgfcVYjwr+kMi7PswAtO1G8HGwp/+bex2D7Fkr6u/SIMMlXJb9Okdvej34zjAp2lUCvqPMthnZXtT83gzTCKvPbd4Yq9l41/0HLgypsUGboujEjYRfcyAaBD4nPszZxiCOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788529578; c=relaxed/simple; bh=qyD4bGNfcFSzPNaLFl2vhb3CFKp/crvP/9Jaao9JAyI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gBZGJLR1yB3u2xxPKMYLpShjOFIEBaS/H175LR8U3cFtFc/1kie1gxIVBfU8PxT6FlfwmgIwUXekntofen4g85nXxnhaJ2sOSpk8GycKex+wUpxcMqCatXof0Mgrjy7rCup12o7TgUeTgAPPRTowAKbTv0gqabm06F/LzyQrdRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b=DK0H3ENh; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b="DK0H3ENh" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-529a1ee0e62so13511461cf.2 for ; Fri, 04 Sep 2026 06:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1788529575; x=1789134375; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=iAwqufnwuKEV24w71YGykBZDHshBllwrVOx0ky+yHTQ=; b=DK0H3ENh98CWzmnIXzijn6sJ2jQjxAY+E1n+HO+SSMMbr0kgljjb0FRr5UTKghzdCR um6tA0pcevfnV054cMjT9n9B7GsixdFl5gdHHZpUJXEG46XwXj4y40MgwZngrYfSm+6Q eVDT4fxr/ot4bRDwd+ucMXK9Na/zujsUkl4hYIlYiSYF/pW1UfILn9MI4O4cXJMDQJmk W95aptIIPyk2aLfiSf37peeQzF1cm79FwydlcrELrBYpV+locayjGI+MeJuRj/ASVZBu XLt+yY/3Yhxk4e+2DOPvkcos/a2VZXp1G6FYbPglSI5ZZx+P0UF0WmmJ8+VQ5bm9867W u+aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788529575; x=1789134375; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=iAwqufnwuKEV24w71YGykBZDHshBllwrVOx0ky+yHTQ=; b=eTWbZ9pyWAJ2dL1w7Yy6wFYLvSLom54gADD43E0NdKF2O9UU2FtUGt+101kuvkUAa1 HAki20ZJdVbmGolBG7/g800PKzp1P3iBSiCRwvCfd+n5Hui4M22qJ38Fn9D4xuURrLVd bKBs7MCSgjBW5qX8O9DvxmKTGdIINca4mK1BHx9Ci26ad+05hs/sAcVzyj70//11QSal jze2HK1iSKQAbYnnR2HbVoS9x/Ao3ZYNb3/ajSWRND9rMorkrhO0RuHbVuiHjm6XI1/Y 8Kld9DW3+YTEGV3dFnXaGml6GckDfX5xecLgzOFFmZdXusJ2tjfvsE9G218CkXMJ5RHS 3Wxg== X-Forwarded-Encrypted: i=1; AKwUvBztftGPxv2u0IiHgKz3dkxD9sXPVAoobe6c+C7Yv3PXOjPBYmJX2496yQBU3VpqHkUxCaeUv2o4RxjOgDw=@vger.kernel.org X-Gm-Message-State: AFuF++nHIpGu9g0EUj0qdn+ieDnlSfnFDkMQUbGuCgIosPJg/0D1edIB 6VxlIJPjViaBQqdvMPKDcxx3F8ZbeYxDm5uxfkCkbl8OKfiLHXaw4lt2fh7deP4N1Fk= X-Gm-Gg: AYBFou280BT//XCgzRaB7MdNBfcbmNn2IoiCdxv/4lzPvdvf/MHLbQvNIwch9JcnqRP anU5GrtxgBSRJ+qqFCT03UZqA6x5D+pTt79DCYgQWysw+GS3tL+uYSk7BpfnrcVLlTjKGMs5dJ4 kEB7sbsiiB0P+JHNcksj/yYvtMomF5vbO9t+UkxazGj2BeEPA4QK2TItYwxvI3DPBb0/AL6ccGy 1chtG7/X2DQHuQfYe/n9tXPr9AU3d1V7HCgk9+SSr3Niv+YrpPEDD/dHCN64yRY1SWeJ9u4FPgN xH+lKRCG01zkH2ej70Ck36/LNz8XPfFo1o0bjlQfe072Qo0fHckGv6Kcn11O2AADwpt3gL8P9OI ninIlKnfYUl03bkFQcyLYFrZK7FERwieeSz0Y0J07TfYI59ksPbAFWnVDMm6+6sgMbpVdaqRwjS DlUDoTkzpW3YNS3bfW1HGvzj8Ssf9wy9910YeKWQzHk5AJT2WEWzW6QvN3GjE93Gt1 X-Received: by 2002:a05:620a:a518:b0:92e:7d53:8e8d with SMTP id af79cd13be357-93980434f3fmr510380985a.27.1788529574458; Fri, 04 Sep 2026 06:46:14 -0700 (PDT) Received: from zippy.localdomain ([73.62.185.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fafc3a7sm211613885a.14.2026.09.04.06.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 06:46:14 -0700 (PDT) From: Alex Elder To: bhelgaas@google.com, robh@kernel.org, saravanak@kernel.org Cc: herve.codina@bootlin.com, daniel@riscstar.com, mohd.anwar@oss.qualcomm.com, lorenzo.bianconi@oss.qualcomm.com, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/4] PCI: of: don't zero flags in of_pci_get_addr_flags() Date: Fri, 4 Sep 2026 08:46:05 -0500 Message-ID: <20260904134607.1856121-4-elder@riscstar.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260904134607.1856121-1-elder@riscstar.com> References: <20260904134607.1856121-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The flags variable whose address is passed to of_pci_get_addr_flags() is zeroed before assigning a value to it. Skip the zeroing and just assign it instead. Reviewed-by: Herve Codina Signed-off-by: Alex Elder --- drivers/pci/of_property.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c index 8131aa1b0b3c4..fca522f70187a 100644 --- a/drivers/pci/of_property.c +++ b/drivers/pci/of_property.c @@ -82,12 +82,10 @@ static int of_pci_get_addr_flags(const struct resource = *res, u32 *flags) else return -EINVAL; =20 - *flags =3D 0; + *flags =3D FIELD_PREP(OF_PCI_ADDR_FIELD_SS, ss); if (res->flags & IORESOURCE_PREFETCH) *flags |=3D OF_PCI_ADDR_FIELD_PREFETCH; =20 - *flags |=3D FIELD_PREP(OF_PCI_ADDR_FIELD_SS, ss); - return 0; } =20 --=20 2.53.0 From nobody Sat Sep 26 04:29:51 2026 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D68B34A2041 for ; Fri, 4 Sep 2026 13:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788529583; cv=none; b=jPDEoPBhobHXFc5o7NvEGi7lUa/wO3EjiB6i337FpTDRjbJDORXNdHFOO6EtXrb3Xbu72MhxRMYCys6nfwrNTXcjy8VN5NUPM/H81k+Fzs+gaRx36yNFL928V0ECJ9KO0mGVCSL/1tnh2WoDFT9wpwd8cGle9BqS0jGyuj1KFwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788529583; c=relaxed/simple; bh=Umf4Qux19s/oJdiljE5afHHlwKfEF4F/L07jXGmhg5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dTez/A9Su777fUqMR2PcfL03leL1j0uM4fcb10g0epRLdntqtk4wUGKslSnXAC8MhAIiwKNsz58WHEvWNHYXZj/KfSZDhs36Q/qJW0K3GvmwN02GMCyC0xG20ERZfxjWUrtaSh1Jj2Sx+DNCYEdQ0M4qWZzYVdwP5K9CQ24l8Ck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com; spf=pass smtp.mailfrom=riscstar.com; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b=JuaSSe+R; arc=none smtp.client-ip=209.85.222.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riscstar.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riscstar.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=riscstar-com.20251104.gappssmtp.com header.i=@riscstar-com.20251104.gappssmtp.com header.b="JuaSSe+R" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-936e393176fso78330485a.0 for ; Fri, 04 Sep 2026 06:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1788529580; x=1789134380; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8jU3bHZExWtt76MVfRZM8b738CbAPfC/obIJMlr2jck=; b=JuaSSe+R3EUxXSGd2hQN6wPIrdjt92DY4jQHxaK5WcF6eSqlRB8MY9+NOhF1CYSbAS wc7oQpT3iUyp6O6PPHmkiCXaNjTmQK/Gfcw25MTyHlJBVsyjIhhmv63VNbHjsGHsgjmm HZaKjAFDacs0gSWUGOBGV9Guf+pWf4l9w9lGEpyFsGfAWn10eUJoca8e5DzWufdUQY2c nWvU+T/tlxNWKbPf9c9uiwB3XWNqT+hbWB7ulFkZYGhCSMrCbp3WRj4bvs+QumJV/y30 QAoSDAJCedBZwRPOBYmDbqsbuUJqH+NxBexCNcOIlhQ38rxty2CbrFkJvIl2+hEtbKx5 nxrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788529580; x=1789134380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8jU3bHZExWtt76MVfRZM8b738CbAPfC/obIJMlr2jck=; b=k2/i46Ft5hqkFKAfUucNyPJYB0c2YdcYMn57ib8oj1JpqyI4C9euthnEO6cxsR4Pxr 7+r7ZMVgU52BQ1/4/4AfDUkymiG3uAnDd5HFNNEthLqskKWitLmrZq4WggIN/+WQdBUC gRNyInG8B9bBJvbmbaj2YnyeWqXia7Pzuo4EsafHJyZZPqd5hSA527e/7ILqBd/XebCG OO2Tw6p5Cpt9fuN2Fy1CwvM3TE0/Ip4HNrxOSFJjRAHe5DzNAQLkkjBcUnFQvqb/QYGE 9n1bcNrU1+CMM6T0x/ZYjtqai/Iy93Urca4mccgxWyp9NnN101PNf773DcqWV98z+/VS nqEg== X-Forwarded-Encrypted: i=1; AKwUvBxD3WNfFFwljwXlH/nb/7cMRpgvJuLD/yAzPYbKdaRWWC6lFkp19dSwdoQIdKPVzRQ669nMgNXQHJAx5zM=@vger.kernel.org X-Gm-Message-State: AFuF++kykvqAQSAeJLedSNj1IIBpO1fJZ8ZjycbLmgWu2UatyTy4hPnn eMuV9N+n5wUO9xCJQKEkE8y3TgU6FC6cx16CYfiw0xychp+HR44nmMdfX1Esv4FayYk= X-Gm-Gg: AYBFou3yPGm5ij196MDV35WxJl/UVPc3kbTfICfMZwxa9bmjvQCgCPAlY59D3o9RtiK oG/PtM6BIy3kYYKzw26yxA9l8Kt7q50r/8r8WkyGC0mmCSMIARZsYEr+u+nSkMwducjvd6yAK7k wyTj4Gp8FVqlVArUe5IlwNPsgHGi5Hcj89kzkJrYP2t1YEpg0wgn7yxFJw8OtsGTC8+VeqiR1ys n0OiLJnLpRmjoASPeD9O12EQov9lf1MYqmHOxlo3zYzZmRW2ckMzVlbQCYu5QCCermaexxDI2Gi 9Of+jGMLPiM95rT1HqaCWUU3TkVFGcDJjmkAGEaaury/SVnRhdN5EmLNTeU5D60fB3xphObaeEQ mjY/pLC35ODXylwsgI8svfZWzfXN5+akHZ8ogN61RQzlNhGIXZY2qUnhW8Me9buN/D0iNfJrUdz jwQodF3L+uumnJaBLYvhYR+3EsxYdvUwWmNCUBRwMUUKYU1m+saEZ2N+WROLk9Nrvm X-Received: by 2002:a05:620a:8201:b0:936:499d:9504 with SMTP id af79cd13be357-939803443cbmr424763285a.14.1788529575649; Fri, 04 Sep 2026 06:46:15 -0700 (PDT) Received: from zippy.localdomain ([73.62.185.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fafc3a7sm211613885a.14.2026.09.04.06.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 06:46:15 -0700 (PDT) From: Alex Elder To: bhelgaas@google.com, robh@kernel.org, saravanak@kernel.org Cc: herve.codina@bootlin.com, daniel@riscstar.com, mohd.anwar@oss.qualcomm.com, lorenzo.bianconi@oss.qualcomm.com, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/4] PCI: of: introduce of_pci_verify_node() Date: Fri, 4 Sep 2026 08:46:06 -0500 Message-ID: <20260904134607.1856121-5-elder@riscstar.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260904134607.1856121-1-elder@riscstar.com> References: <20260904134607.1856121-1-elder@riscstar.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 407d1a51921e9 ("PCI: Create device tree node for bridge") linked the PCI enumeration process together with devicetree, creating a devicetree node for discovered PCI bridges. Its successor commit ae9813db1dc5a ("PCI: Add quirks to generate device tree node for Xilinx Alveo U50") shows how to use a PCI final fixup quirk to also create a devicetree node for a non-bridge PCI device. These changes allowed devicetree overlays to describe components downstream of a PCI device, by providing a place to attach the overlay. Note that the dynamic devicetree node is only created if the device didn't already have an assigned node. Later, commit aa7b4bbcb3a1d ("arm64: dts: qcom: qcs6490-rb3gen2: Add TC9563 PCIe switch node") *pre-defined* devicetree nodes to represent the PCI device nodes that would (also) be discovered via the PCI enumeration process. The devicetree node in this case is created with the content from the DTS file. So when a (host) bridge is done being initialized during PCI enumeration, no node is dynamically created (the commits mentioned above do not apply). Ideally, any pre-defined PCI devicetree node would contain exactly the same information as whatever the dynamic creation process would produce (though it could include more). However that is not the case for the pre-defined Qualcomm RB3gen2 nodes. And in particular, the endpoint (function) nodes include this property: device_type =3D "pci"; This is simply wrong; that property is meant only for bridge nodes. Rob Herring requested that a runtime check to be added to spot this specific error, only for non-bridge PCI devices. Herve Codina further suggested we ensure that bridge PCI devices *do* define the device_type property, with value "pci". We also accept "pciex" as the value of the device_type property for bridges. Reviewed-by: Herve Codina Signed-off-by: Alex Elder --- v4: - Added "pciex" as a valid bridge device_type property value - Added Herve's Reviewed-by tag drivers/pci/bus.c | 1 + drivers/pci/of.c | 32 ++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 655ed53436d3e..679afbc6d3109 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -351,6 +351,7 @@ void pci_bus_add_device(struct pci_dev *dev) * are not assigned yet for some devices. */ pcibios_bus_add_device(dev); + of_pci_verify_node(dev); pci_fixup_device(pci_fixup_final, dev); if (pci_is_bridge(dev)) of_pci_make_dev_node(dev); diff --git a/drivers/pci/of.c b/drivers/pci/of.c index a51dff91b196d..5a040ed836744 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -1085,3 +1085,35 @@ int of_pci_get_equalization_presets(struct device *d= ev, return 0; } EXPORT_SYMBOL_GPL(of_pci_get_equalization_presets); + +/** + * of_pci_verify_node - Sanity check some PCI device node properties + * @pdev: The PCI device whose device node is checked + * + * PCI enumeration authoritatively discovers what we need to know about + * a PCI device. A devicetree-based platform will represent a PCI root + * bridge with a node, but otherwise devicetree doesn't typically include + * many PCI nodes. Where such nodes do exist, experience has shown that + * the "device_type" property is sometimes wrong, so warn about that. + */ +void of_pci_verify_node(struct pci_dev *pdev) +{ + struct device_node *np =3D pci_device_to_OF_node(pdev); + bool device_is_bridge; + bool device_type_pci; + + /* Nothing to check if there's no pre-existing devicetree node */ + if (!np) + return; + + device_is_bridge =3D pci_is_bridge(pdev); + device_type_pci =3D of_node_is_type(np, "pci") || + of_node_is_type(np, "pciex"); + + /* Bridges should have device type "pci"; endpoints should not */ + if (device_is_bridge =3D=3D device_type_pci) + return; + + dev_err(&pdev->dev, "PCI %s have \"pci\" device_type property\n", + device_is_bridge ? "bridge should" : "endpoint should not"); +} diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index ba3c3fddddc23..2e33d3bd4b0ba 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -1253,6 +1253,7 @@ bool of_pci_supply_present(struct device_node *np); int of_pci_get_equalization_presets(struct device *dev, struct pci_eq_presets *presets, int num_lanes); +void of_pci_verify_node(struct pci_dev *pdev); #else static inline int of_get_pci_domain_nr(struct device_node *node) @@ -1308,6 +1309,8 @@ static inline int of_pci_get_equalization_presets(str= uct device *dev, =20 return 0; } + +static inline void of_pci_verify_node(struct pci_dev *pdev) { } #endif /* CONFIG_OF */ =20 struct of_changeset; --=20 2.53.0