Skip to contentSkip to conversation

Improve Synopsys DesignWare Root Complex driver code

PATCH Superseded Gustavo Pimentel 2 participants 15 messages Jan 16, 2019 – Jan 31, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Improve Synopsys DesignWare Root Complex driver code

This patch series aims to improve Synopsys DesignWare Root Complex driver code by:
- removing unnecessary header files
- enforcing variable naming coherency among similar functions
- simplifing code readability of mask/unmask function operations
- replacing bit rotation operation (1 << bit) by BIT(bit)
- adding a pointer null validation on dw_pcie_irq_domain_free()

No functional changes are intended.

All patches are independent so they can be easily analyzed and accepted or discarded.

This patches organization also allows to easily merge (squash) some patches, if desired.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

Gustavo Pimentel (9):
PCI: dwc: Remove unnecessary header include (of_gpio.h)
PCI: dwc: Remove unnecessary header include (signal.h)
PCI: dwc: Replace variable name from data to d on
dw_pci_bottom_mask/unmask()
PCI: dwc: Replace variable name from data to d on

    dw_pci_setup_msi_msg()

PCI: dwc: Replace variable name from data to d on
dw_pci_msi_set_affinity()
PCI: dwc: Replace variable name from data to d on
dw_pcie_irq_domain_free()
PCI: dwc: Improve code readability and simplifies mask/unmask
operations
PCI: dwc: Replace bit rotation operation (1 << bit) by BIT(bit)
PCI: dwc: Add pcie port pointer validation

 drivers/pci/controller/dwc/pcie-designware-host.c | 57 ++++++++++++-----------
 drivers/pci/controller/dwc/pcie-designware-plat.c |  2 -
 drivers/pci/controller/dwc/pcie-designware.h      |  2 +-
 3 files changed, 32 insertions(+), 29 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/9 PCI: dwc: Remove unnecessary header include (of_gpio.h)

Remove unnecessary header include (of_gpio.h) since it doesn't provide any needed symbols.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-plat.c | 1 -
 1 file changed, 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-plat.c +0 -1
index 99ad471..e889512 100644
@@ -13,7 +13,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/resource.h>
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/9 PCI: dwc: Remove unnecessary header include (signal.h)

In reply to Gustavo Pimentel

Remove unnecessary header include (signal.h) since it doesn't provide any needed symbols.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-plat.c | 1 -
 1 file changed, 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-plat.c +0 -1
index e889512..4272c4c 100644
@@ -16,7 +16,6 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/resource.h>
-#include <linux/signal.h>
 #include <linux/types.h>
 #include <linux/regmap.h>
 
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/9 PCI: dwc: Replace variable name from data to d on dw_pci_bottom_mask/unmask()

In reply to Gustavo Pimentel

Replace variable from data to d to maintain coherency between similar functions, such as dw_msi_mask_irq() and dw_msi_unmask_irq().

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +10 -10
index 721d60a..36e284c 100644
@@ -149,20 +149,20 @@ static int dw_pci_msi_set_affinity(struct irq_data *irq_data,
 	return -EINVAL;
 }
 
