Skip to contentSkip to conversation

ata: sata_mv: Use platform_get_irq() to get interrupt

PATCH Applied Rosen Penev 3 participants 3 messages Jul 12 – Jul 18 libata

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ata: sata_mv: Use platform_get_irq() to get interrupt

Extract platform_get_irq() out of the conditional block to run it unconditionally, replacing the direct use of irq_of_parse_and_map() for DT-based systems. This simplifies the probe logic and avoids the need for irq_dispose_mapping.

Remove dead branch for platform_get_irq(). It intercepts 0 and returns -EINVAL, which goes to the first one.

Assisted-by Antigravity:Gemini-3.5-Flash

---
v2: remove dead branch

 drivers/ata/sata_mv.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/ata/sata_mv.c +1 -5
index 41647a56a9f4..a2bf9551a600 100644
@@ -4054,17 +4054,13 @@ static int mv_platform_probe(struct platform_device *pdev)
 				n_ports);
 			return -EINVAL;
 		}
-
-		irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
 	} else {
 		mv_platform_data = dev_get_platdata(&pdev->dev);
 		n_ports = mv_platform_data->n_ports;
-		irq = platform_get_irq(pdev, 0);
 	}
+	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
-	if (!irq)
-		return -EINVAL;
 
 	host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
 	hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing NULL check for mv_platform_data causes a kernel panic if the driver is bound to a device without platform data.
- [High] The pdev->num_resources != 1 check prevents initialization on legacy platforms that provide multiple resources.
- [High] Unbalanced clock cleanup in error path triggers CCF warnings.
- [High] Clock resource leak when port PHY retrieval fails.
--

--- Patch [1]: [PATCHv2] ata: sata_mv: Use platform_get_irq() to get interrupt --- commit a89dd91d3fc9df13b699dc2ac8e0b99f240449bf
Author: Rosen Penev <[email protected]>

ata: sata_mv: Use platform_get_irq() to get interrupt

Extract platform_get_irq() out of the conditional block to run it unconditionally, replacing the direct use of irq_of_parse_and_map() for DT-based systems. This simplifies the probe logic and avoids the need for irq_dispose_mapping. Remove dead branch for platform_get_irq().

drivers/ata/sata_mv.c static int mv_platform_probe(struct platform_device *pdev) · line 4059

Quoted 13 lines
drivers/ata/sata_mv.c +0 -2
index 41647a56a9f4e..a2bf9551a6008 100644
@@ -4054,17 +4054,13 @@ static int mv_platform_probe(struct platform_device *pdev)
 				n_ports);
 			return -EINVAL;
 		}
-
-		irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
 	} else {
 		mv_platform_data = dev_get_platdata(&pdev->dev);
 		n_ports = mv_platform_data->n_ports;

[Severity: High]
This is a pre-existing issue, but is there a missing NULL check here?

If the driver is manually bound via sysfs to a platform device lacking platform data (and without a device tree node), dev_get_platdata() returns NULL, which is immediately dereferenced when accessing n_ports. Could this cause a panic?

drivers/ata/sata_mv.c static int mv_platform_probe(struct platform_device *pdev) · line 4066

Quoted 10 lines
drivers/ata/sata_mv.c +1 -3
-		irq = platform_get_irq(pdev, 0);
 	}
+	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
-	if (!irq)
-		return -EINVAL;
 
 	host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
 	hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);

[Severity: High]
This isn't a bug introduced by this patch, but does the strict resource validation in mv_platform_probe() prevent initialization on legacy platforms?

drivers/ata/sata_mv.c:mv_platform_probe() {
    ...
	if (unlikely(pdev->num_resources != 1)) {
		dev_err(&pdev->dev, "invalid number of resources\n");
		return -EINVAL;
	}
    ...
}

Legacy board files instantiate the sata_mv platform device with two resources (an IORESOURCE_MEM and an IORESOURCE_IRQ). This validation causes the probe to immediately abort with -EINVAL. Could this render the SATA controller unusable on legacy Orion boards?

[Severity: High]
This is a pre-existing issue, but does the cleanup path in mv_platform_probe() unbalance the clock enable count?

drivers/ata/sata_mv.c:mv_platform_probe() {
    ...
	hpriv->clk = clk_get(&pdev->dev, NULL);
	if (IS_ERR(hpriv->clk)) {
		dev_notice(&pdev->dev, "cannot get optional clkdev\n");
	} else {
		rc = clk_prepare_enable(hpriv->clk);
		if (rc)
			goto err;
	}
    ...
err:
	if (!IS_ERR(hpriv->clk)) {
		clk_disable_unprepare(hpriv->clk);
		clk_put(hpriv->clk);
	}
    ...
}

If clk_prepare_enable(hpriv->clk) fails, the code branches to the err label. Because !IS_ERR(hpriv->clk) evaluates to true (the pointer is valid), the cleanup path attempts to disable the clock despite the initialization failure. Does this trigger a WARN_ON in the Common Clock Framework?

[Severity: High]
This is a pre-existing issue, but is there a clock resource leak in mv_platform_probe() when port PHY retrieval fails?

drivers/ata/sata_mv.c:mv_platform_probe() {
    ...
	for (port = 0; port < n_ports; port++) {
        ...
		hpriv->port_clks[port] = clk_get(&pdev->dev, port_number);
		if (!IS_ERR(hpriv->port_clks[port]))
			clk_prepare_enable(hpriv->port_clks[port]);

		sprintf(port_number, "port%d", port);
		hpriv->port_phys[port] = devm_phy_optional_get(&pdev->dev,
							       port_number);
		if (IS_ERR(hpriv->port_phys[port])) {
			rc = PTR_ERR(hpriv->port_phys[port]);
			hpriv->port_phys[port] = NULL;
            ...
			hpriv->n_ports = port;
			goto err;
		} else
    ...
err:
    ...
	for (port = 0; port < hpriv->n_ports; port++) {
		if (!IS_ERR(hpriv->port_clks[port])) {
			clk_disable_unprepare(hpriv->port_clks[port]);
			clk_put(hpriv->port_clks[port]);
		}
		phy_power_off(hpriv->port_phys[port]);
	}
    ...
}

Inside the per-port initialization loop, hpriv->port_clks[port] is obtained and enabled. Immediately after, devm_phy_optional_get() is called. If this fails (e.g., returning -EPROBE_DEFER), the error handler sets hpriv->n_ports = port and jumps to the err label.

The cleanup loop iterates up to hpriv->n_ports - 1, thereby skipping the current port and failing to call clk_disable_unprepare() and clk_put() on the successfully acquired clock. Can this cause a clock reference leak that accumulates if the PHY driver defers probing?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw
In reply to Rosen Penev
Quoted 10 lines · Rosen Penev

Extract platform_get_irq() out of the conditional block to run it unconditionally, replacing the direct use of irq_of_parse_and_map() for DT-based systems. This simplifies the probe logic and avoids the need for irq_dispose_mapping.

Remove dead branch for platform_get_irq(). It intercepts 0 and returns -EINVAL, which goes to the first one.

Assisted-by Antigravity:Gemini-3.5-Flash

Applied to for-7.3. Thanks!

Signature · 2 lines
Damien Le Moal
Western Digital Research