diff mbox series

[v3,10/11] drm/i915/dp_mst: Fix error handling while adding a connector

Message ID 20241211230328.4012496-11-imre.deak@intel.com (mailing list archive)
State New
Headers show
Series drm/connector: Expose only a properly inited connector | expand

Commit Message

Imre Deak Dec. 11, 2024, 11:03 p.m. UTC
After an error during adding an MST connector the MST port and the
intel_connector object could be leaked, fix this up.

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 drivers/gpu/drm/i915/display/intel_dp_mst.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Jani Nikula Dec. 12, 2024, 10:16 a.m. UTC | #1
On Thu, 12 Dec 2024, Imre Deak <imre.deak@intel.com> wrote:
> After an error during adding an MST connector the MST port and the
> intel_connector object could be leaked, fix this up.
>
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Signed-off-by: Imre Deak <imre.deak@intel.com>

Reviewed-by: Jani Nikula <jani.nikula@intel.com>

> ---
>  drivers/gpu/drm/i915/display/intel_dp_mst.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c b/drivers/gpu/drm/i915/display/intel_dp_mst.c
> index debe4d0eee11f..99f08e31fd6e0 100644
> --- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
> +++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
> @@ -1743,11 +1743,8 @@ mst_topology_add_connector(struct drm_dp_mst_topology_mgr *mgr,
>  
>  	ret = drm_connector_dynamic_init(display->drm, connector, &mst_connector_funcs,
>  					 DRM_MODE_CONNECTOR_DisplayPort, NULL);
> -	if (ret) {
> -		drm_dp_mst_put_port_malloc(port);
> -		intel_connector_free(intel_connector);
> -		return NULL;
> -	}
> +	if (ret)
> +		goto err_put_port;
>  
>  	intel_connector->dp.dsc_decompression_aux = drm_dp_mst_dsc_aux_for_port(port);
>  	intel_dp_mst_read_decompression_port_dsc_caps(intel_dp, intel_connector);
> @@ -1762,12 +1759,12 @@ mst_topology_add_connector(struct drm_dp_mst_topology_mgr *mgr,
>  
>  		ret = drm_connector_attach_encoder(&intel_connector->base, enc);
>  		if (ret)
> -			goto err;
> +			goto err_cleanup_connector;
>  	}
>  
>  	ret = mst_topology_add_connector_properties(intel_dp, connector, pathprop);
>  	if (ret)
> -		goto err;
> +		goto err_cleanup_connector;
>  
>  	ret = intel_dp_hdcp_init(dig_port, intel_connector);
>  	if (ret)
> @@ -1776,8 +1773,12 @@ mst_topology_add_connector(struct drm_dp_mst_topology_mgr *mgr,
>  
>  	return connector;
>  
> -err:
> +err_cleanup_connector:
>  	drm_connector_cleanup(connector);
> +err_put_port:
> +	drm_dp_mst_put_port_malloc(port);
> +	intel_connector_free(intel_connector);
> +
>  	return NULL;
>  }
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_dp_mst.c b/drivers/gpu/drm/i915/display/intel_dp_mst.c
index debe4d0eee11f..99f08e31fd6e0 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
@@ -1743,11 +1743,8 @@  mst_topology_add_connector(struct drm_dp_mst_topology_mgr *mgr,
 
 	ret = drm_connector_dynamic_init(display->drm, connector, &mst_connector_funcs,
 					 DRM_MODE_CONNECTOR_DisplayPort, NULL);
-	if (ret) {
-		drm_dp_mst_put_port_malloc(port);
-		intel_connector_free(intel_connector);
-		return NULL;
-	}
+	if (ret)
+		goto err_put_port;
 
 	intel_connector->dp.dsc_decompression_aux = drm_dp_mst_dsc_aux_for_port(port);
 	intel_dp_mst_read_decompression_port_dsc_caps(intel_dp, intel_connector);
@@ -1762,12 +1759,12 @@  mst_topology_add_connector(struct drm_dp_mst_topology_mgr *mgr,
 
 		ret = drm_connector_attach_encoder(&intel_connector->base, enc);
 		if (ret)
-			goto err;
+			goto err_cleanup_connector;
 	}
 
 	ret = mst_topology_add_connector_properties(intel_dp, connector, pathprop);
 	if (ret)
-		goto err;
+		goto err_cleanup_connector;
 
 	ret = intel_dp_hdcp_init(dig_port, intel_connector);
 	if (ret)
@@ -1776,8 +1773,12 @@  mst_topology_add_connector(struct drm_dp_mst_topology_mgr *mgr,
 
 	return connector;
 
-err:
+err_cleanup_connector:
 	drm_connector_cleanup(connector);
+err_put_port:
+	drm_dp_mst_put_port_malloc(port);
+	intel_connector_free(intel_connector);
+
 	return NULL;
 }