Skip to contentSkip to conversation

char: Remove redundant error messages on IRQ request failure

PATCH Applied Pan Chuang 5 participants 8 messages Jul 10 – Jul 17

Subsystems (10)
lore
Share & tools
lore

Pan Chuang

author
#0 lore raw

cover char: Remove redundant error messages on IRQ request failure

Commit 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()") added automatic error logging to devm_request_threaded_irq() and devm_request_any_context_irq() via the new devm_request_result() helper, which prints device name, IRQ number, handler functions, and error code on failure.

Since devm_request_irq() is a static inline wrapper around devm_request_threaded_irq(), it also benefits from this automatic logging.

Remove the now-redundant dev_err() and dev_err_probe() calls in char drivers that follow these devm_request_*_irq() functions, as the core now provides more detailed diagnostic information on failure.

Pan Chuang (3):
hwrng: drivers - Remove redundant dev_err()/dev_err_probe()
tpm: Remove redundant dev_err()
char: xillybus: Remove redundant dev_err()

 drivers/char/hw_random/airoha-trng.c  | 4 +---
 drivers/char/hw_random/cctrng.c       | 2 +-
 drivers/char/hw_random/imx-rngc.c     | 2 +-
 drivers/char/hw_random/jh7110-trng.c  | 3 +--
 drivers/char/hw_random/omap-rng.c     | 5 +----
 drivers/char/hw_random/xgene-rng.c    | 2 +-
 drivers/char/tpm/st33zp24/st33zp24.c  | 5 +----
 drivers/char/tpm/tpm_i2c_nuvoton.c    | 2 --
 drivers/char/tpm/tpm_tis_i2c_cr50.c   | 4 +---
 drivers/char/xillybus/xillybus_of.c   | 5 +----
 drivers/char/xillybus/xillybus_pcie.c | 5 +----
 11 files changed, 10 insertions(+), 29 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/3 hwrng: drivers - Remove redundant dev_err()/dev_err_probe()

Since commit 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()"), devm_request_irq() automatically logs detailed error messages on failure. Remove the now-redundant driver-specific dev_err() and dev_err_probe() calls.

---
 drivers/char/hw_random/airoha-trng.c | 4 +---
 drivers/char/hw_random/cctrng.c      | 2 +-
 drivers/char/hw_random/imx-rngc.c    | 2 +-
 drivers/char/hw_random/jh7110-trng.c | 3 +--
 drivers/char/hw_random/omap-rng.c    | 5 +----
 drivers/char/hw_random/xgene-rng.c   | 2 +-
 6 files changed, 6 insertions(+), 12 deletions(-)
drivers/char/hw_random/airoha-trng.c +1 -3
index 076519a2f100..98c131ee9891 100644
@@ -186,10 +186,8 @@ static int airoha_trng_probe(struct platform_device *pdev)
 	airoha_trng_irq_mask(trng);
 	ret = devm_request_irq(&pdev->dev, irq, airoha_trng_irq, 0,
 			       pdev->name, (void *)trng);
-	if (ret) {
-		dev_err(dev, "Can't get interrupt working.\n");
+	if (ret)
 		return ret;
-	}
 
 	init_completion(&trng->rng_op_done);
 
drivers/char/hw_random/cctrng.c +1 -1
index a5be9258037f..a6925211c3b5 100644
@@ -509,7 +509,7 @@ static int cctrng_probe(struct platform_device *pdev)
 	/* register the driver isr function */
 	rc = devm_request_irq(dev, irq, cc_isr, IRQF_SHARED, "cctrng", drvdata);
 	if (rc)
-		return dev_err_probe(dev, rc, "Could not register to interrupt %d\n", irq);
+		return rc;
 	dev_dbg(dev, "Registered to IRQ: %d\n", irq);
 
 	/* Clear all pending interrupts */
drivers/char/hw_random/imx-rngc.c +1 -1
index 28c56c2d1bf6..bae8cdca13fe 100644
@@ -296,7 +296,7 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
 			irq, imx_rngc_irq, 0, pdev->name, (void *)rngc);
 	if (ret) {
 		clk_disable_unprepare(rngc->clk);
-		return dev_err_probe(&pdev->dev, ret, "Can't get interrupt working.\n");
+		return ret;
 	}
 
 	if (self_test) {
drivers/char/hw_random/jh7110-trng.c +1 -2
index 4712c3c530e4..aee12caab578 100644
@@ -303,8 +303,7 @@ static int starfive_trng_probe(struct platform_device *pdev)
 	ret = devm_request_irq(&pdev->dev, irq, starfive_trng_irq, 0, pdev->name,
 			       (void *)trng);
 	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
-				     "Failed to register interrupt handler\n");
+		return ret;
 
 	trng->hclk = devm_clk_get(&pdev->dev, "hclk");
 	if (IS_ERR(trng->hclk))
