[PATCH] platform: cznic: turris-omnia-mcu: Fix error check in omnia_mcu_register_trng()

Dan Carpenter posted 1 patch 1 year, 3 months ago
drivers/platform/cznic/turris-omnia-mcu-trng.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] platform: cznic: turris-omnia-mcu: Fix error check in omnia_mcu_register_trng()
Posted by Dan Carpenter 1 year, 3 months ago
The gpiod_to_irq() function never returns zero.  It returns negative
error codes or a positive IRQ number.  Update the checking to check
for negatives.

Fixes: 41bb142a4028 ("platform: cznic: turris-omnia-mcu: Add support for MCU provided TRNG")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
For more information about the history of IRQ return values see my blog:
https://staticthinking.wordpress.com/2023/08/07/writing-a-check-for-zero-irq-error-codes/
The gpiod_to_irq() function was modified to not return zero in 2016.

 drivers/platform/cznic/turris-omnia-mcu-trng.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/cznic/turris-omnia-mcu-trng.c b/drivers/platform/cznic/turris-omnia-mcu-trng.c
index ad953fb3c37a..9a1d9292dc9a 100644
--- a/drivers/platform/cznic/turris-omnia-mcu-trng.c
+++ b/drivers/platform/cznic/turris-omnia-mcu-trng.c
@@ -70,8 +70,8 @@ int omnia_mcu_register_trng(struct omnia_mcu *mcu)
 
 	irq_idx = omnia_int_to_gpio_idx[__bf_shf(OMNIA_INT_TRNG)];
 	irq = gpiod_to_irq(gpio_device_get_desc(mcu->gc.gpiodev, irq_idx));
-	if (!irq)
-		return dev_err_probe(dev, -ENXIO, "Cannot get TRNG IRQ\n");
+	if (irq < 0)
+		return dev_err_probe(dev, irq, "Cannot get TRNG IRQ\n");
 
 	/*
 	 * If someone else cleared the TRNG interrupt but did not read the
-- 
2.45.2
Re: [PATCH] platform: cznic: turris-omnia-mcu: Fix error check in omnia_mcu_register_trng()
Posted by Marek Behún 1 year, 3 months ago
On Thu, Sep 05, 2024 at 04:16:53PM +0300, Dan Carpenter wrote:
> The gpiod_to_irq() function never returns zero.  It returns negative
> error codes or a positive IRQ number.  Update the checking to check
> for negatives.
> 
> Fixes: 41bb142a4028 ("platform: cznic: turris-omnia-mcu: Add support for MCU provided TRNG")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Marek Behún <kabel@kernel.org>