[PATCH 48/61] mtd: Prefer IS_ERR_OR_NULL over manual NULL check

Philipp Hahn
2026-03-10T11:55:52Z

Prefer using IS_ERR_OR_NULL() over using IS_ERR() and a manual NULL
check.

Change generated with coccinelle.

To: Miquel Raynal <miquel.raynal@bootlin.com>
To: Richard Weinberger <richard@nod.at>
To: Vignesh Raghavendra <vigneshr@ti.com>
Cc: linux-mtd@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Philipp Hahn <phahn-oss@avm.de>
---
drivers/mtd/nand/raw/gpio.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/raw/gpio.c b/drivers/mtd/nand/raw/gpio.c
index 69e5e43532a448aa6273f3df79f53145784ccc05..86a8b62fb9e8510d36f925b8b468ec17c77e26d8 100644
--- a/drivers/mtd/nand/raw/gpio.c
+++ b/drivers/mtd/nand/raw/gpio.c
@@ -276,9 +276,9 @@ static void gpio_nand_remove(struct platform_device *pdev)
nand_cleanup(chip);

/* Enable write protection and disable the chip */
- if (gpiomtd->nwp && !IS_ERR(gpiomtd->nwp))
+ if (!IS_ERR_OR_NULL(gpiomtd->nwp))
gpiod_set_value(gpiomtd->nwp, 0);
- if (gpiomtd->nce && !IS_ERR(gpiomtd->nce))
+ if (!IS_ERR_OR_NULL(gpiomtd->nce))
gpiod_set_value(gpiomtd->nce, 0);
}

@@ -358,7 +358,7 @@ static int gpio_nand_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, gpiomtd);

/* Disable write protection, if wired up */
- if (gpiomtd->nwp && !IS_ERR(gpiomtd->nwp))
+ if (!IS_ERR_OR_NULL(gpiomtd->nwp))
gpiod_direction_output(gpiomtd->nwp, 1);

/*
@@ -381,10 +381,10 @@ static int gpio_nand_probe(struct platform_device *pdev)
return 0;

err_wp:
- if (gpiomtd->nwp && !IS_ERR(gpiomtd->nwp))
+ if (!IS_ERR_OR_NULL(gpiomtd->nwp))
gpiod_set_value(gpiomtd->nwp, 0);
out_ce:
- if (gpiomtd->nce && !IS_ERR(gpiomtd->nce))
+ if (!IS_ERR_OR_NULL(gpiomtd->nce))
gpiod_set_value(gpiomtd->nce, 0);

return ret;

--
2.43.0