All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
@ 2019-03-23 21:04 ` Aditya Pakki
  0 siblings, 0 replies; 10+ messages in thread
From: Aditya Pakki @ 2019-03-23 21:04 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, Lorenzo Pieralisi, Bjorn Helgaas, Michal Simek, linux-pci,
	linux-arm-kernel, linux-kernel

In case __get_free_pages fail, the fix returns error upstream
to avoid NULL pointer dereference.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>

---
v1: Return error upstream as suggested by Steven
---
 drivers/pci/controller/pcie-xilinx.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
index 9bd1a35cd5d8..91d8945bfb0c 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -335,15 +335,19 @@ static const struct irq_domain_ops msi_domain_ops = {
 /**
  * xilinx_pcie_enable_msi - Enable MSI support
  * @port: PCIe port information
+ * Return: 0 on success, negative error on failure
  */
-static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
+static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
 {
 	phys_addr_t msg_addr;
 
 	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
+	if (!port->msi_pages)
+		return -ENOMEM;
 	msg_addr = virt_to_phys((void *)port->msi_pages);
 	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
 	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
+	return 0;
 }
 
 /* INTx Functions */
@@ -498,6 +502,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 	struct device *dev = port->dev;
 	struct device_node *node = dev->of_node;
 	struct device_node *pcie_intc_node;
+	int ret;
 
 	/* Setup INTx */
 	pcie_intc_node = of_get_next_child(node, NULL);
@@ -526,7 +531,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 			return -ENODEV;
 		}
 
-		xilinx_pcie_enable_msi(port);
+		ret = xilinx_pcie_enable_msi(port);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
-- 
2.17.1


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

* [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
@ 2019-03-23 21:04 ` Aditya Pakki
  0 siblings, 0 replies; 10+ messages in thread
From: Aditya Pakki @ 2019-03-23 21:04 UTC (permalink / raw)
  To: pakki001
  Cc: Lorenzo Pieralisi, linux-pci, kjlu, Michal Simek, linux-kernel,
	Bjorn Helgaas, linux-arm-kernel

In case __get_free_pages fail, the fix returns error upstream
to avoid NULL pointer dereference.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>

---
v1: Return error upstream as suggested by Steven
---
 drivers/pci/controller/pcie-xilinx.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
index 9bd1a35cd5d8..91d8945bfb0c 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -335,15 +335,19 @@ static const struct irq_domain_ops msi_domain_ops = {
 /**
  * xilinx_pcie_enable_msi - Enable MSI support
  * @port: PCIe port information
+ * Return: 0 on success, negative error on failure
  */
-static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
+static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
 {
 	phys_addr_t msg_addr;
 
 	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
+	if (!port->msi_pages)
+		return -ENOMEM;
 	msg_addr = virt_to_phys((void *)port->msi_pages);
 	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
 	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
+	return 0;
 }
 
 /* INTx Functions */
@@ -498,6 +502,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 	struct device *dev = port->dev;
 	struct device_node *node = dev->of_node;
 	struct device_node *pcie_intc_node;
+	int ret;
 
 	/* Setup INTx */
 	pcie_intc_node = of_get_next_child(node, NULL);
@@ -526,7 +531,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 			return -ENODEV;
 		}
 
-		xilinx_pcie_enable_msi(port);
+		ret = xilinx_pcie_enable_msi(port);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
  2019-03-23 21:04 ` Aditya Pakki
@ 2019-03-25 12:08   ` Steven Price
  -1 siblings, 0 replies; 10+ messages in thread
From: Steven Price @ 2019-03-25 12:08 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Lorenzo Pieralisi, linux-pci, kjlu, Michal Simek, linux-kernel,
	Bjorn Helgaas, linux-arm-kernel

On 23/03/2019 21:04, Aditya Pakki wrote:
> In case __get_free_pages fail, the fix returns error upstream
> to avoid NULL pointer dereference.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>

Reviewed-by: Steven Price <steven.price@arm.com>