drivers/char/hw_random/omap-rng.c +1 -4
index 5e8b50f15db7..327643ba971c 100644
@@ -391,11 +391,8 @@ static int of_get_omap_rng_device_details(struct omap_rng_dev *priv,
 
 		err = devm_request_irq(dev, irq, omap4_rng_irq,
 				       IRQF_TRIGGER_NONE, dev_name(dev), priv);
-		if (err) {
-			dev_err(dev, "unable to request irq %d, err = %d\n",
-				irq, err);
+		if (err)
 			return err;
-		}
 
 		/*
 		 * On OMAP4, enabling the shutdown_oflo interrupt is
drivers/char/hw_random/xgene-rng.c +1 -1
index 1f4b95341c2e..629dc85c3741 100644
@@ -336,7 +336,7 @@ static int xgene_rng_probe(struct platform_device *pdev)
 	rc = devm_request_irq(&pdev->dev, ctx->irq, xgene_rng_irq_handler, 0,
 				dev_name(&pdev->dev), ctx);
 	if (rc)
-		return dev_err_probe(&pdev->dev, rc, "Could not request RNG alarm IRQ\n");
+		return rc;
 
 	/* Enable IP clock */
 	clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/3] hwrng: drivers - Remove redundant dev_err()/dev_err_probe()

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

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

Pre-existing issues:
- [High] PM runtime and clock reference leak when the second clock defers probe.
- [High] Device IRQ is requested before hardware clocks and resets are ready.
- [High] Device IRQ is requested before the IP clock is enabled.
- [High] The driver leaks its PM runtime enablement, reset control deassertion, and clock enablements upon driver unbind because it lacks a remove function.
- [High] The driver queues background works (compwork and startwork) but fails to cancel them during driver removal, leading to a Use-After-Free.
- [High] The driver starts a failure recovery timer but fails to delete it when the driver is removed, leading to a Use-After-Free.
- [Medium] Clock prepare/enable leak on error path during probe.
- [Medium] PM runtime reference leak on error path during probe.
--

--- Patch [1]: [PATCH 1/3] hwrng: drivers - Remove redundant dev_err()/dev_err_probe() --- commit 5b0e3802decb80a4bd7c81e612150dfe5af3cc8a
Author: Pan Chuang <[email protected]>

hwrng: drivers - Remove redundant dev_err()/dev_err_probe()

This patch removes driver-specific dev_err() and dev_err_probe() calls following devm_request_irq() since the core now automatically logs these errors.

drivers/char/hw_random/cctrng.c static int cctrng_probe(struct platform_device *pdev) · line 512

Quoted 9 lines
drivers/char/hw_random/cctrng.c +1 -1
@@ -509,7 +509,7 @@ static int cctrng_probe(struct platform_device *pdev)
 	/* register the driver isr function */
 	rc = devm_request_irq(dev, irq, cc_isr, IRQF_SHARED, "cctrng", drvdata);
 	if (rc)
-		return dev_err_probe(dev, rc, "Could not register to interrupt %d\n", irq);
+		return rc;

[Severity: Medium]
This is a pre-existing issue, but does this error path leave the PM runtime reference count elevated?

In cctrng_probe(), cc_trng_pm_get() increments the PM runtime usage count. If devm_hwrng_register() subsequently fails, the code jumps to post_pm_err:

drivers/char/hw_random/cctrng.c:cctrng_probe() {
    ...
    rc = devm_hwrng_register(dev, &drvdata->rng);
    if (rc) {
        dev_err(dev, "Could not register hwrng device.\n");
        goto post_pm_err;
    }
    ...
post_pm_err:
    cc_trng_pm_fini(drvdata);

    return rc;
}

Since cc_trng_pm_fini() only disables PM runtime but doesn't drop the usage count, does this permanently prevent the device's power domain from ever suspending?

[Severity: High]
This is a pre-existing issue, but does the driver queue background works that fail to cancel during driver removal?

The driver schedules asynchronous works (compwork and startwork) during hardware operation. The teardown function only disables PM runtime:

drivers/char/hw_random/cctrng.c:cctrng_remove() {
    ...
    cc_trng_pm_fini(drvdata);

    dev_info(dev, "ARM cctrng device terminated\n");
}