-static void dw_pci_bottom_mask(struct irq_data *data)
+static void dw_pci_bottom_mask(struct irq_data *d)
 {
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	unsigned int res, bit, ctrl;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	if (pp->ops->msi_clear_irq) {
-		pp->ops->msi_clear_irq(pp, data->hwirq);
+		pp->ops->msi_clear_irq(pp, d->hwirq);
 	} else {
-		ctrl = data->hwirq / MAX_MSI_IRQS_PER_CTRL;
+		ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
-		bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL;
+		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
 		pp->irq_status[ctrl] &= ~(1 << bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
@@ -172,20 +172,20 @@ static void dw_pci_bottom_mask(struct irq_data *data)
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
 }
 
-static void dw_pci_bottom_unmask(struct irq_data *data)
+static void dw_pci_bottom_unmask(struct irq_data *d)
 {
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	unsigned int res, bit, ctrl;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	if (pp->ops->msi_set_irq) {
-		pp->ops->msi_set_irq(pp, data->hwirq);
+		pp->ops->msi_set_irq(pp, d->hwirq);
 	} else {
-		ctrl = data->hwirq / MAX_MSI_IRQS_PER_CTRL;
+		ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
-		bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL;
+		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
 		pp->irq_status[ctrl] |= 1 << bit;
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH 3/9] PCI: dwc: Replace variable name from data to d on dw_pci_bottom_mask/unmask()

Quoted 1 line · Gustavo Pimentel

Replace variable from data to d to maintain coherency between similar

s/Replace/Rename
s/coherency/consistency

s/similar/driver

These comments are valid for other patches in this series too.

Quoted 71 lines

functions, such as dw_msi_mask_irq() and dw_msi_unmask_irq().

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +10 -10
index 721d60a..36e284c 100644
@@ -149,20 +149,20 @@ static int dw_pci_msi_set_affinity(struct irq_data *irq_data,
 	return -EINVAL;
 }
 
-static void dw_pci_bottom_mask(struct irq_data *data)
+static void dw_pci_bottom_mask(struct irq_data *d)
 {
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	unsigned int res, bit, ctrl;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	if (pp->ops->msi_clear_irq) {
-		pp->ops->msi_clear_irq(pp, data->hwirq);
+		pp->ops->msi_clear_irq(pp, d->hwirq);
 	} else {
-		ctrl = data->hwirq / MAX_MSI_IRQS_PER_CTRL;
+		ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
-		bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL;
+		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
 		pp->irq_status[ctrl] &= ~(1 << bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
@@ -172,20 +172,20 @@ static void dw_pci_bottom_mask(struct irq_data *data)
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
 }
 
-static void dw_pci_bottom_unmask(struct irq_data *data)
+static void dw_pci_bottom_unmask(struct irq_data *d)
 {
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	unsigned int res, bit, ctrl;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	if (pp->ops->msi_set_irq) {
-		pp->ops->msi_set_irq(pp, data->hwirq);
+		pp->ops->msi_set_irq(pp, d->hwirq);
 	} else {
-		ctrl = data->hwirq / MAX_MSI_IRQS_PER_CTRL;
+		ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
-		bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL;
+		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
 		pp->irq_status[ctrl] |= 1 << bit;
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
Signature · 1 line
2.7.4
#5 lore raw

PATCH 4/9 PCI: dwc: Replace variable name from data to d on dw_pci_setup_msi_msg()

In reply to Gustavo Pimentel

Replace variable from data to d to maintain coherency between similar functions, such as dw_pci_setup_msi_msg().

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +5 -5
index 36e284c..0c6e19a 100644
@@ -120,9 +120,9 @@ static void dw_chained_msi_isr(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
-static void dw_pci_setup_msi_msg(struct irq_data *data, struct msi_msg *msg)
+static void dw_pci_setup_msi_msg(struct irq_data *d, struct msi_msg *msg)
 {
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 	u64 msi_target;
 
@@ -135,12 +135,12 @@ static void dw_pci_setup_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	msg->address_hi = upper_32_bits(msi_target);
 
 	if (pp->ops->get_msi_data)
-		msg->data = pp->ops->get_msi_data(pp, data->hwirq);
+		msg->data = pp->ops->get_msi_data(pp, d->hwirq);
 	else
-		msg->data = data->hwirq;
+		msg->data = d->hwirq;
 
 	dev_dbg(pci->dev, "msi#%d address_hi %#x address_lo %#x\n",
-		(int)data->hwirq, msg->address_hi, msg->address_lo);
+		(int)d->hwirq, msg->address_hi, msg->address_lo);
 }
 
 static int dw_pci_msi_set_affinity(struct irq_data *irq_data,
Signature · 1 line
2.7.4
#6 lore raw

PATCH 5/9 PCI: dwc: Replace variable name from data to d on dw_pci_msi_set_affinity()

In reply to Gustavo Pimentel

Replace variable from data to d to maintain coherency between similar functions.

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +1 -1
index 0c6e19a..a59fc17e 100644
@@ -143,7 +143,7 @@ static void dw_pci_setup_msi_msg(struct irq_data *d, struct msi_msg *msg)
 		(int)d->hwirq, msg->address_hi, msg->address_lo);
 }
 
-static int dw_pci_msi_set_affinity(struct irq_data *irq_data,
+static int dw_pci_msi_set_affinity(struct irq_data *d,
 				   const struct cpumask *mask, bool force)
 {
 	return -EINVAL;
Signature · 1 line
2.7.4
#7 lore raw

PATCH 6/9 PCI: dwc: Replace variable name from data to d on dw_pcie_irq_domain_free()

In reply to Gustavo Pimentel

Replace variable from data to d to maintain coherency between similar functions.

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +3 -3
index a59fc17e..768e16a 100644
@@ -255,13 +255,13 @@ static int dw_pcie_irq_domain_alloc(struct irq_domain *domain,
 static void dw_pcie_irq_domain_free(struct irq_domain *domain,
 				    unsigned int virq, unsigned int nr_irqs)
 {
-	struct irq_data *data = irq_domain_get_irq_data(domain, virq);
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
-	bitmap_release_region(pp->msi_irq_in_use, data->hwirq,
+	bitmap_release_region(pp->msi_irq_in_use, d->hwirq,
 			      order_base_2(nr_irqs));
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
Signature · 1 line
2.7.4
#8 lore raw

PATCH 7/9 PCI: dwc: Improve code readability and simplifies mask/unmask operations

In reply to Gustavo Pimentel

Improve code readability and simplifies mask/unmask operations by inverting the applied logic (no functional change is intended).

Replace variable name from irq_status to irq_mask, since its goal is to keep track of which interuptions are mask or not.

Replace bit rotation operation (1 << bit) by BIT(bit), which simplifies code reading.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++------
 drivers/pci/controller/dwc/pcie-designware.h      |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +6 -6
index 768e16a..d53e6f7 100644
@@ -164,9 +164,9 @@ static void dw_pci_bottom_mask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_status[ctrl] &= ~(1 << bit);
+		pp->irq_mask[ctrl] |= BIT(bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
-				    ~pp->irq_status[ctrl]);
+				    pp->irq_mask[ctrl]);
 	}
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -187,9 +187,9 @@ static void dw_pci_bottom_unmask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_status[ctrl] |= 1 << bit;
+		pp->irq_mask[ctrl] &= ~BIT(bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
-				    ~pp->irq_status[ctrl]);
+				    pp->irq_mask[ctrl]);
 	}
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -665,13 +665,13 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
 
 	/* Initialize IRQ Status array */
 	for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
+		pp->irq_mask[ctrl] = ~0;
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK +
 					(ctrl * MSI_REG_CTRL_BLOCK_SIZE),
-				    4, ~0);
+				    4, pp->irq_mask[ctrl]);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE +
 					(ctrl * MSI_REG_CTRL_BLOCK_SIZE),
 				    4, ~0);
-		pp->irq_status[ctrl] = 0;
 	}
 
 	/* Setup RC BARs */
drivers/pci/controller/dwc/pcie-designware.h +1 -1
index 9943d8c..2790002 100644
@@ -177,7 +177,7 @@ struct pcie_port {
 	struct irq_domain	*msi_domain;
 	dma_addr_t		msi_data;
 	u32			num_vectors;
-	u32			irq_status[MAX_MSI_CTRLS];
+	u32			irq_mask[MAX_MSI_CTRLS];
 	raw_spinlock_t		lock;
 	DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
 };
Signature · 1 line
2.7.4
#9 lore raw

Re: [PATCH 7/9] PCI: dwc: Improve code readability and simplifies mask/unmask operations

Quoted 8 lines · Gustavo Pimentel

Improve code readability and simplifies mask/unmask operations by inverting the applied logic (no functional change is intended).

Replace variable name from irq_status to irq_mask, since its goal is to keep track of which interuptions are mask or not.

Replace bit rotation operation (1 << bit) by BIT(bit), which simplifies code reading.

Two changes, two patches, I know it is tempting to squash trivial changes in one patch but logically that's not correct.

Lorenzo

Quoted 69 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++------
 drivers/pci/controller/dwc/pcie-designware.h      |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +6 -6
index 768e16a..d53e6f7 100644
@@ -164,9 +164,9 @@ static void dw_pci_bottom_mask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_status[ctrl] &= ~(1 << bit);
+		pp->irq_mask[ctrl] |= BIT(bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
-				    ~pp->irq_status[ctrl]);
+				    pp->irq_mask[ctrl]);
 	}
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -187,9 +187,9 @@ static void dw_pci_bottom_unmask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_status[ctrl] |= 1 << bit;
+		pp->irq_mask[ctrl] &= ~BIT(bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
-				    ~pp->irq_status[ctrl]);
+				    pp->irq_mask[ctrl]);
 	}
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -665,13 +665,13 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
 
 	/* Initialize IRQ Status array */
 	for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