> 
> ---
> v1: Return error upstream as suggested by Steven
> ---
>  drivers/pci/controller/pcie-xilinx.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
> index 9bd1a35cd5d8..91d8945bfb0c 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -335,15 +335,19 @@ static const struct irq_domain_ops msi_domain_ops = {
>  /**
>   * xilinx_pcie_enable_msi - Enable MSI support
>   * @port: PCIe port information
> + * Return: 0 on success, negative error on failure
>   */
> -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
> +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
>  {
>  	phys_addr_t msg_addr;
>  
>  	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
> +	if (!port->msi_pages)
> +		return -ENOMEM;
>  	msg_addr = virt_to_phys((void *)port->msi_pages);
>  	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
>  	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
> +	return 0;
>  }
>  
>  /* INTx Functions */
> @@ -498,6 +502,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>  	struct device *dev = port->dev;
>  	struct device_node *node = dev->of_node;
>  	struct device_node *pcie_intc_node;
> +	int ret;
>  
>  	/* Setup INTx */
>  	pcie_intc_node = of_get_next_child(node, NULL);
> @@ -526,7 +531,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>  			return -ENODEV;
>  		}
>  
> -		xilinx_pcie_enable_msi(port);
> +		ret = xilinx_pcie_enable_msi(port);
> +		if (ret)
> +			return ret;
>  	}
>  
>  	return 0;
> 


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

* Re: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
@ 2019-03-25 12:08   ` Steven Price
  0 siblings, 0 replies; 10+ messages in thread
From: Steven Price @ 2019-03-25 12:08 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Lorenzo Pieralisi, linux-pci, kjlu, Michal Simek, linux-kernel,
	Bjorn Helgaas, linux-arm-kernel

On 23/03/2019 21:04, Aditya Pakki wrote:
> In case __get_free_pages fail, the fix returns error upstream
> to avoid NULL pointer dereference.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>

Reviewed-by: Steven Price <steven.price@arm.com>

> 
> ---
> v1: Return error upstream as suggested by Steven
> ---
>  drivers/pci/controller/pcie-xilinx.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
> index 9bd1a35cd5d8..91d8945bfb0c 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -335,15 +335,19 @@ static const struct irq_domain_ops msi_domain_ops = {
>  /**
>   * xilinx_pcie_enable_msi - Enable MSI support
>   * @port: PCIe port information
> + * Return: 0 on success, negative error on failure
>   */
> -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
> +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
>  {
>  	phys_addr_t msg_addr;
>  
>  	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
> +	if (!port->msi_pages)
> +		return -ENOMEM;
>  	msg_addr = virt_to_phys((void *)port->msi_pages);
>  	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
>  	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
> +	return 0;
>  }
>  
>  /* INTx Functions */
> @@ -498,6 +502,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>  	struct device *dev = port->dev;
>  	struct device_node *node = dev->of_node;
>  	struct device_node *pcie_intc_node;
> +	int ret;
>  
>  	/* Setup INTx */
>  	pcie_intc_node = of_get_next_child(node, NULL);
> @@ -526,7 +531,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>  			return -ENODEV;
>  		}
>  
> -		xilinx_pcie_enable_msi(port);
> +		ret = xilinx_pcie_enable_msi(port);
> +		if (ret)
> +			return ret;
>  	}
>  
>  	return 0;
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
  2019-03-23 21:04 ` Aditya Pakki
@ 2019-03-26 13:01   ` Robin Murphy
  -1 siblings, 0 replies; 10+ messages in thread
From: Robin Murphy @ 2019-03-26 13:01 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Lorenzo Pieralisi, linux-pci, kjlu, Michal Simek, linux-kernel,
	Bjorn Helgaas, linux-arm-kernel

On 23/03/2019 21:04, Aditya Pakki wrote:
> In case __get_free_pages fail, the fix returns error upstream
> to avoid NULL pointer dereference.

Where does msi_pages ever get dereferenced?

The logic here might actually still have a chance of working out OK with 
NULL depending on how the memory maps line up, but even if it doesn't, 
the problem is certainly not one of dereferencing.

Robin.

> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> 
> ---
> v1: Return error upstream as suggested by Steven
> ---
>   drivers/pci/controller/pcie-xilinx.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
> index 9bd1a35cd5d8..91d8945bfb0c 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -335,15 +335,19 @@ static const struct irq_domain_ops msi_domain_ops = {
>   /**
>    * xilinx_pcie_enable_msi - Enable MSI support
>    * @port: PCIe port information
> + * Return: 0 on success, negative error on failure
>    */
> -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
> +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
>   {
>   	phys_addr_t msg_addr;
>   
>   	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
> +	if (!port->msi_pages)
> +		return -ENOMEM;
>   	msg_addr = virt_to_phys((void *)port->msi_pages);
>   	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
>   	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
> +	return 0;
>   }
>   
>   /* INTx Functions */
> @@ -498,6 +502,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>   	struct device *dev = port->dev;
>   	struct device_node *node = dev->of_node;
>   	struct device_node *pcie_intc_node;
> +	int ret;
>   
>   	/* Setup INTx */
>   	pcie_intc_node = of_get_next_child(node, NULL);
> @@ -526,7 +531,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>   			return -ENODEV;
>   		}
>   
> -		xilinx_pcie_enable_msi(port);
> +		ret = xilinx_pcie_enable_msi(port);
> +		if (ret)
> +			return ret;
>   	}
>   
>   	return 0;
> 

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

* Re: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
@ 2019-03-26 13:01   ` Robin Murphy
  0 siblings, 0 replies; 10+ messages in thread