Does this lead to a Use-After-Free if a work item is pending or executing when the driver is unbound, since the devres framework will automatically free the drvdata context memory?

drivers/char/hw_random/imx-rngc.c static int __init imx_rngc_probe(struct platform_device *pdev) · line 301

Quoted 10 lines
drivers/char/hw_random/imx-rngc.c +1 -1
@@ -297,7 +297,7 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
 			irq, imx_rngc_irq, 0, pdev->name, (void *)rngc);
 	if (ret) {
 		clk_disable_unprepare(rngc->clk);
-		return dev_err_probe(&pdev->dev, ret, "Can't get interrupt working.\n");
+		return ret;
 	}

[Severity: Medium]
This is a pre-existing issue, but does this error path fail to undo the previous manual clock enablement?

In imx_rngc_probe(), rngc->clk is explicitly enabled via clk_prepare_enable(). If the subsequent call to devm_hwrng_register() fails, the function directly returns the error:

drivers/char/hw_random/imx-rngc.c:imx_rngc_probe() {
    ...
    ret = devm_hwrng_register(&pdev->dev, &rngc->rng);
    if (ret)
        return dev_err_probe(&pdev->dev, ret, "hwrng registration failed\n");
    ...
}

Does this leave the hardware clock perpetually enabled without calling clk_disable_unprepare(rngc->clk)?

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_probe(struct platform_device *pdev) · line 308

Quoted 12 lines
drivers/char/hw_random/jh7110-trng.c +1 -2
@@ -303,8 +303,7 @@ static int starfive_trng_probe(struct platform_device *pdev)
 	ret = devm_request_irq(&pdev->dev, irq, starfive_trng_irq, 0, pdev->name,
 			       (void *)trng);
 	if (ret)
-		return dev_err_probe(&pdev->dev, ret,
-				     "Failed to register interrupt handler\n");
+		return ret;
 
 	trng->hclk = devm_clk_get(&pdev->dev, "hclk");

[Severity: High]
This is a pre-existing issue, but is it safe to request the IRQ before the hardware clocks and resets are ready?

If a shared or pending interrupt triggers immediately upon registration, starfive_trng_irq() could execute and read STARFIVE_ISTAT while the hardware is unpowered and in reset.

Could this lead to a synchronous external abort when the unclocked device registers are accessed?

[Severity: High]
This is a pre-existing issue, but does the platform driver leak resources upon driver unbind?

The driver registers with module_platform_driver() without a remove callback:

