From nobody Fri Sep 25 20:02:12 2026 Received: from mail-yx2-f13.google.com (mail-yx2-f13.google.com [74.125.224.141]) (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 C33CC49E5D8 for ; Thu, 24 Sep 2026 15:02:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790262153; cv=none; b=dNbCvE0w45aKKvtyAEBgX+oXc13fbx0TIvDUSSm6K2VrPvAKKwIUsr3XQMs23nOZfq5kD+c9JR/xK1OzyKBfBwfQ2Z98AljcUiRmLGl5fIwO11vWsDhJugLJKBykvT4TxUdzaJtqqBOWqdk2L8voUaxqAkuGV3328rw1O+tdECs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790262153; c=relaxed/simple; bh=DIq6nTK8Z21Q2/ZIKptExaqVF0kK/MKFX+uQOTHBBhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hQxrsgdcStDzXHgZ+0Dzsp5DB0xXzOzZtcYmqFBP74JdLdVq8fnUvCLgWtddSnh1mpGUuH8LTFkff1Dc6VM+JfEMaL4cZAxz6gLFSGJTs4uU5bRbPy7NVqVixEeUwFN6nKx0V3LxeDfFkwpBeR1m4drP+TMW2zIZfAZuWY8Wt7o= 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=UHUzav33; arc=none smtp.client-ip=74.125.224.141 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="UHUzav33" Received: by mail-yx2-f13.google.com with SMTP id 956f58d0204a3-66f7f72a284so2542485d50.2 for ; Thu, 24 Sep 2026 08:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1790262148; x=1790866948; 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=qN0LJ3BGMSnR0ykGO4CGo4WAreVGKZ321n3p4N5ko7w=; b=UHUzav33fWRrDjyDsjaZN+FI0NFW1Uln4jOpHslNg962/jxg85bt1FKbKKLBompjab Mqq8Ln5E0A//uflXMkNohG935mLJo5xXTjI1z1jYuKwoGI0xIRWM6n20JCPWn00HdVMz pAmdhLZhWXcmd1K+pVj9v2aiQTn//95dAiUTg5b/b8Ge1d0D7lTs5dNOFZLMsLDjjlXU w9Tyal7JB4yJxuib9BwV2De74NSCDIriAnojTRVkSIxiNhNsqbZuF9JX9H+gfQBjW9nc rb9dYlNj2Im/u3n3xTAyEE0jJ6MVariQiiOV9D/2wSi/pLjszX5UoJKm6c0AetSXYD5M uSNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790262148; x=1790866948; 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=qN0LJ3BGMSnR0ykGO4CGo4WAreVGKZ321n3p4N5ko7w=; b=MbfbjbYBHRINh5FPXGlaO77JQz2F53QtYXc9PLmZR+YxZvYdQmi6ZxJ6qKlgQ3ZGOe V4RgQCWSH3GRk649ezmBhvk1vCajgQ2XaB59JBEXZz9+pnUbb+GUbPyzBljW9bGM6Ukp LXDqCnC2NPNYpy4L+anIRF8Q6QrCmgHJrIKxcm8IozCa3gm4SC708cRtJsXjoa+HqLOO Z46O3lC5/E9/6E7E4p4W/ro4zep77G4uEl8xdfRV7MfpA5sW+djU1QBCIvXNXefvuQ0g xSOBTNaDqt9Z4QN/pp+4do05p/37qILOJp3vwavV+Ng0IfLw6i8gZ2PbVtUN5mky+qZk pKuA== X-Forwarded-Encrypted: i=1; AKwUvByBbABU62fd1MhXax+oxqePvYtDgsTgk9oIqmAKjy2BD+1YC/Xld9Xr2kgFZo3rEr6tdgDfKti5kgsDPO0=@vger.kernel.org X-Gm-Message-State: AFuF++lT6JfQwWCG44iGlQ06Rhhvo6Z9RRWSaLm8u8+Aq4/0TZhx0Ao2 rV1ZlxznLYNq2tbR/0g4piMXttj9xScTgCPEHQkV/FuK4vdr53uQGAZDnToa1Dqfc08= X-Gm-Gg: AYBFou02HL0KgyosC9F0eJqWv3P1pVbe51tP18H/u15efffBULIDjhYdgVzq1m/cqvo fB4WKmv77aVdUN3XPOHTfdNESvwHQZ+96tcpKoo5iSJWrbQbijWyDy6Z6mS7YSJ7Rn9AxeEsLKs rmoGuLsYor4B6YaOfSsN18fRX72Hgc22XCUdMDqhwQq+txMBIUCN9U5PH0rdZmbdj6lu5nTXK7z +JSv0qols4OIZHAYwzl3TAzgN+/pnfbtNmVfHe/ehJKSzzcqWaYIwcPpONQcma9sxK6r327g9UF e2DqZKVjl7LkRsakQd8OdseRyef3xFkMuxZe11ott2GuLCJP3No39/9NaIPmZ7CXtwgm2CxKNWn Lye3XbufSkmsvl00qcEdn102zWdV0LXTB3kxCZX6mYNQYDw2ikfciAfQ3Uins8eYdmrAeeJvrL9 yoQff664RbnXetsnxbimLt36zDlB9VJbZtIfGJw8DW2aiZ82hv5yhgXUNwpS56eAtLIFuvOeonU fw= X-Received: by 2002:a05:690e:4383:b0:671:2ab1:899c with SMTP id 956f58d0204a3-672ed50c6c5mr1315067d50.89.1790262148054; Thu, 24 Sep 2026 08:02:28 -0700 (PDT) Received: from zippy.localdomain ([73.62.185.64]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9141e24e458sm18438236d6.21.2026.09.24.08.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 08:02:27 -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 v6 1/4] PCI: of: avoid allocations in of_pci_prop_compatible() Date: Thu, 24 Sep 2026 10:02:18 -0500 Message-ID: <20260924150222.1179235-2-elder@riscstar.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260924150222.1179235-1-elder@riscstar.com> References: <20260924150222.1179235-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 --- drivers/pci/of_property.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c index 75a358f73e694..d66c702218081 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 }; - int i, ret; + char buf[PROP_COMPAT_NUM * PROP_SIZE] =3D { }; + char *bufp =3D buf; + int 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 Fri Sep 25 20:02:12 2026 Received: from mail-yx2-f42.google.com (mail-yx2-f42.google.com [74.125.224.170]) (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 5BBD53D8123 for ; Thu, 24 Sep 2026 15:02:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790262155; cv=none; b=N5ypLWcZ/uF3fbDB/Y0OcsJtZelQFXKChtYt52JrisGZ+UPsN+gqJ5Q00NRDOWgg0bIvISzOiAUid8i4CKUqKWd5ShtDHHdzngeK553C8T/XfT+9ikmq/Iho4J23+KM00hPBRHYgJrgOrdFDIvkdL2o0T/c8GiIGVvOxqIdXTZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790262155; c=relaxed/simple; bh=dSVFMgBYNWS5F0FgVH/G2sJcIm/aUqTCSZVMKsCMKP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sC0YGE5Ep4e9Bj0fqscba+XwLUFkWrqeSNRB3sURWnoK2nwLeWkPnxx4WubH/LGTU2UUk1+4SzrIR80ba3laZsz3tpFC3jgKutKhvrB8kIghJ7jRpm3OYYTkLHliCW0LDdM/UfOCAX91tAu/csYEQlQ80XzhuC0QVqgSXxyy1Vk= 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=QrWyUEkh; arc=none smtp.client-ip=74.125.224.170 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="QrWyUEkh" Received: by mail-yx2-f42.google.com with SMTP id 00721157ae682-895fd505824so27221257b3.1 for ; Thu, 24 Sep 2026 08:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1790262149; x=1790866949; 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=tbp0io90tD3hLKOmsDGrt9wIS9lt0GeXuRra07vYj6c=; b=QrWyUEkhp4k1CScxiasUe0+8crFmEganHkO7zzka6KBNitcnC6tS9CW6pow2XyLVPA xR/v5tqYM2Gnars7P6jKSvhfGBfU8c1OehY2nR9ucAmfUYg77dLrLmf6PIerVqg/u9CG G/6+TC6g6GVKyr1kqfOyT/yfdlDL1GicL40633poNzXzrGHm2Nj/xfzkIZSkFreLoHNw Q3bFgbOxAnhzv1UzTzoYwnsMBeA4QHW3Vusn78hMD4RffPj/F1azaCZ7R/zGfH43n71J sr6dqI2DEDCkrLMxVfw7w4g4vWnf/btoQ1DlYBIVLpMFsx3lMRVHFUJsl5XeQKPl1JvL pytA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790262149; x=1790866949; 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=tbp0io90tD3hLKOmsDGrt9wIS9lt0GeXuRra07vYj6c=; b=CZ0FYXEwrQzYrm4Nj+Xd2WmmxDDiALepdxNAxiLOjn6UZwa7sCVYVLZoGVWjqvP6gO 7ynXE3e5nVxa1aRPWqCZ2+sBwigBBUzgmB60mWSlCG8rQL9XoYpR50nb+JclWiNVm4ac +0VITCQn1mEZ/rfcCARx+2mjcCWQB82f962wSPk8u6FGhbimO4gDvO/jVIzYzawL+m9D Ohj8WVQvrs4Oc5OAFlWhpKkT8EgBftXcpJ+wwCquIqdevwvW8bIA67hxZ/HZhgtp8jl6 gjbpw6C0hSQ98D+WTayUecT7CbEjSIk03T6LkRBewfBswpjvpQTSiqHt2T1wK6Co28Dh lHWw== X-Forwarded-Encrypted: i=1; AKwUvBwWcal3YTxZozDbrkmXRX7VeTK+WkLY9QsBw7qW3LoN6QXPwsz/ToS/JD905ronAwQAaHR07872sVlJl8A=@vger.kernel.org X-Gm-Message-State: AFq9FYJLqCJQshuTZiD7Cmjp5X6ksEWYIq8eSSQLhJItzGUKD2Dq5G5T ueVVTPqw10ymvAjMI8FkXjjmYRJ9igbLZtwMQSWMXCyDaqLMRmyvjzYG5WRv9oS/MJg= X-Gm-Gg: AYBFou0z5p+9WjMflKPiVf8XKO70rDkQiELxaR4nE9lsi7ZZbWRPxwA4JSJ4Vtx0ckZ 21tpsfwzInSPFqvvBm+pE0sOZAdymOgfHDI138LzgQFKReW621DMeONp1wKoZ4qs38lA2nNntfl x92Qyt6NsL8ZGOnGO9xT8h+Gk5h6ATRDSMYum4HksbEtAkpMa0pSZzKcvfiMHyLD9UTXRbnlNG2 aD5HkMPaG55r5Ja6x/uqMxLw0JYrllTQeI8rvRJBCphLXIWOhgW2ZTh7ssHiG5F8ZkVL4cNucha f3MaIA5MVjDcd3cuW6CabDoaAD8BKYerZBtG7scwbmBtei0njVEC2X1lFFVbB79H305zvTccPQ0 WAMmKNdH+q2zhBz/HN61MY8DyC2UUGSmca/Vbm1iypxFFK5iaf+TMDpYMarNXX0fAaxNzeM9tXx R4c8tbIES3axQFu9FBuKyYdv33vGFS1LW4JNInQh3Wr7F401NlMBm6GF4ewC4HpnNbhb8EYSXP1 lP7K7UGsOv6Sg== X-Received: by 2002:a05:690c:85:b0:8a0:e27e:8e75 with SMTP id 00721157ae682-8a64e5bf22amr14434227b3.82.1790262149073; Thu, 24 Sep 2026 08:02:29 -0700 (PDT) Received: from zippy.localdomain ([73.62.185.64]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9141e24e458sm18438236d6.21.2026.09.24.08.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 08:02:28 -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 v6 2/4] PCI: of: drop the reg_num argument to of_pci_set_address() Date: Thu, 24 Sep 2026 10:02:19 -0500 Message-ID: <20260924150222.1179235-3-elder@riscstar.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260924150222.1179235-1-elder@riscstar.com> References: <20260924150222.1179235-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 d66c702218081..1caabbd4c18b5 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 Fri Sep 25 20:02:12 2026 Received: from mail-vs2-f41.google.com (mail-vs2-f41.google.com [74.125.227.41]) (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 B4BBC49DB99 for ; Thu, 24 Sep 2026 15:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790262156; cv=none; b=mvsVSwnUb3OxHr93M0YMkGNapu7n30dBFVUN+zhX+bZpz25g451mhwMQcNWRPufztyKDgHuKD5dDWNUcWO98nKlPBhtblsWYsoLjjmt1rb6RXX0T/rQH4yPxMPYCou5m7CakpWqODOHC//lrHezc1lTWPIYdHBlEbBRTJLhKgEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790262156; c=relaxed/simple; bh=QDjh/o/EJT+5EmtaVLbTs0ss1hLQGrJ710TUSyqfmVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rO8D7sYMXtNj0IbNe3inx6NecdEF7RQlR74oLcChEeCyRNiVpoYnTRJxTWyUhJLDrRLWN734xFQKuWnXeop3OB18BFpYh9n6np5fQTcyh+DEkxUC8p/Tab4NNGiOVZ+23poaFZ+CCoUem8jN5tIeexq7ah8+2Y1nhfeoQyxlVLI= 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=Qgl9uDrH; arc=none smtp.client-ip=74.125.227.41 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="Qgl9uDrH" Received: by mail-vs2-f41.google.com with SMTP id ada2fe7eead31-78564313adaso769777137.3 for ; Thu, 24 Sep 2026 08:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1790262150; x=1790866950; 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=Tf53B7+IQ/UMJpYYTrZ14GDqT88z18YWAe/D6JaHkeo=; b=Qgl9uDrHSIv8lbifsEPuIq/c6HjBnJym/e3UOXa9BXww5Dt2g7LU0XIdIVzHUMwhXd G3zRw59zuN2nCQN31f3FeC1lnaMiqKrNnKS1mTQFx5izodAPVk4ueNp/1EfXUNvxM0i7 7NJjSaq5quddGYTKGUI17Kjort/TyhQhlMOQVUhVqaGyqs/HBOTxw7X8cqJ9HevaZWAY V+aQLx9ixHLLScIlAvjcPAhBKz0IQnyiIJmrKmw9x89J5I8wHs783kAdPCv3Ih8s3N0i /t81pRzl6zurc2Xo0+GVHLlXaZHOUDkUYrZwEtjLjj1reamYEX0PohgvxCwmvqskrsbO C1+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790262150; x=1790866950; 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=Tf53B7+IQ/UMJpYYTrZ14GDqT88z18YWAe/D6JaHkeo=; b=lQ0++Oo7wTN4bu2LiUUrnpPhptHFfvIuzxocC7Bs6ckezSnRwmD3CiLW+94FLSjir7 EPfegkVXzCmDVaHZ5PiLJHgYM3g7WPU0oR8itK3b4fv62omjtwI1cLm+vicrsmVftQ1w wFypFiIToz3lxQeSIFvqmye+v2SWVmNU7KBqr3kP4SrdfnjlREferI8w8cGS/bLpAJaP Kwf0ekCrFs352TWUFI+8Zd7OUAor5mMvkqzCvrQKK915vOw0f+nw7jjtfoYbQoYmRAdF nT4rfks6zncw+zH0LPlAmKi2yYRe/DXqjb896zTA45gXr+9MUg6Uh6uM0n+5Z3c2Ac6e v9+Q== X-Forwarded-Encrypted: i=1; AKwUvBybNTPwdn/2OBNbxAVWLCLyHYXMAsQ8LjuPokXFy5sNahy++HlLMpNWDyl/1TxtLIVPeZty6+VoyFTouD0=@vger.kernel.org X-Gm-Message-State: AFuF++kVjD2SFptMM+eoYfbHL2zpbpYLtN8F1W/INTs3+OCi/UUkks2E cq3dW0uydInd1pHtgwPwVqueGp3VFQS92Rxa+IX7KAPnIe3rTKEODDU/ofeQbwHpAE8= X-Gm-Gg: AYBFou3DvkOlm2pgPcE2W5LRF4op2yk7hnMe7tZZgCbC2iyYch02MRJ/yn7fA1D3SuO WX6f1biTDfTmMH6xdIRn2NAqNTekAXIlN2Rxblz1ljQBvQGjRx58OCypx7OJ3IUIE0Xzna3LTQF vvKJpvj57MjXnuCVfedKgrRrPamZ3vM+w9rSb9WR1EhzCqcMZp+4IL79cIbzTolC9zTBYBfXXF+ wUb4VTx/huuwMHcPoS4/bzGdKInldXV5d4+u2ocoHSRcFq3pe52vOgnLtQBDPBZ9bV8QiIbYoQl OJ4oRIQyFFVzKRVa3b3401FpcAbKRH019jyviOHQjX9BvIm5KFoFrxjhzkNVm7WaMJpm6vOhhfY E6XC2Ja0rzhJqHsDKZkh6KkVbess+lR5tnE9WuEbmPTec0lL3qcpd4evLP8FUHlWJtuTpvjPPy+ 9kP6ggH+YsuA3KqRbGpfzF323K+WDuG4/Pv08gQIGiTlGxH7KTDaYt7MHLE0AYSM1ElTWqXNI= X-Received: by 2002:a05:6102:4b14:b0:79c:99ea:2c9a with SMTP id ada2fe7eead31-7af1cba3036mr1226812137.11.1790262150404; Thu, 24 Sep 2026 08:02:30 -0700 (PDT) Received: from zippy.localdomain ([73.62.185.64]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9141e24e458sm18438236d6.21.2026.09.24.08.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 08:02:29 -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 v6 3/4] PCI: of: don't zero flags in of_pci_get_addr_flags() Date: Thu, 24 Sep 2026 10:02:20 -0500 Message-ID: <20260924150222.1179235-4-elder@riscstar.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260924150222.1179235-1-elder@riscstar.com> References: <20260924150222.1179235-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 1caabbd4c18b5..1e5d7dde467b8 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 Fri Sep 25 20:02:12 2026 Received: from mail-qk2-f13.google.com (mail-qk2-f13.google.com [74.125.230.205]) (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 2F33449EC79 for ; Thu, 24 Sep 2026 15:02:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.230.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790262156; cv=none; b=U9F2I17peUWMPy3ZNRm6MqbYFInSwCwEqeTsWpj8kKkkRKLepe4/sSTc7Ehf8W0akksQdY6/utP/jrDzQv6jtEsr6lQPN2mYPDoUAIQ13OiI04DJI9GgChKpzpfQHcLq1RRQtfwrGMfKwqtrYCAOsaFGgoXWgIfTebN+3wTsoZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790262156; c=relaxed/simple; bh=X1KXs+i5uL9uwAw7KV41qBYIJSZ3+jEh3Bc9Sxzdsps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R7LOVy+bkFtcvXllKVNDsP+wvjgRgOGu8sTO12VOjvDmwTA8vVg6D6Qws5+8X0uNvhEYo5SUvTQB1YsyTWYfAFjoXuiBnjI1QlT6eUfCb/nqhK39J5r8zJq2hhuYzjLqAAzDqdO9KlEfvzk1oeKpDFkHIc8Za6TEiAEeuYWVye8= 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=xhDNwbl0; arc=none smtp.client-ip=74.125.230.205 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="xhDNwbl0" Received: by mail-qk2-f13.google.com with SMTP id d75a77b69052e-52fb76ec504so13949011cf.3 for ; Thu, 24 Sep 2026 08:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riscstar-com.20251104.gappssmtp.com; s=20251104; t=1790262152; x=1790866952; 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=fLSKarAZusXR0W9CXQ8qq3Qvo3B/rbo6r97R+Zk/6MU=; b=xhDNwbl0jSobv0z6BMv6cqJkaf6/0KFlt69f/TFEt9uju+7arJcP0/mQE1rFure/+G RSpckLxPez+IPmN2AGJLxF1uGJGUTTb4HU74FIYZ8XArPtkDN76Y40fztVKRzZmT4s5O Cnsr4VKKtD72gGuFngkNPMYoOt4XBFG0bFl7CGgLjaZRZtPk9c7770LlV3jHl1k6BlqQ 8MP1mAJZ8QRzp4/GrSmD1H3Nw5VDlNAovGZVqN/X9uZN08Wobj+pGOtngq3t9o8pl/6o iNUL8wNxaos5rQWT6+1Zj7hmuzaE71zHmcbknoGqn+ejck8TmCKnW/up5rwzQ48tCLME oJQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790262152; x=1790866952; 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=fLSKarAZusXR0W9CXQ8qq3Qvo3B/rbo6r97R+Zk/6MU=; b=WtBfpDsO+YRy6R5cjkxdzAcuQXMVnZbIQH3fkpvt0CkvrdlYmakJKQGlEQQVV0c11f awT/vaGxSNZLRuRkAAKKP/sSdhqRuFLXxgAdtyP45p1STUYHvuqKsgt2egw8OjKnJzHu f17f1ci8UEFd+mxVAfiTMKouVf8FzE2fRTdn51on1Tv9YZSvR0cYHS13wcRYslqkbiwD DwWbK5AwuxKwu8OKU3ObCPqqQQBRoMB2r0saop/PbenMJfkaDDKCw5OW0J+XS00MCZmA fDrIAgrPNKlDZyqgaAAc1yU765uloaH+rLfMI9tzixAVEkrRIMRDl5kH3iVOO7hihUhh iNSg== X-Forwarded-Encrypted: i=1; AKwUvBxizcZ5SCvL4b8vFKd8X8+HqIYO2uqAvftrsKMvbNZ5v99vxM4hv98D0By9EFXIXQs32I3+Neu0cDV1HPc=@vger.kernel.org X-Gm-Message-State: AFuF++lHdAQqTWvknh2ra4VHUE8A+NtwfjHabnalsmO3fMjsjLl5ujxe 50u6DR3Dwkza/KVA0nn+5pCnQfbEQ1jgOqZ/1TIC5URtzxSYm27sQTxcRdrHQvN0q24= X-Gm-Gg: AYBFou2U3cD/IWOGv6L6mqqpaqXZ5Ark9ocogNVt5HiDi1bGkDlTSFJXXuNJ8J8U3XU 0ZNBiSoX4vZVwUh2+gEBh8rV3y7z5Tx94zrhqxz2d7X5YdZaSI2pH+RcvRaNu0uTWA0yl6ejBw/ G12NDtLSGIR0g0LUtmgggMchshxV+zQNxuU8MOA30zVfCs+KfdwZ8s7rhyP2uh2gBwlLVcdscrq 8gRhxLEa9tSEdPS4JBSrtf++6mC1hWDeihv17ZiUbHIBOVguVdJUbJ/qNis1Dt42NwA9tSqeyBu pr3SeXgahLkAdvGJJrZiFrWRRLYAwPlta1qsouhfmu4aUA2hRRHoGadJaH2lehCZFpZzM2u0KMk QHlMnL8/C4jVF9ZufZvngs+FQGgMG090UtvAACfDbQYuRDDHqc4FD6RToSE9+Dx20lpin5CSoFe dLsyiFCT4JtgVFAXKp+d0IEbA9BHVfOvxfznttQPcaPn2OWnvdcBQEsw33q8eckkgvh7kDOH6h+ ow/ X-Received: by 2002:a05:6214:4801:b0:912:588d:55e8 with SMTP id 6a1803df08f44-91421c8bf57mr26174106d6.9.1790262151859; Thu, 24 Sep 2026 08:02:31 -0700 (PDT) Received: from zippy.localdomain ([73.62.185.64]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9141e24e458sm18438236d6.21.2026.09.24.08.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 08:02:31 -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 v6 4/4] PCI: of: introduce of_pci_verify_node() Date: Thu, 24 Sep 2026 10:02:21 -0500 Message-ID: <20260924150222.1179235-5-elder@riscstar.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260924150222.1179235-1-elder@riscstar.com> References: <20260924150222.1179235-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 Open Firmware PCI Bus Supplement and Devicetree Specification reserves the device_type property for PCI bridge nodes (with value "pci" or "pciex"). Non-bridge PCI endpoint nodes must not include this property. Rob Herring observed that developers seem to get this wrong. Commit df4107fc729e3 ("arm64: dts: qcom: qcs6490-rb3gen2: clean up PCI function nodes") and a few that follow demonstrate this. Rob requested that a runtime check 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" or "pciex". Implement these suggested warnings in of_pci_verify_node(), a new function called by pci_bus_add_device() for both bridges and endpoints. If a PCI bridge has a devicetree node, a warning is issued if it has a device_type property whose value is not "pci" or "pciex" (or if it has no such property). Similarly, a warning is issued for an endpoint if it has a device_type property having one of those two values. To be clear, this adds warnings, but otherwise ignores the errors it warns about. It is meant to help developers; users should never see them. Reviewed-by: Herve Codina Signed-off-by: Alex Elder --- 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