Re: [PATCH v3 01/20] drm/amdgpu: Add error handling to amdgpu_dm_initialize_dp_connector()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the change!

Reviewed-by: Mikita Lipski <Mikita.Lipski@xxxxxxx>

On 2021-04-19 6:55 p.m., Lyude Paul wrote:
While working on moving i2c device registration into drm_dp_aux_init() - I
realized that in order to do so we need to make sure that drivers calling
drm_dp_aux_init() handle any errors it could possibly return. In the
process of doing that, I noticed that the majority of AMD's code for DP
connector creation doesn't attempt to do any real error handling.

So, let's fix this and also cleanup amdgpu_dm_initialize_dp_connector()
while we're at it. This way we can handle the error codes from
drm_dp_aux_init().

Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
---
  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 29 +++++++-----
  .../display/amdgpu_dm/amdgpu_dm_mst_types.c   | 44 +++++++++++--------
  .../display/amdgpu_dm/amdgpu_dm_mst_types.h   |  6 +--
  3 files changed, 45 insertions(+), 34 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index a0c8c41e4e57..fc5d315bbb05 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -7608,10 +7608,9 @@ static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
aconnector->i2c = i2c;
  	res = i2c_add_adapter(&i2c->base);
-
  	if (res) {
  		DRM_ERROR("Failed to register hw i2c %d\n", link->link_index);
-		goto out_free;
+		goto fail_free;
  	}
connector_type = to_drm_connector_type(link->connector_signal);
@@ -7625,8 +7624,7 @@ static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
if (res) {
  		DRM_ERROR("connector_init failed\n");
-		aconnector->connector_id = -1;
-		goto out_free;
+		goto fail_id;
  	}
drm_connector_helper_add(
@@ -7643,15 +7641,22 @@ static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
  	drm_connector_attach_encoder(
  		&aconnector->base, &aencoder->base);
- if (connector_type == DRM_MODE_CONNECTOR_DisplayPort
-		|| connector_type == DRM_MODE_CONNECTOR_eDP)
-		amdgpu_dm_initialize_dp_connector(dm, aconnector, link->link_index);
-
-out_free:
-	if (res) {
-		kfree(i2c);
-		aconnector->i2c = NULL;
+	if (connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
+	    connector_type == DRM_MODE_CONNECTOR_eDP) {
+		res = amdgpu_dm_initialize_dp_connector(dm, aconnector, link->link_index);
+		if (res)
+			goto fail_cleanup;
  	}
+
+	return 0;
+fail_cleanup:
+	drm_connector_cleanup(&aconnector->base);
+fail_id:
+	aconnector->connector_id = -1;
+fail_free:
+	kfree(i2c);
+	aconnector->i2c = NULL;
+
  	return res;
  }
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index 73cdb9fe981a..3dee9cce9c9e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -425,33 +425,39 @@ static const struct drm_dp_mst_topology_cbs dm_mst_cbs = {
  	.add_connector = dm_dp_add_mst_connector,
  };
-void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,
-				       struct amdgpu_dm_connector *aconnector,
-				       int link_index)
+int amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,
+				      struct amdgpu_dm_connector *aconnector,
+				      int link_index)
  {
-	aconnector->dm_dp_aux.aux.name =
-		kasprintf(GFP_KERNEL, "AMDGPU DM aux hw bus %d",
-			  link_index);
-	aconnector->dm_dp_aux.aux.transfer = dm_dp_aux_transfer;
-	aconnector->dm_dp_aux.ddc_service = aconnector->dc_link->ddc;
+	struct amdgpu_dm_dp_aux *dm_aux = &aconnector->dm_dp_aux;
+	int ret;
- drm_dp_aux_init(&aconnector->dm_dp_aux.aux);
-	drm_dp_cec_register_connector(&aconnector->dm_dp_aux.aux,
-				      &aconnector->base);
+	dm_aux->aux.name = kasprintf(GFP_KERNEL, "AMDGPU DM aux hw bus %d", link_index);
+	if (!dm_aux->aux.name)
+		return -ENOMEM;
+
+	dm_aux->aux.transfer = dm_dp_aux_transfer;
+	dm_aux->ddc_service = aconnector->dc_link->ddc;
+
+	drm_dp_aux_init(&dm_aux->aux);
+	drm_dp_cec_register_connector(&dm_aux->aux, &aconnector->base);
if (aconnector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
-		return;
+		return 0;
aconnector->mst_mgr.cbs = &dm_mst_cbs;
-	drm_dp_mst_topology_mgr_init(
-		&aconnector->mst_mgr,
-		adev_to_drm(dm->adev),
-		&aconnector->dm_dp_aux.aux,
-		16,
-		4,
-		aconnector->connector_id);
+	ret = drm_dp_mst_topology_mgr_init(&aconnector->mst_mgr, adev_to_drm(dm->adev),
+					   &dm_aux->aux, 16, 4, aconnector->connector_id);
+	if (ret)
+		goto unreg_cec;
drm_connector_attach_dp_subconnector_property(&aconnector->base);
+
+	return 0;
+unreg_cec:
+	drm_dp_cec_unregister_connector(&dm_aux->aux);
+	kfree(dm_aux->aux.name);
+	return ret;
  }
int dm_mst_get_pbn_divider(struct dc_link *link)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.h
index b38bd68121ce..cf771ff58bb3 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.h
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.h
@@ -31,9 +31,9 @@ struct amdgpu_dm_connector;
int dm_mst_get_pbn_divider(struct dc_link *link); -void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,
-				       struct amdgpu_dm_connector *aconnector,
-				       int link_index);
+int amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,
+				      struct amdgpu_dm_connector *aconnector,
+				      int link_index);
void
  dm_dp_create_fake_mst_encoders(struct amdgpu_device *adev);

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel



[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux