Skip to contentSkip to conversation

usb: chipidea: ci_hdrc_imx: Propagate errors from optional IRQ lookup

PATCH In review [email protected] 4 participants 7 messages Aug 10 – Sep 11

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

PATCH v3 1/2 usb: chipidea: ci_hdrc_imx: Propagate errors from optional IRQ lookup

From: bui duc phuc <[email protected]>

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no IRQ is available, while other errors should be propagated.

Propagate errors such as -EPROBE_DEFER and -EINVAL instead of continuing probe without the IRQ.

---

Link v2:
https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Use the phy_shutdown label instead of err_clk as suggested by Sashiko's review.
- Add Peter Chen's Acked-by tag.

 drivers/usb/chipidea/ci_hdrc_imx.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/chipidea/ci_hdrc_imx.c +4 -0
index 56d2ba824a0b..9e529398c607 100644
@@ -525,6 +525,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		data->supports_runtime_pm = true;
 
 	data->wakeup_irq = platform_get_irq_optional(pdev, 1);
+	if (data->wakeup_irq < 0 && data->wakeup_irq != -ENXIO) {
+		ret = data->wakeup_irq;
+		goto phy_shutdown;
+	}
 	if (data->wakeup_irq > 0) {
 		irq_name = devm_kasprintf(dev, GFP_KERNEL, "%s:wakeup", pdata.name);
 		if (!irq_name) {
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 2/2 usb: chipidea: ci_hdrc_imx: Fix error handling when creating IRQ name

From: bui duc phuc <[email protected]>

devm_kasprintf() can fail when allocating the wakeup IRQ name. The error was logged with dev_err_probe(), but its return value was ignored and probe could continue with a successful return value.

Store the error returned by dev_err_probe() in ret and jump to the error path to propagate the failure.

---

Link v2:
https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Use the phy_shutdown label instead of err_clk as suggested by Sashiko's review.
- Add Peter Chen's Acked-by tag.
- Add Frank Li's Reviewed-by tag.

 drivers/usb/chipidea/ci_hdrc_imx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/chipidea/ci_hdrc_imx.c +3 -3
index 9e529398c607..edbf9df9b8f2 100644
@@ -532,8 +532,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 	if (data->wakeup_irq > 0) {
 		irq_name = devm_kasprintf(dev, GFP_KERNEL, "%s:wakeup", pdata.name);
 		if (!irq_name) {
-			dev_err_probe(dev, -ENOMEM, "failed to create irq_name\n");
-			goto err_clk;
+			ret = dev_err_probe(dev, -ENOMEM, "failed to create irq_name\n");
+			goto phy_shutdown;
 		}
 
 		ret = devm_request_threaded_irq(dev, data->wakeup_irq,
@@ -541,7 +541,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 						IRQF_ONESHOT | IRQF_NO_AUTOEN,
 						irq_name, data);
 		if (ret)
-			goto err_clk;
+			goto phy_shutdown;
 	}
 
 	ret = imx_usbmisc_init(data->usbmisc_data);
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v3 2/2] usb: chipidea: ci_hdrc_imx: Fix error handling when creating IRQ name

Quoted 54 lines · On Mon, Aug 10, 2026 at 04:31:12PM +0700, [email protected] wrote:

From: bui duc phuc <[email protected]>

devm_kasprintf() can fail when allocating the wakeup IRQ name. The error was logged with dev_err_probe(), but its return value was ignored and probe could continue with a successful return value.

Store the error returned by dev_err_probe() in ret and jump to the error path to propagate the failure.

---

Link v2:
https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Use the phy_shutdown label instead of err_clk as suggested by Sashiko's review.
- Add Peter Chen's Acked-by tag.
- Add Frank Li's Reviewed-by tag.

 drivers/usb/chipidea/ci_hdrc_imx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/chipidea/ci_hdrc_imx.c +3 -3
index 9e529398c607..edbf9df9b8f2 100644
@@ -532,8 +532,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 	if (data->wakeup_irq > 0) {
 		irq_name = devm_kasprintf(dev, GFP_KERNEL, "%s:wakeup", pdata.name);
 		if (!irq_name) {
-			dev_err_probe(dev, -ENOMEM, "failed to create irq_name\n");
-			goto err_clk;
+			ret = dev_err_probe(dev, -ENOMEM, "failed to create irq_name\n");
+			goto phy_shutdown;
 		}
 
 		ret = devm_request_threaded_irq(dev, data->wakeup_irq,
@@ -541,7 +541,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 						IRQF_ONESHOT | IRQF_NO_AUTOEN,
 						irq_name, data);
 		if (ret)
-			goto err_clk;
+			goto phy_shutdown;
 	}
 
 	ret = imx_usbmisc_init(data->usbmisc_data);
Signature · 1 line
2.43.0

This patch did not apply, please rebase and resend.

thanks,
greg k-h

#3 lore raw

Re: [PATCH v3 2/2] usb: chipidea: ci_hdrc_imx: Fix error handling when creating IRQ name

Hi Greg,

Thanks for letting me know.

Quoted 3 lines

This patch did not apply, please rebase and resend.

I have rebased the patch and resent it here:

https://lore.kernel.org/all/[email protected]/

Best regards,
Phuc

#4 lore raw
In reply to [email protected]
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

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

Pre-existing issues:
- [High] If devm_kasprintf() fails to allocate memory for irq_name, dev_err_probe() is called but its return value is not assigned to ret. Since ret is 0 at this point, the probe function incorrectly returns 0 (success) despite the failure, leaving the device in a broken, partially initialized state. --

--- Patch [1]: [PATCH v3 1/2] usb: chipidea: ci_hdrc_imx: Propagate errors from optional IRQ lookup --- commit bd6ce4edd163bb35e7e3be5ae05ae52d0c380e8a
Author: bui duc phuc <[email protected]>

usb: chipidea: ci_hdrc_imx: Propagate errors from optional IRQ lookup

This commit updates ci_hdrc_imx_probe() to propagate errors returned from platform_get_irq_optional(). Instead of continuing without an IRQ on failures like -EPROBE_DEFER or -EINVAL, the driver now properly aborts and returns the error.

Quoted 5 lines
drivers/usb/chipidea/ci_hdrc_imx.c +0 -0
index 56d2ba824a0b2..9e529398c6075 100644

drivers/usb/chipidea/ci_hdrc_imx.c static int ci_hdrc_imx_probe(struct platform_device *pdev) · line 534

Quoted 10 lines
drivers/usb/chipidea/ci_hdrc_imx.c +4 -0
@@ -525,6 +525,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		data->supports_runtime_pm = true;
 
 	data->wakeup_irq = platform_get_irq_optional(pdev, 1);
+	if (data->wakeup_irq < 0 && data->wakeup_irq != -ENXIO) {
+		ret = data->wakeup_irq;
+		goto phy_shutdown;
+	}
 	if (data->wakeup_irq > 0) {
 		irq_name = devm_kasprintf(dev, GFP_KERNEL, "%s:wakeup", pdata.name);
 		if (!irq_name) {

[Severity: High]
This is a pre-existing issue, but missing an assignment to ret here causes the probe to falsely succeed:

drivers/usb/chipidea/ci_hdrc_imx.c:ci_hdrc_imx_probe() {
    ...
	if (data->wakeup_irq > 0) {
		irq_name = devm_kasprintf(dev, GFP_KERNEL, "%s:wakeup", pdata.name);
		if (!irq_name) {
			dev_err_probe(dev, -ENOMEM, "failed to create irq_name\n");
			goto err_clk;
		}
    ...
}

Because dev_err_probe() is called but its return value is not assigned to ret, and ret is 0 at this point, the probe function incorrectly returns 0 (success) despite the memory allocation failure.

Does this code need to assign the error to ret before jumping to err_clk?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#5 lore raw
Quoted 15 lines

[Severity: High]
This is a pre-existing issue, but missing an assignment to ret here causes the probe to falsely succeed:

drivers/usb/chipidea/ci_hdrc_imx.c:ci_hdrc_imx_probe() {
    ...
        if (data->wakeup_irq > 0) {
                irq_name = devm_kasprintf(dev, GFP_KERNEL, "%s:wakeup", pdata.name);
                if (!irq_name) {
                        dev_err_probe(dev, -ENOMEM, "failed to create irq_name\n");
                        goto err_clk;
                }
    ...
}
Quoted 5 lines

Because dev_err_probe() is called but its return value is not assigned to ret, and ret is 0 at this point, the probe function incorrectly returns 0 (success) despite the memory allocation failure.

Does this code need to assign the error to ret before jumping to err_clk?

This issue has been addressed in patch 2:
[PATCH v3 2/2] usb: chipidea: ci_hdrc_imx: Fix error handling when creating IRQ name

Reviewed-by on v3 1/2
#6 lore raw
In reply to [email protected]
Quoted 6 lines · On Mon, Aug 10, 2026 at 04:31:11PM +0700, [email protected] wrote:

From: bui duc phuc <[email protected]>

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no IRQ is available, while other errors should be propagated.

Quoted 6 lines

Propagate errors such as -EPROBE_DEFER and -EINVAL instead of continuing probe without the IRQ.

---

Quoted 30 lines

Link v2:
https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Use the phy_shutdown label instead of err_clk as suggested by Sashiko's review.
- Add Peter Chen's Acked-by tag.

 drivers/usb/chipidea/ci_hdrc_imx.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/usb/chipidea/ci_hdrc_imx.c +4 -1
index 56d2ba824a0b..9e529398c607 100644
@@ -525,6 +525,10 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
 		data->supports_runtime_pm = true;
 
 	data->wakeup_irq = platform_get_irq_optional(pdev, 1);
+	if (data->wakeup_irq < 0 && data->wakeup_irq != -ENXIO) {
+		ret = data->wakeup_irq;
+		goto phy_shutdown;
+	}
 	if (data->wakeup_irq > 0) {
 		irq_name = devm_kasprintf(dev, GFP_KERNEL, "%s:wakeup", pdata.name);
 		if (!irq_name) {
--

2.43.0