From: Robin Murphy @ 2019-03-26 13:01 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Lorenzo Pieralisi, linux-pci, kjlu, Michal Simek, linux-kernel,
	Bjorn Helgaas, linux-arm-kernel

On 23/03/2019 21:04, Aditya Pakki wrote:
> In case __get_free_pages fail, the fix returns error upstream
> to avoid NULL pointer dereference.

Where does msi_pages ever get dereferenced?

The logic here might actually still have a chance of working out OK with 
NULL depending on how the memory maps line up, but even if it doesn't, 
the problem is certainly not one of dereferencing.

Robin.

> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> 
> ---
> v1: Return error upstream as suggested by Steven
> ---
>   drivers/pci/controller/pcie-xilinx.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
> index 9bd1a35cd5d8..91d8945bfb0c 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -335,15 +335,19 @@ static const struct irq_domain_ops msi_domain_ops = {
>   /**
>    * xilinx_pcie_enable_msi - Enable MSI support
>    * @port: PCIe port information
> + * Return: 0 on success, negative error on failure
>    */
> -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
> +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
>   {
>   	phys_addr_t msg_addr;
>   
>   	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
> +	if (!port->msi_pages)
> +		return -ENOMEM;
>   	msg_addr = virt_to_phys((void *)port->msi_pages);
>   	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
>   	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
> +	return 0;
>   }
>   
>   /* INTx Functions */
> @@ -498,6 +502,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>   	struct device *dev = port->dev;
>   	struct device_node *node = dev->of_node;
>   	struct device_node *pcie_intc_node;
> +	int ret;
>   
>   	/* Setup INTx */
>   	pcie_intc_node = of_get_next_child(node, NULL);
> @@ -526,7 +531,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>   			return -ENODEV;
>   		}
>   
> -		xilinx_pcie_enable_msi(port);
> +		ret = xilinx_pcie_enable_msi(port);
> +		if (ret)
> +			return ret;
>   	}
>   
>   	return 0;
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
  2019-03-25 21:31   ` Kangjie Lu
@ 2019-03-25 21:51     ` Bjorn Helgaas
  -1 siblings, 0 replies; 10+ messages in thread
From: Bjorn Helgaas @ 2019-03-25 21:51 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: Lorenzo Pieralisi, linux-pci, Michal Simek, linux-kernel,
	pakki001, linux-arm-kernel

Hi Kangjie,

Thanks for the patch!

Please update the subject line like this:

  PCI: xilinx: Check for __get_free_pages() failure

You can always get a good idea of the style for subject lines by doing
something like this:

  git log --oneline --follow drivers/pci/controller/pcie-xilinx.c

On Mon, Mar 25, 2019 at 04:31:13PM -0500, Kangjie Lu wrote:
> In case __get_free_pages fail, the fix returns -ENOMEMto avoid
> NULL pointer dereference.

s/In case/If/
s/__get_free_pages/__get_free_pages()/
s/fail/fails/
s/the fix returns/return/
s/-ENOMEMto/-ENOMEM to/

> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> Reviewed-by: Steven Price <steven.price@arm.com>

I didn't see Steven's reviewed-by on the mailing list.  I did see his
*review*, but his "Reviewed-by: Steven Price <steven.price@arm.com>"
implies that he reviewed it *and* believes it to ready for merging
(see Documentation/process/submitting-patches.rst for all the
details).

So we should only add the Reviewed-by tag after Steven himself posts
it.

