Skip to contentSkip to conversation

drm/ingenic: fix error code in ingenic_drm_gem_create_object()

PATCH In review Dan Carpenter 2 participants 2 messages Nov 18, 2021 – Dec 9, 2021

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

PATCH 1/1 drm/ingenic: fix error code in ingenic_drm_gem_create_object()

The ->gem_create_object() function pointers are supposed to return NULL on error. This function returns an error pointer but none of the callers expect that so it will lead to an Oops. See drm_gem_vram_create() for example of it checks for NULL but an error pointer would lead to a crash.

Fixes 4a791cb6d34f ("drm/ingenic: Add option to alloc cached GEM buffers")
---
 drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ingenic/ingenic-drm-drv.c +1 -1
index a5df1c8d34cd..eb7266a0b037 100644
@@ -757,7 +757,7 @@ ingenic_drm_gem_create_object(struct drm_device *drm, size_t size)
 
 	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
 	if (!obj)
-		return ERR_PTR(-ENOMEM);
+		return NULL;
 
 	obj->map_noncoherent = priv->soc_info->map_noncoherent;
 
Signature · 1 line
2.20.1
#1 lore raw

FYI this issue was fixed by [1]. Please don't merge.

[1] https://lore.kernel.org/dri-devel/[email protected]/

Am 18.11.21 um 12:15 schrieb Dan Carpenter:

Quoted 26 lines

The ->gem_create_object() function pointers are supposed to return NULL on error. This function returns an error pointer but none of the callers expect that so it will lead to an Oops. See drm_gem_vram_create() for example of it checks for NULL but an error pointer would lead to a crash.

Fixes 4a791cb6d34f ("drm/ingenic: Add option to alloc cached GEM buffers")
---
  drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ingenic/ingenic-drm-drv.c +1 -1
index a5df1c8d34cd..eb7266a0b037 100644
@@ -757,7 +757,7 @@ ingenic_drm_gem_create_object(struct drm_device *drm, size_t size)
 
  	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
  	if (!obj)
-		return ERR_PTR(-ENOMEM);
+		return NULL;
 
  	obj->map_noncoherent = priv->soc_info->map_noncoherent;
 
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev