Change to use drmres helpers drmm_kzalloc() to allocate driver data
and drmm_encoder_init() to initialize the encoder. With use of drmres
the manual encoder cleanup in failure path and unbind is also removed.

Signed-off-by: Jonas Karlman <[email protected]>
---
 drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c | 29 ++++++++-------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c 
b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
index 435352f91b88..982d0829f278 100644
--- a/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
+++ b/drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c
@@ -14,6 +14,7 @@
 
 #include <drm/bridge/dw_hdmi.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_of.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
@@ -550,13 +551,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;
@@ -608,28 +610,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 bind encoder\n");
 
        return 0;
-
-err_bind:
-       drm_encoder_cleanup(encoder);
-
-       return ret;
 }
 
 static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master,
@@ -638,7 +632,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 = {
-- 
2.54.0

Reply via email to