Linux ATA/IDE development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: dlemoal@kernel.org, cassel@kernel.org, linux-ide@vger.kernel.org
Subject: Re: [PATCHv2] ata: sata_mv: Use platform_get_irq() to get interrupt
Date: Sun, 12 Jul 2026 22:31:53 +0000	[thread overview]
Message-ID: <20260712223153.B24241F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260712222003.1008136-1-rosenp@gmail.com>

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 <rosenp@gmail.com>

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().

> diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
> index 41647a56a9f4e..a2bf9551a6008 100644
> --- a/drivers/ata/sata_mv.c
> +++ b/drivers/ata/sata_mv.c
> @@ -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?

> -		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?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260712222003.1008136-1-rosenp@gmail.com?part=1

      reply	other threads:[~2026-07-12 22:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-12 22:20 [PATCHv2] ata: sata_mv: Use platform_get_irq() to get interrupt Rosen Penev
2026-07-12 22:31 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260712223153.B24241F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=rosenp@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox