Skip to contentSkip to conversation

mfd: intel-lpss: refactor PCI probe and common IRQ check

PATCH Applied Andy Shevchenko 2 participants 6 messages Nov 6, 2023 – Nov 23, 2023

Subsystems (2)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

v3 cover mfd: intel-lpss: refactor PCI probe and common IRQ check

The PCI code can be refactored to use respective PCI APIs instead of direct dereference of struct pci_dev members.

With that, we may unshadow the error code that is promoted in the irq field of info structure. PCI core shouldn't propagate 0 as a value there, and in case it happens it reveals a bug somewhere else.

Changelog:

v2 -> v3:
1. Refactored PCI glue driver a bit (a new patch)
2. Updated commit message in the original patch

v1 -> v2:
1. Update commit message
2. Fix IRQ check in intel_lpcc_probe()

Andy Shevchenko (1):
mfd: intel-lpss: Use PCI APIs instead of derefereincing

Chen Ni (1):
mfd: intel-lpss: Amend IRQ check

 drivers/mfd/intel-lpss-pci.c | 8 ++++++--
 drivers/mfd/intel-lpss.c     | 5 ++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
Signature · 1 line
2.40.0.1.gaa8946217a0b
author reviewer
#1 lore raw

PATCH v3 1/2 mfd: intel-lpss: Use PCI APIs instead of derefereincing

We have a few PCI APIs that may be used instead of direct dereferencibg, Using them will also provide better error codes.

---
 drivers/mfd/intel-lpss-pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/mfd/intel-lpss-pci.c +6 -2
index ae5759200622..cf56cd3a40ee 100644
@@ -37,13 +37,17 @@ static int intel_lpss_pci_probe(struct pci_dev *pdev,
 	if (ret)
 		return ret;
 
+	ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_LEGACY);
+	if (ret)
+		return ret;
+
 	info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
 			    GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
 
-	info->mem = &pdev->resource[0];
-	info->irq = pdev->irq;
+	info->mem = pci_resource_n(pdev, 0);
+	info->irq = pci_irq_vector(pdev, 0);
 
 	if (pci_match_id(ignore_resource_conflicts_ids, pdev))
 		info->ignore_resource_conflicts = true;
Signature · 1 line
2.40.0.1.gaa8946217a0b
maintainer
#2 lore raw

Re: [PATCH v3 1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing

Quoted 7 lines · Andy Shevchenko

We have a few PCI APIs that may be used instead of direct dereferencibg, Using them will also provide better error codes.

---
 drivers/mfd/intel-lpss-pci.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Please use spell-check on your commit messages.

Let's not get complacent.

Quoted 27 lines
drivers/mfd/intel-lpss-pci.c +6 -2
index ae5759200622..cf56cd3a40ee 100644
@@ -37,13 +37,17 @@ static int intel_lpss_pci_probe(struct pci_dev *pdev,
 	if (ret)
 		return ret;
 
+	ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_LEGACY);
+	if (ret)
+		return ret;
+
 	info = devm_kmemdup(&pdev->dev, (void *)id->driver_data, sizeof(*info),
 			    GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
 
-	info->mem = &pdev->resource[0];
-	info->irq = pdev->irq;
+	info->mem = pci_resource_n(pdev, 0);
+	info->irq = pci_irq_vector(pdev, 0);
 
 	if (pci_match_id(ignore_resource_conflicts_ids, pdev))
 		info->ignore_resource_conflicts = true;
Signature · 1 line
2.40.0.1.gaa8946217a0b
Signature · 1 line
Lee Jones [李琼斯]
author reviewer
#3 lore raw

PATCH v3 2/2 mfd: intel-lpss: Amend IRQ check

In reply to Andy Shevchenko

From: Chen Ni <[email protected]>

platform_get_irq() returns a negative error code to indicating an error. All the same does pci_alloc_irq_vectors() and pci_irq_vector(). So in intel_lpss_probe() the erroneous IRQ should be better returned as is.

The pci_alloc_irq_vectors() call and platform_get_irq() guarantee that IRQ won't be 0, hence drop that check.

[andy: updated commit message]
---
 drivers/mfd/intel-lpss.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mfd/intel-lpss.c +4 -1
index 9591b354072a..4c9d0222751a 100644
@@ -378,9 +378,12 @@ int intel_lpss_probe(struct device *dev,
 	struct intel_lpss *lpss;
 	int ret;
 
-	if (!info || !info->mem || info->irq <= 0)
+	if (!info || !info->mem)
 		return -EINVAL;
 
+	if (info->irq < 0)
+		return info->irq;
+
 	lpss = devm_kzalloc(dev, sizeof(*lpss), GFP_KERNEL);
 	if (!lpss)
 		return -ENOMEM;
Signature · 1 line
2.40.0.1.gaa8946217a0b
maintainer
#4 lore raw

Re: [PATCH v3 2/2] mfd: intel-lpss: Amend IRQ check

Quoted 7 lines · Andy Shevchenko

From: Chen Ni <[email protected]>

platform_get_irq() returns a negative error code to indicating an error. All the same does pci_alloc_irq_vectors() and pci_irq_vector(). So in intel_lpss_probe() the erroneous IRQ should be better returned as is.

Quoted 5 lines

The pci_alloc_irq_vectors() call and platform_get_irq() guarantee that IRQ won't be 0, hence drop that check.

[andy: updated commit message]

I reworded it further.

Quoted 26 lines
---
 drivers/mfd/intel-lpss.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mfd/intel-lpss.c +4 -1
index 9591b354072a..4c9d0222751a 100644
@@ -378,9 +378,12 @@ int intel_lpss_probe(struct device *dev,
 	struct intel_lpss *lpss;
 	int ret;
 
-	if (!info || !info->mem || info->irq <= 0)
+	if (!info || !info->mem)
 		return -EINVAL;
 
+	if (info->irq < 0)
+		return info->irq;
+
 	lpss = devm_kzalloc(dev, sizeof(*lpss), GFP_KERNEL);
 	if (!lpss)
 		return -ENOMEM;
Signature · 1 line
2.40.0.1.gaa8946217a0b
Signature · 1 line
Lee Jones [李琼斯]
maintainer Applied
#5 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

The PCI code can be refactored to use respective PCI APIs instead of direct dereference of struct pci_dev members.

With that, we may unshadow the error code that is promoted in the irq field of info structure. PCI core shouldn't propagate 0 as a value there, and in case it happens it reveals a bug somewhere else.

[...]

Applied, thanks!

[1/2] mfd: intel-lpss: Use PCI APIs instead of derefereincing

      commit: e6951fb7878751aba4c147f1f206a2cbc05d1b9f
[2/2] mfd: intel-lpss: Amend IRQ check
      commit: ec791121b8ace33d2251b6c7a4d11a231ee51c05

--
Lee Jones [李琼斯]