AMD-GFX Archive on lore.kernel.org
 help / color / Atom feed
From: Lyude Paul <lyude@redhat.com>
To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	nouveau@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Thierry Reding" <thierry.reding@gmail.com>
Cc: "Stylon Wang" <stylon.wang@amd.com>,
	"Mikita Lipski" <mikita.lipski@amd.com>,
	"Chris Park" <Chris.Park@amd.com>,
	"Eryk Brol" <eryk.brol@amd.com>, "Leo Li" <sunpeng.li@amd.com>,
	"Bhawanpreet Lakha" <Bhawanpreet.Lakha@amd.com>,
	"Wayne Lin" <Wayne.Lin@amd.com>,
	"Rodrigo Siqueira" <Rodrigo.Siqueira@amd.com>,
	"open list" <linux-kernel@vger.kernel.org>,
	"Nicholas Kazlauskas" <nicholas.kazlauskas@amd.com>,
	"Meenakshikumar Somasundaram"
	<meenakshikumar.somasundaram@amd.com>,
	"David Airlie" <airlied@linux.ie>,
	"Aurabindo Pillai" <aurabindo.pillai@amd.com>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Bas Nieuwenhuizen" <bas@basnieuwenhuizen.nl>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Nikola Cornij" <nikola.cornij@amd.com>,
	"Harry Wentland" <harry.wentland@amd.com>,
	"Christian König" <christian.koenig@amd.com>
Subject: [PATCH v3 01/20] drm/amdgpu: Add error handling to amdgpu_dm_initialize_dp_connector()
Date: Mon, 19 Apr 2021 18:55:03 -0400
Message-ID: <20210419225523.184856-2-lyude@redhat.com> (raw)
In-Reply-To: <20210419225523.184856-1-lyude@redhat.com>

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@redhat.com>
---
 .../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);
-- 
2.30.2

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  reply index

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 22:55 [PATCH v3 00/20] drm: Use new DRM printk funcs (like drm_dbg_*()) in DP helpers Lyude Paul
2021-04-19 22:55 ` Lyude Paul [this message]
2021-04-21 14:23   ` [PATCH v3 01/20] drm/amdgpu: Add error handling to amdgpu_dm_initialize_dp_connector() Mikita Lipski
2021-04-21 15:22     ` Deucher, Alexander
2021-04-19 22:55 ` [PATCH v3 02/20] drm/dp: Add __no_check to drm_dp_aux_register() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 03/20] drm/dp: Move i2c init to drm_dp_aux_init, add __must_check and fini Lyude Paul
2021-04-19 23:16   ` Ville Syrjälä
2021-04-22 17:18     ` Lyude Paul
2021-04-22 22:33       ` Lyude Paul
2021-04-23  4:11         ` Lyude Paul
2021-04-23 12:39           ` Thierry Reding
2021-04-23 17:53             ` Lyude Paul
2021-04-23 12:38         ` Thierry Reding
2021-04-23 12:34       ` Thierry Reding
2021-04-19 22:55 ` [PATCH v3 04/20] drm/bridge/cdns-mhdp8546: Register DP aux channel with userspace Lyude Paul
2021-04-19 22:55 ` [PATCH v3 05/20] drm/nouveau/kms/nv50-: Move AUX adapter reg to connector late register/early unregister Lyude Paul
2021-04-19 22:55 ` [PATCH v3 06/20] drm/dp: Add backpointer to drm_device in drm_dp_aux Lyude Paul
2021-04-19 22:55 ` [PATCH v3 07/20] drm/dp: Clarify DP AUX registration time Lyude Paul
2021-04-19 22:55 ` [PATCH v3 08/20] drm/dp: Pass drm_dp_aux to drm_dp_link_train_clock_recovery_delay() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 09/20] drm/dp: Pass drm_dp_aux to drm_dp*_link_train_channel_eq_delay() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 10/20] drm/dp: Always print aux channel name in logs Lyude Paul
2021-04-19 22:55 ` [PATCH v3 11/20] drm/dp_dual_mode: Pass drm_device to drm_dp_dual_mode_detect() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 12/20] drm/dp_dual_mode: Pass drm_device to drm_dp_dual_mode_set_tmds_output() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 13/20] drm/dp_dual_mode: Pass drm_device to drm_dp_dual_mode_max_tmds_clock() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 14/20] drm/dp_dual_mode: Pass drm_device to drm_dp_dual_mode_get_tmds_output() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 15/20] drm/dp_dual_mode: Pass drm_device to drm_lspcon_(get|set)_mode() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 16/20] drm/dp_mst: Pass drm_dp_mst_topology_mgr to drm_dp_get_vc_payload_bw() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 17/20] drm/print: Handle potentially NULL drm_devices in drm_dbg_* Lyude Paul
2021-04-19 22:55 ` [PATCH v3 18/20] drm/dp: Convert drm_dp_helper.c to using drm_err/drm_dbg_*() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 19/20] drm/dp_dual_mode: Convert drm_dp_dual_mode_helper.c to using drm_err/drm_dbg_kms() Lyude Paul
2021-04-19 22:55 ` [PATCH v3 20/20] drm/dp_mst: Convert drm_dp_mst_topology.c to drm_err()/drm_dbg*() Lyude Paul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210419225523.184856-2-lyude@redhat.com \
    --to=lyude@redhat.com \
    --cc=Bhawanpreet.Lakha@amd.com \
    --cc=Chris.Park@amd.com \
    --cc=Rodrigo.Siqueira@amd.com \
    --cc=Wayne.Lin@amd.com \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=aurabindo.pillai@amd.com \
    --cc=bas@basnieuwenhuizen.nl \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eryk.brol@amd.com \
    --cc=harry.wentland@amd.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=meenakshikumar.somasundaram@amd.com \
    --cc=mikita.lipski@amd.com \
    --cc=nicholas.kazlauskas@amd.com \
    --cc=nikola.cornij@amd.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=stylon.wang@amd.com \
    --cc=sunpeng.li@amd.com \
    --cc=thierry.reding@gmail.com \
    --cc=tzimmermann@suse.de \
    --cc=ville.syrjala@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

AMD-GFX Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/amd-gfx/0 amd-gfx/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 amd-gfx amd-gfx/ https://lore.kernel.org/amd-gfx \
		amd-gfx@lists.freedesktop.org
	public-inbox-index amd-gfx

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.freedesktop.lists.amd-gfx


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git