All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tong Zhang <ztong0001@gmail.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Tong Zhang <ztong0001@gmail.com>
Subject: [PATCH] media: cobalt: fix null-ptr-deref when there is no PCI bridge
Date: Fri, 23 Apr 2021 20:52:06 -0400	[thread overview]
Message-ID: <20210424005206.261622-1-ztong0001@gmail.com> (raw)

the PCI bridge might be NULL, so we'd better check before use it

[    1.870569] RIP: 0010:pcie_bus_link_get_lanes.isra.0+0x26/0x59 [cobalt]
[    1.875880] Call Trace:
[    1.876013]  cobalt_probe.cold+0x1be/0xc11 [cobalt]
[    1.876683]  pci_device_probe+0x10f/0x1c0

Signed-off-by: Tong Zhang <ztong0001@gmail.com>
---
 drivers/media/pci/cobalt/cobalt-driver.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
index 0695078ef812..5687ed4869ac 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.c
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -189,6 +189,8 @@ void cobalt_pcie_status_show(struct cobalt *cobalt)
 	u32 capa;
 	u16 stat, ctrl;
 
+	if (!pci_bus_dev)
+		return;
 	if (!pci_is_pcie(pci_dev) || !pci_is_pcie(pci_bus_dev))
 		return;
 
@@ -247,6 +249,8 @@ static unsigned pcie_bus_link_get_lanes(struct cobalt *cobalt)
 	struct pci_dev *pci_dev = cobalt->pci_dev->bus->self;
 	u32 link;
 
+	if (!pci_dev)
+		return 0;
 	if (!pci_is_pcie(pci_dev))
 		return 0;
 	pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &link);
-- 
2.25.1


             reply	other threads:[~2021-04-24  0:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-24  0:52 Tong Zhang [this message]
2021-05-05  9:18 ` [PATCH] media: cobalt: fix null-ptr-deref when there is no PCI bridge Hans Verkuil
2021-05-10 22:32   ` Tong Zhang
2021-05-26 13:07     ` Hans Verkuil

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=20210424005206.261622-1-ztong0001@gmail.com \
    --to=ztong0001@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.