* [PATCH] drm/sharp-memory: Fix IS_ERR() vs NULL check in sharp_memory_probe()
@ 2026-01-30 9:22 Chen Ni
2026-01-31 7:04 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Chen Ni @ 2026-01-30 9:22 UTC (permalink / raw)
To: lanzano.alex, maarten.lankhorst, mripard, tzimmermann, airlied,
simona, lumag, mehdi.djait, u.kleine-koenig
Cc: dri-devel, linux-kernel, Chen Ni
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 <nichen@iscas.ac.cn>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/sharp-memory: Fix IS_ERR() vs NULL check in sharp_memory_probe()
2026-01-30 9:22 [PATCH] drm/sharp-memory: Fix IS_ERR() vs NULL check in sharp_memory_probe() Chen Ni
@ 2026-01-31 7:04 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2026-01-31 7:04 UTC (permalink / raw)
To: Chen Ni, dri-devel, Alex Lanzano, David Airlie, Dmitry Baryshkov,
Maarten Lankhorst, Maxime Ripard, Mehdi Djait, Simona Vetter,
Thomas Zimmermann, Uwe Kleine-König
Cc: LKML
…
> Replace the NULL check after devm_drm_dev_alloc() with IS_ERR()
May extra error messages be omitted for selected allocation failures?
> 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.
* Were any source code analysis tools involved here?
* Did anything hinder to add any tags (like “Fixes” and “Cc”) accordingly?
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-31 7:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-30 9:22 [PATCH] drm/sharp-memory: Fix IS_ERR() vs NULL check in sharp_memory_probe() Chen Ni
2026-01-31 7:04 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®