Static analysis issue:

drm_encoder_init is capable of returning an error code in some cases,
such as when drm_mode_object_add fails, or if
dev->mode_config.num_encoder >= 32.  In these cases, encoder->dev is not
properly initialized, which may lead to issues when it is dereferenced
in, for example, intel_ddi_init_dp_connector, which calls
intel_dp_init_connector.

Much like the other error cases in this function, just return if an
error code is reported from drm_encoder_init.  Note that goto err in
this case would only exacerbate the issue, as drm_encoder_cleanup also
relies on encoder->dev being present.  So, just kfree the dig_port
before returning, as that's the only necessary part of the error path to
call here.

Signed-off-by: Jonathan Cavitt <[email protected]>
---
 drivers/gpu/drm/i915/display/intel_ddi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c 
b/drivers/gpu/drm/i915/display/intel_ddi.c
index d8739e2bb004..7fc5f726e9a8 100644
--- a/drivers/gpu/drm/i915/display/intel_ddi.c
+++ b/drivers/gpu/drm/i915/display/intel_ddi.c
@@ -5264,9 +5264,12 @@ void intel_ddi_init(struct intel_display *display,
        encoder = &dig_port->base;
        encoder->devdata = devdata;
 
-       drm_encoder_init(display->drm, &encoder->base, &intel_ddi_funcs,
-                        DRM_MODE_ENCODER_TMDS, "%s",
-                        intel_ddi_encoder_name(display, port, phy, 
&encoder_name));
+       if (drm_encoder_init(display->drm, &encoder->base, &intel_ddi_funcs,
+                            DRM_MODE_ENCODER_TMDS, "%s",
+                            intel_ddi_encoder_name(display, port, phy, 
&encoder_name))) {
+               kfree(dig_port);
+               return;
+       }
 
        intel_encoder_link_check_init(encoder, intel_ddi_link_check);
 
-- 
2.43.0

Reply via email to