+		pp->irq_mask[ctrl] = ~0;
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK +
 					(ctrl * MSI_REG_CTRL_BLOCK_SIZE),
-				    4, ~0);
+				    4, pp->irq_mask[ctrl]);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE +
 					(ctrl * MSI_REG_CTRL_BLOCK_SIZE),
 				    4, ~0);
-		pp->irq_status[ctrl] = 0;
 	}
 
 	/* Setup RC BARs */
drivers/pci/controller/dwc/pcie-designware.h +1 -1
index 9943d8c..2790002 100644
@@ -177,7 +177,7 @@ struct pcie_port {
 	struct irq_domain	*msi_domain;
 	dma_addr_t		msi_data;
 	u32			num_vectors;
-	u32			irq_status[MAX_MSI_CTRLS];
+	u32			irq_mask[MAX_MSI_CTRLS];
 	raw_spinlock_t		lock;
 	DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
 };
Signature · 1 line
2.7.4
#10 lore raw

Re: [PATCH 7/9] PCI: dwc: Improve code readability and simplifies mask/unmask operations

Quoted 4 lines · Lorenzo Pieralisi
Quoted 3 lines · Gustavo Pimentel

Improve code readability and simplifies mask/unmask operations by inverting the applied logic (no functional change is intended).

Quoted 8 lines
Quoted 5 lines

