Skip to contentSkip to conversation

drm/tiny: sharp-memory: fix pointer error dereference

PATCH In review Ethan Tidmore 3 participants 3 messages Feb 16 – Feb 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/tiny: sharp-memory: fix pointer error dereference

The function devm_drm_dev_alloc() returns a pointer error upon failure not NULL. Change null check to pointer error check.

Detected by Smatch:
drivers/gpu/drm/tiny/sharp-memory.c:549 sharp_memory_probe() error:
'smd' dereferencing possible ERR_PTR()

Fixes b8f9f21716fec ("drm/tiny: Add driver for Sharp Memory LCD")
---
 drivers/gpu/drm/tiny/sharp-memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/tiny/sharp-memory.c +2 -2
index 64272cd0f6e2..cbf69460ebf3 100644
@@ -541,8 +541,8 @@ 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 PTR_ERR(smd);
 
 	spi_set_drvdata(spi, smd);
 
Signature · 1 line
2.53.0
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Ethan Tidmore

The function devm_drm_dev_alloc() returns a pointer error upon failure not NULL. Change null check to pointer error check.

Detected by Smatch:
drivers/gpu/drm/tiny/sharp-memory.c:549 sharp_memory_probe() error:
'smd' dereferencing possible ERR_PTR()

Fixes b8f9f21716fec ("drm/tiny: Add driver for Sharp Memory LCD")

Best regards
Uwe

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Ethan Tidmore

Am 16.02.26 um 05:04 schrieb Ethan Tidmore:

Quoted 9 lines

The function devm_drm_dev_alloc() returns a pointer error upon failure not NULL. Change null check to pointer error check.

Detected by Smatch:
drivers/gpu/drm/tiny/sharp-memory.c:549 sharp_memory_probe() error:
'smd' dereferencing possible ERR_PTR()

Fixes b8f9f21716fec ("drm/tiny: Add driver for Sharp Memory LCD")

Thanks for the fix.

Quoted 19 lines
---
  drivers/gpu/drm/tiny/sharp-memory.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/tiny/sharp-memory.c +2 -2
index 64272cd0f6e2..cbf69460ebf3 100644
@@ -541,8 +541,8 @@ 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 PTR_ERR(smd);
 
  	spi_set_drvdata(spi, smd);
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)