diff --git a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c index 0d45fb2226dd..2c68c47cffda 100644 --- a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c +++ b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -552,13 +553,14 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master, if (!drv_data) return -ENODEV; - hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); + hdmi = drmm_kzalloc(drm, sizeof(*hdmi), GFP_KERNEL); if (!hdmi) return -ENOMEM; - plat_data = devm_kmemdup(dev, drv_data, sizeof(*drv_data), GFP_KERNEL); + plat_data = drmm_kzalloc(drm, sizeof(*drv_data), GFP_KERNEL); if (!plat_data) return -ENOMEM; + memcpy(plat_data, drv_data, sizeof(*drv_data)); hdmi->dev = dev; hdmi->plat_data = plat_data; @@ -610,28 +612,20 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master, FIELD_PREP_WM16(RK3568_HDMI_SCLIN_MSK, 1)); } + ret = drmm_encoder_init(drm, encoder, NULL, DRM_MODE_ENCODER_TMDS, NULL); + if (ret) + return dev_err_probe(dev, ret, "failed to init encoder\n"); + drm_encoder_helper_add(encoder, &dw_hdmi_rockchip_encoder_helper_funcs); - drm_simple_encoder_init(drm, encoder, DRM_MODE_ENCODER_TMDS); platform_set_drvdata(pdev, hdmi); hdmi->hdmi = dw_hdmi_bind(pdev, encoder, plat_data); - - /* - * If dw_hdmi_bind() fails we'll never call dw_hdmi_unbind(), - * which would have called the encoder cleanup. Do it manually. - */ - if (IS_ERR(hdmi->hdmi)) { - ret = PTR_ERR(hdmi->hdmi); - goto err_bind; - } + if (IS_ERR(hdmi->hdmi)) + return dev_err_probe(dev, PTR_ERR(hdmi->hdmi), + "failed to probe dw-hdmi bridge\n"); return 0; - -err_bind: - drm_encoder_cleanup(encoder); - - return ret; } static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master, @@ -640,7 +634,6 @@ static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master, struct rockchip_hdmi *hdmi = dev_get_drvdata(dev); dw_hdmi_unbind(hdmi->hdmi); - drm_encoder_cleanup(&hdmi->encoder.encoder); } static const struct component_ops dw_hdmi_rockchip_ops = {