Skip to contentSkip to conversation

serial: hvc: use modern IRQ acquisition API

PATCH Superseded Rosen Penev 2 participants 2 messages Sep 25

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: hvc: use modern IRQ acquisition API

Use platform_get_irq_optional() to be able to handle potential -EPROBE_DEFER and other errors.

---
 drivers/tty/hvc/hvc_opal.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/tty/hvc/hvc_opal.c +6 -4
index 402da9e7c534..ce726b8b5ab0 100644
@@ -13,7 +13,6 @@
 #include <linux/slab.h>
 #include <linux/console.h>
 #include <linux/of.h>
-#include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/export.h>
 #include <linux/interrupt.h>
@@ -157,8 +156,9 @@ static int hvc_opal_probe(struct platform_device *dev)
 	struct hvc_struct *hp;
 	struct hvc_opal_priv *pv;
 	hv_protocol_t proto;
-	unsigned int termno, irq, boot = 0;
+	unsigned int termno, boot = 0;
 	const __be32 *reg;
+	int irq;
 
 	if (of_device_is_compatible(dev->dev.of_node, "ibm,opal-console-raw")) {
 		proto = HV_PROTOCOL_RAW;
@@ -209,8 +209,10 @@ static int hvc_opal_probe(struct platform_device *dev)
 		dev->dev.of_node,
 		boot ? " (boot console)" : "");
 
-	irq = irq_of_parse_and_map(dev->dev.of_node, 0);
-	if (!irq) {
+	irq = platform_get_irq_optional(dev, 0);
+	if (irq == -EPROBE_DEFER)
+		return irq;
+	if (irq < 0) {
 		pr_info("hvc%d: No interrupts property, using OPAL event\n",
 				termno);
 		irq = opal_event_request(ilog2(OPAL_EVENT_CONSOLE_INPUT));
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] tty: hvc: permanent probe failure on -EPROBE_DEFER due to state corruption --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] tty: hvc: permanent probe failure on -EPROBE_DEFER due to state corruption --

commit 3ec0d2af78ba8c496b4a45223b1fb5f9769284c2
Author: Rosen Penev <[email protected]>

serial: hvc: use modern IRQ acquisition API

This patch updates the hvc_opal driver to use platform_get_irq_optional() for acquiring its interrupt. It adds handling for -EPROBE_DEFER and other negative error codes returned by the new API.

Quoted 4 lines
drivers/tty/hvc/hvc_opal.c +0 -0
index 402da9e7c5346..ce726b8b5ab00 100644

[ ... ]

drivers/tty/hvc/hvc_opal.c static int hvc_opal_probe(struct platform_device *dev) · line 214

Quoted 9 lines
drivers/tty/hvc/hvc_opal.c +3 -2
@@ -209,8 +209,10 @@ static int hvc_opal_probe(struct platform_device *dev)
 		dev->dev.of_node,
 		boot ? " (boot console)" : "");
 
-	irq = irq_of_parse_and_map(dev->dev.of_node, 0);
-	if (!irq) {
+	irq = platform_get_irq_optional(dev, 0);
+	if (irq == -EPROBE_DEFER)
+		return irq;

[Severity: High]
Can this early return cause a memory leak and permanent probe failure on retry?

Earlier in hvc_opal_probe(), the driver allocates a struct hvc_opal_priv and saves it in a global array:

drivers/tty/hvc/hvc_opal.c:hvc_opal_probe() {
    ...
    } else if (hvc_opal_privs[termno] == NULL) {
        pv = kzalloc_obj(struct hvc_opal_priv);
        if (!pv)
            return -ENOMEM;
        pv->proto = proto;
        hvc_opal_privs[termno] = pv;
    ...
}

If platform_get_irq_optional() returns -EPROBE_DEFER here, the function returns immediately without freeing pv or clearing hvc_opal_privs[termno].

When the driver is later re-probed, it will see that hvc_opal_privs[termno] is no longer NULL and fail with -ENXIO:

drivers/tty/hvc/hvc_opal.c:hvc_opal_probe() {
    ...
    } else {
        pr_err("hvc_opal: Device %pOF has duplicate terminal number #%d\n",
               dev->dev.of_node, termno);
        return -ENXIO;
    }
}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1