Skip to contentSkip to conversation

media: ipu3-cio2: disable MSI on probe failure and remove

PATCH In review Myeonghun Pak 2 participants 2 messages Jul 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: ipu3-cio2: disable MSI on probe failure and remove

cio2_pci_probe() enables MSI with pci_enable_msi() but pci_disable_msi() is never called, so MSI is left enabled on the probe error paths and on normal removal in cio2_pci_remove().

The IRQ is requested with devm_request_irq() and freed by devres only after remove() (or a failed probe) returns, so a plain pci_disable_msi() in remove() would tear the MSI vector down before free_irq() runs. Register it with devm_add_action_or_reset() right after pci_enable_msi() instead: devres releases in reverse order, so the IRQ is freed before MSI is disabled, on every error path and on remove.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes c2a6a07afe4a ("media: intel-ipu3: cio2: add new MIPI-CSI2 driver")
---
 drivers/media/pci/intel/ipu3/ipu3-cio2.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/media/pci/intel/ipu3/ipu3-cio2.c +11 -0
index 986b9afd7c..3f738ca681 100644
@@ -1654,6 +1654,13 @@ static void cio2_queues_exit(struct cio2_device *cio2)
 
 /**************** PCI interface ****************/
 
+static void cio2_disable_msi(void *data)
+{
+	struct pci_dev *pci_dev = data;
+
+	pci_disable_msi(pci_dev);
+}
+
 static int cio2_pci_probe(struct pci_dev *pci_dev,
 			  const struct pci_device_id *id)
 {
@@ -1707,6 +1714,10 @@ static int cio2_pci_probe(struct pci_dev *pci_dev,
 		return r;
 	}
 
+	r = devm_add_action_or_reset(dev, cio2_disable_msi, pci_dev);
+	if (r)
+		return r;
+
 	r = cio2_fbpt_init_dummy(cio2);
 	if (r)
 		return r;
Signature · 1 line
2.47.1
maintainer
#1 lore raw

Hi Myeonghun,

Thank you for the patch.

Quoted 41 lines · Myeonghun Pak

cio2_pci_probe() enables MSI with pci_enable_msi() but pci_disable_msi() is never called, so MSI is left enabled on the probe error paths and on normal removal in cio2_pci_remove().

The IRQ is requested with devm_request_irq() and freed by devres only after remove() (or a failed probe) returns, so a plain pci_disable_msi() in remove() would tear the MSI vector down before free_irq() runs. Register it with devm_add_action_or_reset() right after pci_enable_msi() instead: devres releases in reverse order, so the IRQ is freed before MSI is disabled, on every error path and on remove.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes c2a6a07afe4a ("media: intel-ipu3: cio2: add new MIPI-CSI2 driver")
---
 drivers/media/pci/intel/ipu3/ipu3-cio2.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/media/pci/intel/ipu3/ipu3-cio2.c +7 -0
index 986b9afd7c..3f738ca681 100644
@@ -1654,6 +1654,13 @@ static void cio2_queues_exit(struct cio2_device *cio2)
 
 /**************** PCI interface ****************/
 
+static void cio2_disable_msi(void *data)
+{
+	struct pci_dev *pci_dev = data;
+
+	pci_disable_msi(pci_dev);
+}
+
 static int cio2_pci_probe(struct pci_dev *pci_dev,
 			  const struct pci_device_id *id)
 {

drivers/media/pci/intel/ipu3/ipu3-cio2.c static int cio2_pci_probe(struct pci_dev *pci_dev, · line 1717

Quoted 4 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c +1 -0
@@ -1707,6 +1714,10 @@ static int cio2_pci_probe(struct pci_dev *pci_dev,
 		return r;
 	}
 
+	r = devm_add_action_or_reset(dev, cio2_disable_msi, pci_dev);

I think I'd do this without using devm_*().

Alternatively, pcim_enable_msi() could be nice. There would probably be other similar functions that could benefit from similar wrappers so that might be best kept separate in any case, also for backporting reasons.

Quoted 6 lines
drivers/media/pci/intel/ipu3/ipu3-cio2.c +3 -0
+	if (r)
+		return r;
+
 	r = cio2_fbpt_init_dummy(cio2);
 	if (r)
 		return r;
Signature · 3 lines
Kind regards,

Sakari Ailus