> ---
> v2: caller is redefined to accept the error code, as suggested by
> Steven Price <steven.price@arm.com>
> ---
>  drivers/pci/controller/pcie-xilinx.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
> index 9bd1a35cd5d8..abc214e94f7c 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -336,14 +336,19 @@ static const struct irq_domain_ops msi_domain_ops = {
>   * xilinx_pcie_enable_msi - Enable MSI support
>   * @port: PCIe port information
>   */
> -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
> +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
>  {
>  	phys_addr_t msg_addr;
>  
>  	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
> +	if (unlikely(!port->msi_pages))
> +		return -ENOMEM;

No need to use "unlikely()" here.  It *is* unlikely that
__get_free_pages() will fail, but the annotation clutters the code a
bit, so I prefer to avoid it except for performance paths.

This should probably be documented somewhere in
Documentation/process/, but regrettably, it isn't (yet).

>  	msg_addr = virt_to_phys((void *)port->msi_pages);
>  	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
>  	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
> +
> +	return 0;
>  }
>  
>  /* INTx Functions */
> @@ -498,6 +503,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>  	struct device *dev = port->dev;
>  	struct device_node *node = dev->of_node;
>  	struct device_node *pcie_intc_node;
> +	int ret;
>  
>  	/* Setup INTx */
>  	pcie_intc_node = of_get_next_child(node, NULL);
> @@ -526,7 +532,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>  			return -ENODEV;
>  		}
>  
> -		xilinx_pcie_enable_msi(port);
> +		ret = xilinx_pcie_enable_msi(port);
> +		if (ret)
> +			return ret;
>  	}
>  
>  	return 0;
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
@ 2019-03-25 21:51     ` Bjorn Helgaas
  0 siblings, 0 replies; 10+ messages in thread
From: Bjorn Helgaas @ 2019-03-25 21:51 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: Lorenzo Pieralisi, linux-pci, Michal Simek, linux-kernel,
	pakki001, linux-arm-kernel

Hi Kangjie,

Thanks for the patch!

Please update the subject line like this:

  PCI: xilinx: Check for __get_free_pages() failure

You can always get a good idea of the style for subject lines by doing
something like this:

  git log --oneline --follow drivers/pci/controller/pcie-xilinx.c

On Mon, Mar 25, 2019 at 04:31:13PM -0500, Kangjie Lu wrote:
> In case __get_free_pages fail, the fix returns -ENOMEMto avoid
> NULL pointer dereference.

s/In case/If/
s/__get_free_pages/__get_free_pages()/
s/fail/fails/
s/the fix returns/return/
s/-ENOMEMto/-ENOMEM to/

> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> Reviewed-by: Steven Price <steven.price@arm.com>

I didn't see Steven's reviewed-by on the mailing list.  I did see his
*review*, but his "Reviewed-by: Steven Price <steven.price@arm.com>"
implies that he reviewed it *and* believes it to ready for merging
(see Documentation/process/submitting-patches.rst for all the
details).

So we should only add the Reviewed-by tag after Steven himself posts
it.

> ---
> v2: caller is redefined to accept the error code, as suggested by
> Steven Price <steven.price@arm.com>
> ---
>  drivers/pci/controller/pcie-xilinx.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
> index 9bd1a35cd5d8..abc214e94f7c 100644
> --- a/drivers/pci/controller/pcie-xilinx.c
> +++ b/drivers/pci/controller/pcie-xilinx.c
> @@ -336,14 +336,19 @@ static const struct irq_domain_ops msi_domain_ops = {
>   * xilinx_pcie_enable_msi - Enable MSI support
>   * @port: PCIe port information
>   */
> -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
> +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
>  {
>  	phys_addr_t msg_addr;
>  
>  	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
> +	if (unlikely(!port->msi_pages))
> +		return -ENOMEM;

No need to use "unlikely()" here.  It *is* unlikely that
__get_free_pages() will fail, but the annotation clutters the code a
bit, so I prefer to avoid it except for performance paths.

This should probably be documented somewhere in
Documentation/process/, but regrettably, it isn't (yet).

>  	msg_addr = virt_to_phys((void *)port->msi_pages);
>  	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
>  	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
> +
> +	return 0;
>  }
>  
>  /* INTx Functions */
> @@ -498,6 +503,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>  	struct device *dev = port->dev;
>  	struct device_node *node = dev->of_node;
>  	struct device_node *pcie_intc_node;
> +	int ret;
>  
>  	/* Setup INTx */
>  	pcie_intc_node = of_get_next_child(node, NULL);
> @@ -526,7 +532,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
>  			return -ENODEV;
>  		}
>  
> -		xilinx_pcie_enable_msi(port);
> +		ret = xilinx_pcie_enable_msi(port);
> +		if (ret)
> +			return ret;
>  	}
>  
>  	return 0;
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
  2019-03-22 16:26 [PATCH] " Steven Price
@ 2019-03-25 21:31   ` Kangjie Lu
  0 siblings, 0 replies; 10+ messages in thread