Replace variable name from irq_status to irq_mask, since its goal is to keep track of which interuptions are mask or not.

Replace bit rotation operation (1 << bit) by BIT(bit), which simplifies code reading.

Two changes, two patches, I know it is tempting to squash trivial changes in one patch but logically that's not correct.

Ok, I'll move 2 replacement bit operation to the next patch since its goal is only that.
Thanks

Gustavo

Quoted 72 lines

Lorenzo

Quoted 69 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++------
 drivers/pci/controller/dwc/pcie-designware.h      |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +6 -6
index 768e16a..d53e6f7 100644
@@ -164,9 +164,9 @@ static void dw_pci_bottom_mask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_status[ctrl] &= ~(1 << bit);
+		pp->irq_mask[ctrl] |= BIT(bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
-				    ~pp->irq_status[ctrl]);
+				    pp->irq_mask[ctrl]);
 	}
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -187,9 +187,9 @@ static void dw_pci_bottom_unmask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_status[ctrl] |= 1 << bit;
+		pp->irq_mask[ctrl] &= ~BIT(bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
-				    ~pp->irq_status[ctrl]);
+				    pp->irq_mask[ctrl]);
 	}
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -665,13 +665,13 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
 
 	/* Initialize IRQ Status array */
 	for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
+		pp->irq_mask[ctrl] = ~0;
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK +
 					(ctrl * MSI_REG_CTRL_BLOCK_SIZE),
