diff mbox series

[9/9] PCI: dwc: Add pcie port pointer validation

Message ID 0164f622c6d16755d006ae090fba65cff24cfeb2.1547631485.git.gustavo.pimentel@synopsys.com
State Changes Requested
Delegated to: Lorenzo Pieralisi
Headers show
Series Improve Synopsys DesignWare Root Complex driver code | expand

Commit Message

Gustavo Pimentel Jan. 16, 2019, 10:14 a.m. UTC
Add pcie port pointer validation to avoid a potencial crash accessing a
null pointer reported by coverity scan.

Warning generated by coverity: "Dereferencing a pointer that might be
null "data" when calling "irq_data_get_irq_chip_data".

Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: Jingoo Han <jingoohan1@gmail.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Lorenzo Pieralisi Jan. 31, 2019, 4:51 p.m. UTC | #1
[+Marc, for his information]

On Wed, Jan 16, 2019 at 11:14:22AM +0100, Gustavo Pimentel wrote:
> Add pcie port pointer validation to avoid a potencial crash accessing a
> null pointer reported by coverity scan.

s/potencial/potential
s/null/NULL

> Warning generated by coverity: "Dereferencing a pointer that might be
> null "data" when calling "irq_data_get_irq_chip_data".

s/null/NULL

> Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Joao Pinto <jpinto@synopsys.com>
> Cc: Jingoo Han <jingoohan1@gmail.com>
> ---
>  drivers/pci/controller/dwc/pcie-designware-host.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index 45ff5e4..419a56b 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -256,9 +256,14 @@ static void dw_pcie_irq_domain_free(struct irq_domain *domain,
>  				    unsigned int virq, unsigned int nr_irqs)
>  {
>  	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
> -	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
> +	struct pcie_port *pp;
>  	unsigned long flags;
>  
> +	if (!d)
> +		return;
> +
> +	pp = irq_data_get_irq_chip_data(d);

Well, we do not validate pp either and I wonder whether coverity trips
over this code path but that's just a false positive.

If we have to actually patch it there are other code paths in the kernel
to be updated too.

Lorenzo

> +
>  	raw_spin_lock_irqsave(&pp->lock, flags);
>  
>  	bitmap_release_region(pp->msi_irq_in_use, d->hwirq,
> -- 
> 2.7.4
>
Gustavo Pimentel Jan. 31, 2019, 5:37 p.m. UTC | #2
On 31/01/2019 16:51, Lorenzo Pieralisi wrote:
> [+Marc, for his information]
> 
> On Wed, Jan 16, 2019 at 11:14:22AM +0100, Gustavo Pimentel wrote:
>> Add pcie port pointer validation to avoid a potencial crash accessing a
>> null pointer reported by coverity scan.
> 
> s/potencial/potential
> s/null/NULL
> 
>> Warning generated by coverity: "Dereferencing a pointer that might be
>> null "data" when calling "irq_data_get_irq_chip_data".
> 
> s/null/NULL
> 
>> Signed-off-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
>> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>> Cc: Joao Pinto <jpinto@synopsys.com>
>> Cc: Jingoo Han <jingoohan1@gmail.com>
>> ---
>>  drivers/pci/controller/dwc/pcie-designware-host.c | 7 ++++++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
>> index 45ff5e4..419a56b 100644
>> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
>> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
>> @@ -256,9 +256,14 @@ static void dw_pcie_irq_domain_free(struct irq_domain *domain,
>>  				    unsigned int virq, unsigned int nr_irqs)
>>  {
>>  	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
>> -	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
>> +	struct pcie_port *pp;
>>  	unsigned long flags;
>>  
>> +	if (!d)
>> +		return;
>> +
>> +	pp = irq_data_get_irq_chip_data(d);
> 
> Well, we do not validate pp either and I wonder whether coverity trips
> over this code path but that's just a false positive.
> 
> If we have to actually patch it there are other code paths in the kernel
> to be updated too.

Ok, I can drop this patch.

Gustavo

> 
> Lorenzo
> 
>> +
>>  	raw_spin_lock_irqsave(&pp->lock, flags);
>>  
>>  	bitmap_release_region(pp->msi_irq_in_use, d->hwirq,
>> -- 
>> 2.7.4
>>
diff mbox series

Patch

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 45ff5e4..419a56b 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -256,9 +256,14 @@  static void dw_pcie_irq_domain_free(struct irq_domain *domain,
 				    unsigned int virq, unsigned int nr_irqs)
 {
 	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
-	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
+	struct pcie_port *pp;
 	unsigned long flags;
 
+	if (!d)
+		return;
+
+	pp = irq_data_get_irq_chip_data(d);
+
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	bitmap_release_region(pp->msi_irq_in_use, d->hwirq,