On Thu, Apr 3, 2025 at 7:09 PM AngeloGioacchino Del Regno <angelogioacchino.delre...@collabora.com> wrote: > > During probe, this driver is registering two platform devices: one > for the HDMI Codec driver and one for the DisplayPort PHY driver. > > In the probe function, none of the error cases are unregistering > any of the two platform devices and this may cause registration > of multiple instances of those in case this driver returns one or > more probe deferral(s) in the "wrong" spots. > > In order to fix this, add devm actions to unregister those and > remove the manual calls to platform_device_unregister in the > mtk_dp_remove() function, as those would otherwise be redundant. > > Fixes: e71a8ebbe086 ("drm/mediatek: dp: Audio support for MT8195") > Fixes: caf2ae486742 ("drm/mediatek: dp: Add support for embedded DisplayPort > aux-bus") > Signed-off-by: AngeloGioacchino Del Regno > <angelogioacchino.delre...@collabora.com> > --- > drivers/gpu/drm/mediatek/mtk_dp.c | 30 ++++++++++++++++++++++++++---- > 1 file changed, 26 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c > b/drivers/gpu/drm/mediatek/mtk_dp.c > index 3d4648d2e15f..3eb685a46d99 100644 > --- a/drivers/gpu/drm/mediatek/mtk_dp.c > +++ b/drivers/gpu/drm/mediatek/mtk_dp.c > @@ -2648,6 +2648,13 @@ static const struct hdmi_codec_ops > mtk_dp_audio_codec_ops = { > .hook_plugged_cb = mtk_dp_audio_hook_plugged_cb, > }; > > +static void mtk_dp_unregister_pdevs(void *data) > +{ > + struct platform_device *ext_pdev = data; > + > + platform_device_unregister(ext_pdev); > +} > + > static int mtk_dp_register_audio_driver(struct device *dev) > { > struct mtk_dp *mtk_dp = dev_get_drvdata(dev); > @@ -2658,18 +2665,29 @@ static int mtk_dp_register_audio_driver(struct device > *dev) > .data = mtk_dp, > .no_capture_mute = 1, > }; > + int ret; > > mtk_dp->audio_pdev = platform_device_register_data(dev, > > HDMI_CODEC_DRV_NAME, > > PLATFORM_DEVID_AUTO, > &codec_data, > > sizeof(codec_data)); > - return PTR_ERR_OR_ZERO(mtk_dp->audio_pdev); > + if (IS_ERR(mtk_dp->audio_pdev)) > + return PTR_ERR(mtk_dp->audio_pdev); > + > + ret = devm_add_action_or_reset(dev, mtk_dp_unregister_pdevs, > mtk_dp->phy_dev);
Wrong platform device given here. You want audio_pdev instead. Having briefly looked at this driver, I think it needs more cleanup. :o ChenYu > + if (ret) { > + platform_device_unregister(mtk_dp->audio_pdev); > + return dev_err_probe(dev, ret, > + "Failed to add codec unregister devm > action"); > + } > + return 0; > } > > static int mtk_dp_register_phy(struct mtk_dp *mtk_dp) > { > struct device *dev = mtk_dp->dev; > + int ret; > > mtk_dp->phy_dev = platform_device_register_data(dev, > "mediatek-dp-phy", > PLATFORM_DEVID_AUTO, > @@ -2679,6 +2697,13 @@ static int mtk_dp_register_phy(struct mtk_dp *mtk_dp) > return dev_err_probe(dev, PTR_ERR(mtk_dp->phy_dev), > "Failed to create device > mediatek-dp-phy\n"); > > + ret = devm_add_action_or_reset(dev, mtk_dp_unregister_pdevs, > mtk_dp->phy_dev); > + if (ret) { > + platform_device_unregister(mtk_dp->phy_dev); > + return dev_err_probe(dev, ret, > + "Failed to add phy unregister devm > action"); > + } > + > mtk_dp_get_calibration_data(mtk_dp); > > mtk_dp->phy = devm_phy_get(&mtk_dp->phy_dev->dev, "dp"); > @@ -2848,9 +2873,6 @@ static void mtk_dp_remove(struct platform_device *pdev) > pm_runtime_disable(&pdev->dev); > if (mtk_dp->data->bridge_type != DRM_MODE_CONNECTOR_eDP) > del_timer_sync(&mtk_dp->debounce_timer); > - platform_device_unregister(mtk_dp->phy_dev); > - if (mtk_dp->audio_pdev) > - platform_device_unregister(mtk_dp->audio_pdev); > } > > #ifdef CONFIG_PM_SLEEP > -- > 2.48.1 >