[PATCH] mfd: htc-i2cpld: Fix an IS_ERR() vs NULL bug in htcpld_core_probe

Peng Wu posted 1 patch 3 years, 6 months ago
drivers/mfd/htc-i2cpld.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
[PATCH] mfd: htc-i2cpld: Fix an IS_ERR() vs NULL bug in htcpld_core_probe
Posted by Peng Wu 3 years, 6 months ago
The gpiochip_request_own_desc() function returns error pointers on error,
it doesn't return NULL.

Fixes: 0ef5164a81fbf ("mfd/omap1: htc-i2cpld: Convert to a pure GPIO driver")
Signed-off-by: Peng Wu <wupeng58@huawei.com>
---
 drivers/mfd/htc-i2cpld.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c
index 97d47715aa97..b45b1346ab54 100644
--- a/drivers/mfd/htc-i2cpld.c
+++ b/drivers/mfd/htc-i2cpld.c
@@ -567,23 +567,26 @@ static int htcpld_core_probe(struct platform_device *pdev)
 	htcpld->int_reset_gpio_hi = gpiochip_request_own_desc(&htcpld->chip[2].chip_out,
 							      7, "htcpld-core", GPIO_ACTIVE_HIGH,
 							      GPIOD_OUT_HIGH);
-	if (!htcpld->int_reset_gpio_hi)
+	if (IS_ERR(htcpld->int_reset_gpio_hi)) {
 		/*
 		 * If it failed, that sucks, but we can probably
 		 * continue on without it.
 		 */
+		htcpld->int_reset_gpio_hi = NULL;
 		dev_warn(dev, "Unable to request int_reset_gpio_hi -- interrupts may not work\n");
-
+	}
 
 	htcpld->int_reset_gpio_lo = gpiochip_request_own_desc(&htcpld->chip[2].chip_out,
 							      0, "htcpld-core", GPIO_ACTIVE_HIGH,
 							      GPIOD_OUT_LOW);
-	if (!htcpld->int_reset_gpio_lo)
+	if (IS_ERR(htcpld->int_reset_gpio_lo)) {
 		/*
 		 * If it failed, that sucks, but we can probably
 		 * continue on without it.
 		 */
+		htcpld->int_reset_gpio_lo = NULL;
 		dev_warn(dev, "Unable to request int_reset_gpio_lo -- interrupts may not work\n");
+	}
 
 	dev_info(dev, "Initialized successfully\n");
 	return 0;
-- 
2.17.1
Re: [PATCH] mfd: htc-i2cpld: Fix an IS_ERR() vs NULL bug in htcpld_core_probe
Posted by Lee Jones 3 years, 6 months ago
On Tue, 13 Sep 2022, Peng Wu wrote:

> The gpiochip_request_own_desc() function returns error pointers on error,
> it doesn't return NULL.
> 
> Fixes: 0ef5164a81fbf ("mfd/omap1: htc-i2cpld: Convert to a pure GPIO driver")
> Signed-off-by: Peng Wu <wupeng58@huawei.com>
> ---
>  drivers/mfd/htc-i2cpld.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)

Applied, thanks.

-- 
Lee Jones [李琼斯]
Re: [PATCH] mfd: htc-i2cpld: Fix an IS_ERR() vs NULL bug in htcpld_core_probe
Posted by Linus Walleij 3 years, 6 months ago
On Tue, Sep 13, 2022 at 9:19 AM Peng Wu <wupeng58@huawei.com> wrote:

> The gpiochip_request_own_desc() function returns error pointers on error,
> it doesn't return NULL.
>
> Fixes: 0ef5164a81fbf ("mfd/omap1: htc-i2cpld: Convert to a pure GPIO driver")
> Signed-off-by: Peng Wu <wupeng58@huawei.com>

Good catch!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij