The devm_drm_dev_alloc() function returns an ERR_PTR encoded error
pointer on failure, not NULL. devm_gpiod_get_optional() may return
ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which
indicates the legitimate absence of an optional GPIO.

Replace the NULL check after devm_drm_dev_alloc() with IS_ERR() and add
a missing IS_ERR() check after devm_gpiod_get_optional(). On error,
return the error code from the probe function to ensure proper failure
handling rather than proceeding with invalid pointers.

Fixes: b8f9f21716fe ("drm/tiny: Add driver for Sharp Memory LCD")
Signed-off-by: Chen Ni <[email protected]>
---
 drivers/gpu/drm/tiny/sharp-memory.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/tiny/sharp-memory.c 
b/drivers/gpu/drm/tiny/sharp-memory.c
index 64272cd0f6e2..5e6a54a0696c 100644
--- a/drivers/gpu/drm/tiny/sharp-memory.c
+++ b/drivers/gpu/drm/tiny/sharp-memory.c
@@ -541,8 +541,9 @@ static int sharp_memory_probe(struct spi_device *spi)
 
        smd = devm_drm_dev_alloc(dev, &sharp_memory_drm_driver,
                                 struct sharp_memory_device, drm);
-       if (!smd)
-               return -ENOMEM;
+       if (IS_ERR(smd))
+               return dev_err_probe(dev, PTR_ERR(smd),
+                                    "Failed to allocate drm device\n");
 
        spi_set_drvdata(spi, smd);
 
@@ -553,6 +554,9 @@ static int sharp_memory_probe(struct spi_device *spi)
                return dev_err_probe(dev, ret, "Failed to initialize drm 
config\n");
 
        smd->enable_gpio = devm_gpiod_get_optional(dev, "enable", 
GPIOD_OUT_HIGH);
+       if (IS_ERR(smd->enable_gpio))
+               return dev_err_probe(dev, PTR_ERR(smd->enable_gpio),
+                                    "Failed to get gpio 'enable'\n");
        if (!smd->enable_gpio)
                dev_warn(dev, "Enable gpio not defined\n");
 
-- 
2.25.1

Reply via email to