linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Young Xiao <92siuyang@gmail.com>
To: bhelgaas@google.com, tyreld@linux.vnet.ibm.com,
	andy.shevchenko@gmail.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Young Xiao <92siuyang@gmail.com>
Subject: [PATCH] PCI/hotplug: fix potential null pointer deference
Date: Fri, 14 Jun 2019 20:41:25 +0800	[thread overview]
Message-ID: <1560516085-3101-1-git-send-email-92siuyang@gmail.com> (raw)

There is otherwise a risk of a null pointer dereference.

Signed-off-by: Young Xiao <92siuyang@gmail.com>
---
 drivers/pci/hotplug/cpqphp_ctrl.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index b7f4e1f..3c8399f 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -598,10 +598,11 @@ static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size
 			*head = node->next;
 		} else {
 			prevnode = *head;
-			while (prevnode->next != node)
+			while (prevnode && prevnode->next != node)
 				prevnode = prevnode->next;
 
-			prevnode->next = node->next;
+			if (prevnode)
+				prevnode->next = node->next;
 		}
 		node->next = NULL;
 		break;
@@ -788,10 +789,11 @@ static struct pci_resource *get_resource(struct pci_resource **head, u32 size)
 			*head = node->next;
 		} else {
 			prevnode = *head;
-			while (prevnode->next != node)
+			while (prevnode && prevnode->next != node)
 				prevnode = prevnode->next;
 
-			prevnode->next = node->next;
+			if (prevnode)
+				prevnode->next = node->next;
 		}
 		node->next = NULL;
 		break;
-- 
2.7.4


             reply	other threads:[~2019-06-14 12:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 12:41 Young Xiao [this message]
2019-06-14 13:56 ` [PATCH] PCI/hotplug: fix potential null pointer deference Andy Shevchenko
2019-08-02  0:14   ` Bjorn Helgaas

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=1560516085-3101-1-git-send-email-92siuyang@gmail.com \
    --to=92siuyang@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=tyreld@linux.vnet.ibm.com \
    /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).