diff mbox series

PCI: Fix null pointer dereference in of_pci_prop_compatible

Message ID 20231204062245.2453512-1-chentao@kylinos.cn (mailing list archive)
State New
Delegated to: Bjorn Helgaas
Headers show
Series PCI: Fix null pointer dereference in of_pci_prop_compatible | expand

Commit Message

Kunwu Chan Dec. 4, 2023, 6:22 a.m. UTC
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure.

Fixes: 407d1a51921e ("PCI: Create device tree node for bridge")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/pci/of_property.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c
index c2c7334152bc..5e16bbff3ba4 100644
--- a/drivers/pci/of_property.c
+++ b/drivers/pci/of_property.c
@@ -304,6 +304,11 @@  static int of_pci_prop_compatible(struct pci_dev *pdev,
 	compat_strs[PROP_COMPAT_PCICLASS_CCSS] =
 		kasprintf(GFP_KERNEL, "pciclass,%04x", pdev->class >> 8);
 
+	if (!compat_strs[PROP_COMPAT_PCI_VVVV_DDDD] ||
+	    !compat_strs[PROP_COMPAT_PCICLASS_CCSSPP] ||
+	    !compat_strs[PROP_COMPAT_PCICLASS_CCSS])
+		return -ENOMEM;
+
 	ret = of_changeset_add_prop_string_array(ocs, np, "compatible",
 						 compat_strs, PROP_COMPAT_NUM);
 	for (i = 0; i < PROP_COMPAT_NUM; i++)