-				    4, ~0);
+				    4, pp->irq_mask[ctrl]);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE +
 					(ctrl * MSI_REG_CTRL_BLOCK_SIZE),
 				    4, ~0);
-		pp->irq_status[ctrl] = 0;
 	}
 
 	/* Setup RC BARs */
drivers/pci/controller/dwc/pcie-designware.h +1 -1
index 9943d8c..2790002 100644
@@ -177,7 +177,7 @@ struct pcie_port {
 	struct irq_domain	*msi_domain;
 	dma_addr_t		msi_data;
 	u32			num_vectors;
-	u32			irq_status[MAX_MSI_CTRLS];
+	u32			irq_mask[MAX_MSI_CTRLS];
 	raw_spinlock_t		lock;
 	DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
 };
Signature · 1 line
2.7.4
#11 lore raw

PATCH 8/9 PCI: dwc: Replace bit rotation operation (1 << bit) by BIT(bit)

In reply to Gustavo Pimentel

Replace bit rotation operation (1 << bit) by BIT(bit), which simplifies code reading.

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +1 -1
index d53e6f7..45ff5e4 100644
@@ -207,7 +207,7 @@ static void dw_pci_bottom_ack(struct irq_data *d)
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
-	dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_STATUS + res, 4, 1 << bit);
+	dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_STATUS + res, 4, BIT(bit));
 
 	if (pp->ops->msi_irq_ack)
 		pp->ops->msi_irq_ack(d->hwirq, pp);
Signature · 1 line
2.7.4
#12 lore raw

PATCH 9/9 PCI: dwc: Add pcie port pointer validation

In reply to Gustavo Pimentel

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

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +6 -1
index 45ff5e4..419a56b 100644
@@ -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,
Signature · 1 line
2.7.4
#13 lore raw

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

[+Marc, for his information]

Quoted 2 lines · Gustavo Pimentel

Add pcie port pointer validation to avoid a potencial crash accessing a null pointer reported by coverity scan.

s/potencial/potential
s/null/NULL

Quoted 2 lines

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

s/null/NULL

Quoted 14 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +0 -0
index 45ff5e4..419a56b 100644
@@ -256,9 +256,14 @@ static void dw_pcie_irq_domain_free(struct irq_domain *domain,
 				    unsigned int virq, unsigned int nr_irqs)

drivers/pci/controller/dwc/pcie-designware-host.c static void dw_pcie_irq_domain_free(struct irq_domain *domain, · line 265

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-host.c +5 -1
 {
 	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

Quoted 7 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1 -0
+
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	bitmap_release_region(pp->msi_irq_in_use, d->hwirq,
Signature · 1 line
2.7.4
#14 lore raw

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

Quoted 42 lines · Lorenzo Pieralisi

[+Marc, for his information]

Quoted 2 lines · Gustavo Pimentel

Add pcie port pointer validation to avoid a potencial crash accessing a null pointer reported by coverity scan.

s/potencial/potential
s/null/NULL

Quoted 2 lines

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

s/null/NULL

Quoted 14 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +0 -0
index 45ff5e4..419a56b 100644
@@ -256,9 +256,14 @@ static void dw_pcie_irq_domain_free(struct irq_domain *domain,
 				    unsigned int virq, unsigned int nr_irqs)

drivers/pci/controller/dwc/pcie-designware-host.c static void dw_pcie_irq_domain_free(struct irq_domain *domain, · line 265

Quoted 10 lines
drivers/pci/controller/dwc/pcie-designware-host.c +5 -1
 {
 	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.

Quoted 2 lines

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

Quoted 10 lines

Lorenzo

Quoted 7 lines
drivers/pci/controller/dwc/pcie-designware-host.c +1 -0
+
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	bitmap_release_region(pp->msi_irq_in_use, d->hwirq,
Signature · 1 line
2.7.4