linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kunwu Chan <chentao@kylinos.cn>
To: bhelgaas@google.com, lizhi.hou@amd.com, robh@kernel.org
Cc: kunwu.chan@hotmail.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org, Kunwu Chan <chentao@kylinos.cn>
Subject: [PATCH] PCI: Fix null pointer dereference in of_pci_prop_compatible
Date: Mon,  4 Dec 2023 14:22:45 +0800	[thread overview]
Message-ID: <20231204062245.2453512-1-chentao@kylinos.cn> (raw)

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 --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++)
-- 
2.34.1


                 reply	other threads:[~2023-12-04  6:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231204062245.2453512-1-chentao@kylinos.cn \
    --to=chentao@kylinos.cn \
    --cc=bhelgaas@google.com \
    --cc=kunwu.chan@hotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lizhi.hou@amd.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).