This is the new API for allocating DRM bridges.

Switching from a non-devm to a devm allocation allows removing the kfree()
in the remove function and in the probe error management code, and as a
consequence to simplify the code flow by removing now unnecessary gotos.

Signed-off-by: Luca Ceresoli <luca.ceres...@bootlin.com>

---

Cc: "Rob Herring (Arm)" <r...@kernel.org>
Cc: Kuninori Morimoto <kuninori.morimoto...@renesas.com>
Cc: Tomi Valkeinen <tomi.valkei...@ideasonboard.com>
---
 drivers/gpu/drm/omapdrm/dss/sdi.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/sdi.c 
b/drivers/gpu/drm/omapdrm/dss/sdi.c
index 
e78826e4b560a2b9af2d8a5a38e181bd3e44d250..df4cbc683e2ca27ef5fc45f79b77dcdcd9ca529a
 100644
--- a/drivers/gpu/drm/omapdrm/dss/sdi.c
+++ b/drivers/gpu/drm/omapdrm/dss/sdi.c
@@ -284,7 +284,6 @@ static const struct drm_bridge_funcs sdi_bridge_funcs = {
 
 static void sdi_bridge_init(struct sdi_device *sdi)
 {
-       sdi->bridge.funcs = &sdi_bridge_funcs;
        sdi->bridge.of_node = sdi->pdev->dev.of_node;
        sdi->bridge.type = DRM_MODE_CONNECTOR_LVDS;
 
@@ -344,21 +343,19 @@ int sdi_init_port(struct dss_device *dss, struct 
platform_device *pdev,
        u32 datapairs;
        int r;
 
-       sdi = kzalloc(sizeof(*sdi), GFP_KERNEL);
-       if (!sdi)
-               return -ENOMEM;
+       sdi = devm_drm_bridge_alloc(&pdev->dev, struct sdi_device, bridge, 
&sdi_bridge_funcs);
+       if (IS_ERR(sdi))
+               return PTR_ERR(sdi);
 
        ep = of_graph_get_next_port_endpoint(port, NULL);
-       if (!ep) {
-               r = 0;
-               goto err_free;
-       }
+       if (!ep)
+               return 0;
 
        r = of_property_read_u32(ep, "datapairs", &datapairs);
        of_node_put(ep);
        if (r) {
                DSSERR("failed to parse datapairs\n");
-               goto err_free;
+               return r;
        }
 
        sdi->datapairs = datapairs;
@@ -372,19 +369,14 @@ int sdi_init_port(struct dss_device *dss, struct 
platform_device *pdev,
                r = PTR_ERR(sdi->vdds_sdi_reg);
                if (r != -EPROBE_DEFER)
                        DSSERR("can't get VDDS_SDI regulator\n");
-               goto err_free;
+               return r;
        }
 
        r = sdi_init_output(sdi);
        if (r)
-               goto err_free;
+               return r;
 
        return 0;
-
-err_free:
-       kfree(sdi);
-
-       return r;
 }
 
 void sdi_uninit_port(struct device_node *port)
@@ -395,5 +387,4 @@ void sdi_uninit_port(struct device_node *port)
                return;
 
        sdi_uninit_output(sdi);
-       kfree(sdi);
 }

-- 
2.49.0

Reply via email to