<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:11pt;color:#0078D7;margin:5pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I'm fine with having these changes go through drm-misc.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Alex</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Lipski, Mikita <Mikita.Lipski@amd.com><br>
<b>Sent:</b> Wednesday, April 21, 2021 10:23 AM<br>
<b>To:</b> Lyude Paul <lyude@redhat.com>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; intel-gfx@lists.freedesktop.org <intel-gfx@lists.freedesktop.org>; nouveau@lists.freedesktop.org <nouveau@lists.freedesktop.org>; amd-gfx@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><br>
<b>Cc:</b> Wang, Chao-kai (Stylon) <Stylon.Wang@amd.com>; Lipski, Mikita <Mikita.Lipski@amd.com>; Park, Chris <Chris.Park@amd.com>; Brol, Eryk <Eryk.Brol@amd.com>; Li, Sun peng (Leo) <Sunpeng.Li@amd.com>; Lakha, Bhawanpreet <Bhawanpreet.Lakha@amd.com>; Lin,
 Wayne <Wayne.Lin@amd.com>; Siqueira, Rodrigo <Rodrigo.Siqueira@amd.com>; open list <linux-kernel@vger.kernel.org>; Kazlauskas, Nicholas <Nicholas.Kazlauskas@amd.com>; Somasundaram, Meenakshikumar <Meenakshikumar.Somasundaram@amd.com>; David Airlie <airlied@linux.ie>;
 Pillai, Aurabindo <Aurabindo.Pillai@amd.com>; Daniel Vetter <daniel@ffwll.ch>; Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>; Deucher, Alexander <Alexander.Deucher@amd.com>; Cornij, Nikola <Nikola.Cornij@amd.com>; Wentland, Harry <Harry.Wentland@amd.com>; Koenig,
 Christian <Christian.Koenig@amd.com><br>