drivers/char/hw_random/jh7110-trng.c {

static struct platform_driver starfive_trng_driver = {
    .probe = starfive_trng_probe,
    .driver = {
        .name = "jh7110-trng",

...
}

During starfive_trng_probe(), the driver manually enables clocks, deasserts reset, and enables PM runtime.

Since there is no remove callback, does devm automatically unregister the hwrng while leaving the manually acquired clocks, reset, and PM runtime states permanently active?

drivers/char/hw_random/omap-rng.c

Quoted 3 lines
drivers/char/hw_random/omap-rng.c +0 -0

[ ... ]

[Severity: High]
This is a pre-existing issue, but does the immediate return on -EPROBE_DEFER bypass manual resource cleanup?

In omap_rng_probe(), PM runtime is enabled and priv->clk is manually enabled. The driver then attempts to get the second clock:

drivers/char/hw_random/omap-rng.c:omap_rng_probe() {
    ...
    priv->clk_reg = devm_clk_get(&pdev->dev, "reg");
    if (PTR_ERR(priv->clk_reg) == -EPROBE_DEFER)
        return -EPROBE_DEFER;
    ...
}

Does this early return bypass the err_register and err_ioremap cleanup labels, leaving pm_runtime_put_sync(), pm_runtime_disable(), and clk_disable_unprepare(priv->clk) uncalled?

drivers/char/hw_random/xgene-rng.c static int xgene_rng_probe(struct platform_device *pdev) · line 343

Quoted 12 lines
drivers/char/hw_random/xgene-rng.c +1 -1
@@ -337,7 +337,7 @@ static int xgene_rng_probe(struct platform_device *pdev)
 	rc = devm_request_irq(&pdev->dev, ctx->irq, xgene_rng_irq_handler, 0,
 				dev_name(&pdev->dev), ctx);
 	if (rc)
-		return dev_err_probe(&pdev->dev, rc, "Could not request RNG alarm IRQ\n");
+		return rc;
 
 	/* Enable IP clock */
 	clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);

[Severity: High]
This is a pre-existing issue, but is the IRQ requested before the IP clock is enabled?

An early interrupt execution during this window could cause the handler to read the RNG_INTR_STS_ACK register.

Could accessing an unclocked APB/AHB register lead to a system crash or bus error?

[Severity: High]
This is a pre-existing issue, but does the driver start a failure recovery timer that fails to get deleted when the driver is removed?

The teardown function returns without canceling the asynchronous failure_timer:

drivers/char/hw_random/xgene-rng.c:xgene_rng_remove() {
    ...
    rc = device_init_wakeup(&pdev->dev, 0);
    if (rc)
        dev_err(&pdev->dev, "RNG init wakeup failed error %d\n", rc);
}

After remove() completes, the devres framework automatically frees the xgene_rng_dev context. If the timer later expires, could xgene_rng_expired_timer() execute and dereference the freed memory?

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

Re: [PATCH 1/3] hwrng: drivers - Remove redundant dev_err()/dev_err_probe()

In reply to Pan Chuang
Quoted 6 lines · Pan Chuang

Since commit 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()"), devm_request_irq() automatically logs detailed error messages on failure. Remove the now-redundant driver-specific dev_err() and dev_err_probe() calls.

Quoted 8 lines
---
 drivers/char/hw_random/airoha-trng.c | 4 +---
 drivers/char/hw_random/cctrng.c      | 2 +-
 drivers/char/hw_random/imx-rngc.c    | 2 +-
 drivers/char/hw_random/jh7110-trng.c | 3 +--
 drivers/char/hw_random/omap-rng.c    | 5 +----
 drivers/char/hw_random/xgene-rng.c   | 2 +-
 6 files changed, 6 insertions(+), 12 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author
#4 lore raw

PATCH 2/3 tpm: Remove redundant dev_err()

In reply to Pan Chuang

Since commit 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()"), devm_request_irq() automatically logs detailed error messages on failure. Remove the now-redundant driver-specific dev_err() calls.

---
 drivers/char/tpm/st33zp24/st33zp24.c | 5 +----
 drivers/char/tpm/tpm_i2c_nuvoton.c   | 2 --
 drivers/char/tpm/tpm_tis_i2c_cr50.c  | 4 +---
 3 files changed, 2 insertions(+), 9 deletions(-)
drivers/char/tpm/st33zp24/st33zp24.c +1 -4
index e2b7451ea7cc..8d5179367eac 100644
@@ -506,11 +506,8 @@ int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
 		ret = devm_request_irq(dev, irq, tpm_ioserirq_handler,
 				IRQF_TRIGGER_HIGH, "TPM SERIRQ management",
 				chip);
-		if (ret < 0) {
-			dev_err(&chip->dev, "TPM SERIRQ signals %d not available\n",
-				irq);
+		if (ret < 0)
 			goto _tpm_clean_answer;
-		}
 
 		intmask |= TPM_INTF_CMD_READY_INT
 			|  TPM_INTF_STS_VALID_INT
drivers/char/tpm/tpm_i2c_nuvoton.c +0 -2
index aa3673002f3a..c84afb29d548 100644
@@ -576,8 +576,6 @@ static int i2c_nuvoton_probe(struct i2c_client *client)
 				      dev_name(&chip->dev),
 				      chip);
 		if (rc) {
-			dev_err(dev, "%s() Unable to request irq: %d for use\n",
-				__func__, priv->irq);
 			priv->irq = 0;
 		} else {
 			chip->flags |= TPM_CHIP_FLAG_IRQ;
drivers/char/tpm/tpm_tis_i2c_cr50.c +1 -3
index b48cacacc066..7f828fae70d3 100644
@@ -751,10 +751,8 @@ static int tpm_cr50_i2c_probe(struct i2c_client *client)
 		rc = devm_request_irq(dev, client->irq, tpm_cr50_i2c_int_handler,
 				      IRQF_TRIGGER_FALLING | IRQF_NO_AUTOEN,
 				      dev->driver->name, chip);
-		if (rc < 0) {
-			dev_err(dev, "Failed to probe IRQ %d\n", client->irq);
+		if (rc < 0)
 			return rc;
-		}
 
 		priv->irq = client->irq;
 	} else {
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 2/3 Applied
#5 lore raw

Re: [PATCH 2/3] tpm: Remove redundant dev_err()

Quoted 6 lines · Pan Chuang

Since commit 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()"), devm_request_irq() automatically logs detailed error messages on failure. Remove the now-redundant driver-specific dev_err() calls.

Applied: https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/log/

Quoted 55 lines
---
 drivers/char/tpm/st33zp24/st33zp24.c | 5 +----
 drivers/char/tpm/tpm_i2c_nuvoton.c   | 2 --
 drivers/char/tpm/tpm_tis_i2c_cr50.c  | 4 +---
 3 files changed, 2 insertions(+), 9 deletions(-)
drivers/char/tpm/st33zp24/st33zp24.c +1 -4
index e2b7451ea7cc..8d5179367eac 100644
@@ -506,11 +506,8 @@ int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
 		ret = devm_request_irq(dev, irq, tpm_ioserirq_handler,
 				IRQF_TRIGGER_HIGH, "TPM SERIRQ management",
 				chip);
-		if (ret < 0) {
-			dev_err(&chip->dev, "TPM SERIRQ signals %d not available\n",
-				irq);
+		if (ret < 0)
 			goto _tpm_clean_answer;
-		}
 
 		intmask |= TPM_INTF_CMD_READY_INT
 			|  TPM_INTF_STS_VALID_INT
drivers/char/tpm/tpm_i2c_nuvoton.c +0 -2
index aa3673002f3a..c84afb29d548 100644
@@ -576,8 +576,6 @@ static int i2c_nuvoton_probe(struct i2c_client *client)
 				      dev_name(&chip->dev),
 				      chip);
 		if (rc) {
-			dev_err(dev, "%s() Unable to request irq: %d for use\n",
-				__func__, priv->irq);
 			priv->irq = 0;
 		} else {
 			chip->flags |= TPM_CHIP_FLAG_IRQ;
drivers/char/tpm/tpm_tis_i2c_cr50.c +1 -3
index b48cacacc066..7f828fae70d3 100644
@@ -751,10 +751,8 @@ static int tpm_cr50_i2c_probe(struct i2c_client *client)
 		rc = devm_request_irq(dev, client->irq, tpm_cr50_i2c_int_handler,
 				      IRQF_TRIGGER_FALLING | IRQF_NO_AUTOEN,
 				      dev->driver->name, chip);
-		if (rc < 0) {
-			dev_err(dev, "Failed to probe IRQ %d\n", client->irq);
+		if (rc < 0)
 			return rc;
-		}
 
 		priv->irq = client->irq;
 	} else {
Signature · 1 line
2.34.1

BR, Jarkko

author
#6 lore raw

PATCH 3/3 char: xillybus: Remove redundant dev_err()

In reply to Pan Chuang

Since commit 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()"), devm_request_irq() automatically logs detailed error messages on failure. Remove the now-redundant driver-specific dev_err() calls.

---
 drivers/char/xillybus/xillybus_of.c   | 5 +----
 drivers/char/xillybus/xillybus_pcie.c | 5 +----
 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/char/xillybus/xillybus_of.c +1 -4
index 1a1e64133315..46e1046abfca 100644
@@ -55,11 +55,8 @@ static int xilly_drv_probe(struct platform_device *op)
 
 	rc = devm_request_irq(dev, irq, xillybus_isr, 0, xillyname, endpoint);
 
-	if (rc) {
-		dev_err(endpoint->dev,
-			"Failed to register IRQ handler. Aborting.\n");
+	if (rc)
 		return -ENODEV;
-	}
 
 	return xillybus_endpoint_discovery(endpoint);
 }
drivers/char/xillybus/xillybus_pcie.c +1 -4
index 9858711e3e79..32064b6c7627 100644
@@ -83,11 +83,8 @@ static int xilly_probe(struct pci_dev *pdev,
 	}
 	rc = devm_request_irq(&pdev->dev, pdev->irq, xillybus_isr, 0,
 			      xillyname, endpoint);
-	if (rc) {
-		dev_err(endpoint->dev,
-			"Failed to register MSI handler. Aborting.\n");
+	if (rc)
 		return -ENODEV;
-	}
 
 	/*
 	 * Some (old and buggy?) hardware drops 64-bit addressed PCIe packets,
Signature · 1 line
2.34.1
maintainer Acked-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] char: xillybus: Remove redundant dev_err()

Quoted 5 lines · Pan Chuang

Since commit 55b48e23f5c4 ("genirq/devres: Add error handling in devm_request_*_irq()"), devm_request_irq() automatically logs detailed error messages on failure. Remove the now-redundant driver-specific dev_err() calls.

My opinion about error messages is the more the merrier, but I suppose this is part of a more general code cleanup. As this specific error message isn't expected to happen often, I have no reason to object.

Thanks & regards,
Eli