linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: cpqphp: Fix possible NULL pointer dereference
@ 2018-02-25  2:01 Shawn Lin
  2018-02-28 20:37 ` Bjorn Helgaas
  0 siblings, 1 reply; 2+ messages in thread
From: Shawn Lin @ 2018-02-25  2:01 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Shawn Lin

io_node is used before verify whether it's null pointer,
so move the check of null pointer immediately after.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/pci/hotplug/cpqphp_ctrl.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index b1b6e45..616df44 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -2812,18 +2812,16 @@ static int configure_new_function(struct controller *ctrl, struct pci_func *func
 
 					dbg("CND:      length = 0x%x\n", base);
 					io_node = get_io_resource(&(resources->io_head), base);
+					if (!io_node)
+						return -ENOMEM;
 					dbg("Got io_node start = %8.8x, length = %8.8x next (%p)\n",
 					    io_node->base, io_node->length, io_node->next);
 					dbg("func (%p) io_head (%p)\n", func, func->io_head);
 
 					/* allocate the resource to the board */
-					if (io_node) {
-						base = io_node->base;
-
-						io_node->next = func->io_head;
-						func->io_head = io_node;
-					} else
-						return -ENOMEM;
+					base = io_node->base;
+					io_node->next = func->io_head;
+					func->io_head = io_node;
 				} else if ((temp_register & 0x0BL) == 0x08) {
 					/* Map prefetchable memory */
 					base = temp_register & 0xFFFFFFF0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] PCI: cpqphp: Fix possible NULL pointer dereference
  2018-02-25  2:01 [PATCH] PCI: cpqphp: Fix possible NULL pointer dereference Shawn Lin
@ 2018-02-28 20:37 ` Bjorn Helgaas
  0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2018-02-28 20:37 UTC (permalink / raw)
  To: Shawn Lin; +Cc: Bjorn Helgaas, linux-pci

On Sun, Feb 25, 2018 at 10:01:42AM +0800, Shawn Lin wrote:
> io_node is used before verify whether it's null pointer,
> so move the check of null pointer immediately after.
> 
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

Applied to pci/hotplug for v4.17, thanks!

> ---
> 
>  drivers/pci/hotplug/cpqphp_ctrl.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
> index b1b6e45..616df44 100644
> --- a/drivers/pci/hotplug/cpqphp_ctrl.c
> +++ b/drivers/pci/hotplug/cpqphp_ctrl.c
> @@ -2812,18 +2812,16 @@ static int configure_new_function(struct controller *ctrl, struct pci_func *func
>  
>  					dbg("CND:      length = 0x%x\n", base);
>  					io_node = get_io_resource(&(resources->io_head), base);
> +					if (!io_node)
> +						return -ENOMEM;
>  					dbg("Got io_node start = %8.8x, length = %8.8x next (%p)\n",
>  					    io_node->base, io_node->length, io_node->next);
>  					dbg("func (%p) io_head (%p)\n", func, func->io_head);
>  
>  					/* allocate the resource to the board */
> -					if (io_node) {
> -						base = io_node->base;
> -
> -						io_node->next = func->io_head;
> -						func->io_head = io_node;
> -					} else
> -						return -ENOMEM;
> +					base = io_node->base;
> +					io_node->next = func->io_head;
> +					func->io_head = io_node;
>  				} else if ((temp_register & 0x0BL) == 0x08) {
>  					/* Map prefetchable memory */
>  					base = temp_register & 0xFFFFFFF0;
> -- 
> 1.9.1
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-28 20:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-25  2:01 [PATCH] PCI: cpqphp: Fix possible NULL pointer dereference Shawn Lin
2018-02-28 20:37 ` Bjorn Helgaas

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).