Skip to contentSkip to conversation

drm/omap: clean up error exit path on omap_encoder allocation failure

PATCH In review Colin Ian King 2 participants 2 messages Oct 15, 2024 – Oct 28, 2024

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

PATCH 1/1 drm/omap: clean up error exit path on omap_encoder allocation failure

Currently when an allocation failure occurs for omap_encoder the exit path will destroy encoder via omap_encoder_destroy if it is not null. However, encoder is always null at this point, so the check and destroy is redundant and can be removed. Clean up the code by removing the exit path and redundant omap_encoder_destroy call, and just return NULL.

---
 drivers/gpu/drm/omapdrm/omap_encoder.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/gpu/drm/omapdrm/omap_encoder.c +1 -7
index 4dd05bc732da..a99022638a2c 100644
@@ -126,21 +126,15 @@ struct drm_encoder *omap_encoder_init(struct drm_device *dev,
 
 	omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
 	if (!omap_encoder)
-		goto fail;
+		return NULL;
 
 	omap_encoder->output = output;
 
 	encoder = &omap_encoder->base;
 
 	drm_encoder_init(dev, encoder, &omap_encoder_funcs,
 			 DRM_MODE_ENCODER_TMDS, NULL);
 	drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
 
 	return encoder;
-
-fail:
-	if (encoder)
-		omap_encoder_destroy(encoder);
-
-	return NULL;
 }
Signature · 1 line
2.39.5
maintainer
#1 lore raw

Hi,

Quoted 10 lines · Colin Ian King

Currently when an allocation failure occurs for omap_encoder the exit path will destroy encoder via omap_encoder_destroy if it is not null. However, encoder is always null at this point, so the check and destroy is redundant and can be removed. Clean up the code by removing the exit path and redundant omap_encoder_destroy call, and just return NULL.

---
  drivers/gpu/drm/omapdrm/omap_encoder.c | 8 +-------
  1 file changed, 1 insertion(+), 7 deletions(-)

This is correct, but I think it would make sense to fix the error handling in omap_encoder_init() fully, instead of just partially: drm_encoder_init() can return an error, in which case we should free the omap_encoder.

Could you update the patch to do that too?

Tomi

Quoted 27 lines
drivers/gpu/drm/omapdrm/omap_encoder.c +1 -7
index 4dd05bc732da..a99022638a2c 100644
@@ -126,21 +126,15 @@ struct drm_encoder *omap_encoder_init(struct drm_device *dev,
 
  	omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
  	if (!omap_encoder)
-		goto fail;
+		return NULL;
 
  	omap_encoder->output = output;
 
  	encoder = &omap_encoder->base;
 
  	drm_encoder_init(dev, encoder, &omap_encoder_funcs,
  			 DRM_MODE_ENCODER_TMDS, NULL);
  	drm_encoder_helper_add(encoder, &omap_encoder_helper_funcs);
 
  	return encoder;
-
-fail:
-	if (encoder)
-		omap_encoder_destroy(encoder);
-
-	return NULL;
  }