<b>Subject:</b> Re: [PATCH v3 01/20] drm/amdgpu: Add error handling to amdgpu_dm_initialize_dp_connector()</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Thanks for the change!<br>
<br>
Reviewed-by: Mikita Lipski <Mikita.Lipski@amd.com><br>
<br>
On 2021-04-19 6:55 p.m., Lyude Paul wrote:<br>
> While working on moving i2c device registration into drm_dp_aux_init() - I<br>
> realized that in order to do so we need to make sure that drivers calling<br>
> drm_dp_aux_init() handle any errors it could possibly return. In the<br>
> process of doing that, I noticed that the majority of AMD's code for DP<br>
> connector creation doesn't attempt to do any real error handling.<br>
> <br>
> So, let's fix this and also cleanup amdgpu_dm_initialize_dp_connector()<br>
> while we're at it. This way we can handle the error codes from<br>
> drm_dp_aux_init().<br>
> <br>
> Signed-off-by: Lyude Paul <lyude@redhat.com><br>
> ---<br>
>   .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 29 +++++++-----<br>
>   .../display/amdgpu_dm/amdgpu_dm_mst_types.c   | 44 +++++++++++--------<br>
>   .../display/amdgpu_dm/amdgpu_dm_mst_types.h   |  6 +--<br>
>   3 files changed, 45 insertions(+), 34 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
> index a0c8c41e4e57..fc5d315bbb05 100644<br>
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
> @@ -7608,10 +7608,9 @@ static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,<br>
>   <br>
>        aconnector->i2c = i2c;<br>
>        res = i2c_add_adapter(&i2c->base);<br>
> -<br>
>        if (res) {<br>
>                DRM_ERROR("Failed to register hw i2c %d\n", link->link_index);<br>
> -             goto out_free;<br>
> +             goto fail_free;<br>
>        }<br>
>   <br>
>        connector_type = to_drm_connector_type(link->connector_signal);<br>
> @@ -7625,8 +7624,7 @@ static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,<br>
>   <br>
>        if (res) {<br>
>                DRM_ERROR("connector_init failed\n");<br>
> -             aconnector->connector_id = -1;<br>
> -             goto out_free;<br>
> +             goto fail_id;<br>
>        }<br>
>   <br>
>        drm_connector_helper_add(<br>
> @@ -7643,15 +7641,22 @@ static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,<br>
>        drm_connector_attach_encoder(<br>
>                &aconnector->base, &aencoder->base);<br>
>   <br>
> -     if (connector_type == DRM_MODE_CONNECTOR_DisplayPort<br>
> -             || connector_type == DRM_MODE_CONNECTOR_eDP)<br>
> -             amdgpu_dm_initialize_dp_connector(dm, aconnector, link->link_index);<br>
> -<br>
> -out_free:<br>
> -     if (res) {<br>
> -             kfree(i2c);<br>
> -             aconnector->i2c = NULL;<br>
> +     if (connector_type == DRM_MODE_CONNECTOR_DisplayPort ||<br>
> +         connector_type == DRM_MODE_CONNECTOR_eDP) {<br>
> +             res = amdgpu_dm_initialize_dp_connector(dm, aconnector, link->link_index);<br>
> +             if (res)<br>
> +                     goto fail_cleanup;<br>
>        }<br>
> +<br>
> +     return 0;<br>
> +fail_cleanup:<br>
> +     drm_connector_cleanup(&aconnector->base);<br>
> +fail_id:<br>
> +     aconnector->connector_id = -1;<br>
> +fail_free:<br>
> +     kfree(i2c);<br>
> +     aconnector->i2c = NULL;<br>
> +<br>
>        return res;<br>
>   }<br>
>   <br>
> 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<br>
> index 73cdb9fe981a..3dee9cce9c9e 100644<br>
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c<br>
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c<br>
> @@ -425,33 +425,39 @@ static const struct drm_dp_mst_topology_cbs dm_mst_cbs = {<br>
>        .add_connector = dm_dp_add_mst_connector,<br>
>   };<br>
>   <br>
> -void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,<br>
> -                                    struct amdgpu_dm_connector *aconnector,<br>
> -                                    int link_index)<br>
> +int amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,<br>
> +                                   struct amdgpu_dm_connector *aconnector,<br>
> +                                   int link_index)<br>
>   {<br>
> -     aconnector->dm_dp_aux.aux.name =<br>
> -             kasprintf(GFP_KERNEL, "AMDGPU DM aux hw bus %d",<br>
> -                       link_index);<br>
> -     aconnector->dm_dp_aux.aux.transfer = dm_dp_aux_transfer;<br>
> -     aconnector->dm_dp_aux.ddc_service = aconnector->dc_link->ddc;<br>
> +     struct amdgpu_dm_dp_aux *dm_aux = &aconnector->dm_dp_aux;<br>
> +     int ret;<br>
>   <br>
> -     drm_dp_aux_init(&aconnector->dm_dp_aux.aux);<br>
> -     drm_dp_cec_register_connector(&aconnector->dm_dp_aux.aux,<br>
> -                                   &aconnector->base);<br>
> +     dm_aux->aux.name = kasprintf(GFP_KERNEL, "AMDGPU DM aux hw bus %d", link_index);<br>
> +     if (!dm_aux->aux.name)<br>
> +             return -ENOMEM;<br>
> +<br>
> +     dm_aux->aux.transfer = dm_dp_aux_transfer;<br>
> +     dm_aux->ddc_service = aconnector->dc_link->ddc;<br>
> +<br>
> +     drm_dp_aux_init(&dm_aux->aux);<br>
> +     drm_dp_cec_register_connector(&dm_aux->aux, &aconnector->base);<br>
>   <br>
>        if (aconnector->base.connector_type == DRM_MODE_CONNECTOR_eDP)<br>
> -             return;<br>
> +             return 0;<br>
>   <br>
>        aconnector->mst_mgr.cbs = &dm_mst_cbs;<br>
> -     drm_dp_mst_topology_mgr_init(<br>
> -             &aconnector->mst_mgr,<br>
> -             adev_to_drm(dm->adev),<br>
> -             &aconnector->dm_dp_aux.aux,<br>
> -             16,<br>
> -             4,<br>
> -             aconnector->connector_id);<br>
> +     ret = drm_dp_mst_topology_mgr_init(&aconnector->mst_mgr, adev_to_drm(dm->adev),<br>
> +                                        &dm_aux->aux, 16, 4, aconnector->connector_id);<br>
> +     if (ret)<br>
> +             goto unreg_cec;<br>
>   <br>
>        drm_connector_attach_dp_subconnector_property(&aconnector->base);<br>
> +<br>
> +     return 0;<br>
> +unreg_cec:<br>
> +     drm_dp_cec_unregister_connector(&dm_aux->aux);<br>
> +     kfree(dm_aux->aux.name);<br>
> +     return ret;<br>
>   }<br>
>   <br>
>   int dm_mst_get_pbn_divider(struct dc_link *link)<br>
> 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<br>
> index b38bd68121ce..cf771ff58bb3 100644<br>
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.h<br>
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.h<br>
> @@ -31,9 +31,9 @@ struct amdgpu_dm_connector;<br>
>   <br>
>   int dm_mst_get_pbn_divider(struct dc_link *link);<br>
>   <br>
> -void amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,<br>
> -                                    struct amdgpu_dm_connector *aconnector,<br>
> -                                    int link_index);<br>
> +int amdgpu_dm_initialize_dp_connector(struct amdgpu_display_manager *dm,<br>
> +                                   struct amdgpu_dm_connector *aconnector,<br>
> +                                   int link_index);<br>
>   <br>
>   void<br>
>   dm_dp_create_fake_mst_encoders(struct amdgpu_device *adev);<br>
> <br>
</div>
</span></font></div>
</div>
</body>
</html>