From: Kangjie Lu @ 2019-03-25 21:31 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Lorenzo Pieralisi, Bjorn Helgaas, Michal Simek,
	linux-pci, linux-arm-kernel, linux-kernel

In case __get_free_pages fail, the fix returns -ENOMEMto avoid
NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Reviewed-by: Steven Price <steven.price@arm.com>
---
v2: caller is redefined to accept the error code, as suggested by
Steven Price <steven.price@arm.com>
---
 drivers/pci/controller/pcie-xilinx.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
index 9bd1a35cd5d8..abc214e94f7c 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -336,14 +336,19 @@ static const struct irq_domain_ops msi_domain_ops = {
  * xilinx_pcie_enable_msi - Enable MSI support
  * @port: PCIe port information
  */
-static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
+static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
 {
 	phys_addr_t msg_addr;
 
 	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
+	if (unlikely(!port->msi_pages))
+		return -ENOMEM;
+
 	msg_addr = virt_to_phys((void *)port->msi_pages);
 	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
 	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
+
+	return 0;
 }
 
 /* INTx Functions */
@@ -498,6 +503,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 	struct device *dev = port->dev;
 	struct device_node *node = dev->of_node;
 	struct device_node *pcie_intc_node;
+	int ret;
 
 	/* Setup INTx */
 	pcie_intc_node = of_get_next_child(node, NULL);
@@ -526,7 +532,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 			return -ENODEV;
 		}
 
-		xilinx_pcie_enable_msi(port);
+		ret = xilinx_pcie_enable_msi(port);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
-- 
2.17.1


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

* [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages
@ 2019-03-25 21:31   ` Kangjie Lu
  0 siblings, 0 replies; 10+ messages in thread
From: Kangjie Lu @ 2019-03-25 21:31 UTC (permalink / raw)
  To: kjlu
  Cc: Lorenzo Pieralisi, linux-pci, Michal Simek, linux-kernel,
	pakki001, Bjorn Helgaas, linux-arm-kernel

In case __get_free_pages fail, the fix returns -ENOMEMto avoid
NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Reviewed-by: Steven Price <steven.price@arm.com>
---
v2: caller is redefined to accept the error code, as suggested by
Steven Price <steven.price@arm.com>
---
 drivers/pci/controller/pcie-xilinx.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c
index 9bd1a35cd5d8..abc214e94f7c 100644
--- a/drivers/pci/controller/pcie-xilinx.c
+++ b/drivers/pci/controller/pcie-xilinx.c
@@ -336,14 +336,19 @@ static const struct irq_domain_ops msi_domain_ops = {
  * xilinx_pcie_enable_msi - Enable MSI support
  * @port: PCIe port information
  */
-static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
+static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
 {
 	phys_addr_t msg_addr;
 
 	port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
+	if (unlikely(!port->msi_pages))
+		return -ENOMEM;
+
 	msg_addr = virt_to_phys((void *)port->msi_pages);
 	pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
 	pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
+
+	return 0;
 }
 
 /* INTx Functions */
@@ -498,6 +503,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 	struct device *dev = port->dev;
 	struct device_node *node = dev->of_node;
 	struct device_node *pcie_intc_node;
+	int ret;
 
 	/* Setup INTx */
 	pcie_intc_node = of_get_next_child(node, NULL);
@@ -526,7 +532,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
 			return -ENODEV;
 		}
 
-		xilinx_pcie_enable_msi(port);
+		ret = xilinx_pcie_enable_msi(port);
+		if (ret)
+			return ret;
 	}
 
 	return 0;
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2019-03-26 13:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-23 21:04 [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages Aditya Pakki
2019-03-23 21:04 ` Aditya Pakki
2019-03-25 12:08 ` Steven Price
2019-03-25 12:08   ` Steven Price
2019-03-26 13:01 ` Robin Murphy
2019-03-26 13:01   ` Robin Murphy
  -- strict thread matches above, loose matches on Subject: below --
2019-03-22 16:26 [PATCH] " Steven Price
2019-03-25 21:31 ` [PATCH v2] " Kangjie Lu
2019-03-25 21:31   ` Kangjie Lu
2019-03-25 21:51   ` Bjorn Helgaas
2019-03-25 21:51     ` Bjorn Helgaas

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.