Right now, the DRM panel logic returns NULL when a panel pointing to
the passed OF node is not present in the list of registered panels.
Most drivers interpret this NULL value as -EPROBE_DEFER, but we are
about to modify the semantic of of_drm_find_panel() and let the
framework return -ENODEV when the device node we're pointing to has
a status property that is not equal to "okay" or "ok".
Let's first patch the of_drm_find_panel() implementation to return
ERR_PTR(-EPROBE_DEFER) instead of NULL and patch all callers to replace
the '!panel' check by an 'IS_ERR(panel)' one.
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180509130042.9435-2-boris.brezillon@bootlin.com
                np = of_node_get(dev->dev.of_node);
 
        panel = of_drm_find_panel(np);
-       if (panel) {
+       if (!IS_ERR(panel)) {
                bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_DSI);
        } else {
                bridge = of_drm_find_bridge(dev->dev.of_node);
 
 
        panel = of_drm_find_panel(panel_node);
        of_node_put(panel_node);
-       if (!panel) {
+       if (IS_ERR(panel)) {
                dev_dbg(&pdev->dev, "panel not found, deferring probe\n");
-               return -EPROBE_DEFER;
+               return PTR_ERR(panel);
        }
 
        lvds_encoder->panel_bridge =
 
 
        if (panel) {
                *panel = of_drm_find_panel(remote);
-               if (*panel)
+               if (!IS_ERR(*panel))
                        ret = 0;
+               else
+                       *panel = NULL;
        }
 
        /* No panel found yet, check for a bridge next. */
 
  * tree node. If a matching panel is found, return a pointer to it.
  *
  * Return: A pointer to the panel registered for the specified device tree
- * node or NULL if no panel matching the device tree node can be found.
+ * node or an ERR_PTR() if no panel matching the device tree node can be found.
+ * The only error that can be reported is -EPROBE_DEFER, meaning that the panel
+ * device has not been probed yet, and the caller should retry later.
  */
 struct drm_panel *of_drm_find_panel(const struct device_node *np)
 {
        }
 
        mutex_unlock(&panel_lock);
-       return NULL;
+       return ERR_PTR(-EPROBE_DEFER);
 }
 EXPORT_SYMBOL(of_drm_find_panel);
 #endif
 
        np = of_parse_phandle(dev->of_node, "panel", 0);
        if (np) {
                dp->plat_data.panel = of_drm_find_panel(np);
+
                of_node_put(np);
-               if (!dp->plat_data.panel)
-                       return -EPROBE_DEFER;
+               if (IS_ERR(dp->plat_data.panel))
+                       return PTR_ERR(dp->plat_data.panel);
+
                goto out;
        }
 
 
 
        if (ctx->panel_node) {
                ctx->panel = of_drm_find_panel(ctx->panel_node);
-               if (!ctx->panel)
-                       return ERR_PTR(-EPROBE_DEFER);
+               if (IS_ERR(ctx->panel))
+                       return ERR_CAST(ctx->panel);
        }
 
        return &ctx->encoder;
 
        dsi->format = device->format;
        dsi->mode_flags = device->mode_flags;
        dsi->panel = of_drm_find_panel(device->dev.of_node);
+       if (IS_ERR(dsi->panel))
+               dsi->panel = NULL;
+
        if (dsi->panel) {
                drm_panel_attach(dsi->panel, &dsi->connector);
                dsi->connector.status = connector_status_connected;
 
        if (panel_node) {
                fsl_dev->connector.panel = of_drm_find_panel(panel_node);
                of_node_put(panel_node);
-               if (!fsl_dev->connector.panel)
-                       return -EPROBE_DEFER;
+               if (IS_ERR(fsl_dev->connector.panel))
+                       return PTR_ERR(fsl_dev->connector.panel);
+
                return fsl_dcu_attach_panel(fsl_dev, fsl_dev->connector.panel);
        }
 
 
        mdp4_write(mdp4_kms, REG_MDP4_LCDC_ENABLE, 0);
 
        panel = of_drm_find_panel(mdp4_lcdc_encoder->panel_node);
-       if (panel) {
+       if (!IS_ERR(panel)) {
                drm_panel_disable(panel);
                drm_panel_unprepare(panel);
        }
                dev_err(dev->dev, "failed to enable lcdc_clk: %d\n", ret);
 
        panel = of_drm_find_panel(mdp4_lcdc_encoder->panel_node);
-       if (panel) {
+       if (!IS_ERR(panel)) {
                drm_panel_prepare(panel);
                drm_panel_enable(panel);
        }
 
        struct mdp4_lvds_connector *mdp4_lvds_connector =
                        to_mdp4_lvds_connector(connector);
 
-       if (!mdp4_lvds_connector->panel)
+       if (!mdp4_lvds_connector->panel) {
                mdp4_lvds_connector->panel =
                        of_drm_find_panel(mdp4_lvds_connector->panel_node);
+               if (IS_ERR(mdp4_lvds_connector->panel))
+                       mdp4_lvds_connector->panel = NULL;
+       }
 
        return mdp4_lvds_connector->panel ?
                        connector_status_connected :
 
                 * output
                 */
                if (check_defer && msm_host->device_node) {
-                       if (!of_drm_find_panel(msm_host->device_node))
+                       if (IS_ERR(of_drm_find_panel(msm_host->device_node)))
                                if (!of_drm_find_bridge(msm_host->device_node))
                                        return -EPROBE_DEFER;
                }
 
                        ret = -EPROBE_DEFER;
        } else {
                lvds->panel = of_drm_find_panel(remote);
-               if (!lvds->panel)
-                       ret = -EPROBE_DEFER;
+               if (IS_ERR(lvds->panel))
+                       ret = PTR_ERR(lvds->panel);
        }
 
 done:
 
        dsi->format = device->format;
        dsi->mode_flags = device->mode_flags;
        dsi->panel = of_drm_find_panel(device->dev.of_node);
-       if (dsi->panel)
+       if (!IS_ERR(dsi->panel))
                return drm_panel_attach(dsi->panel, &dsi->connector);
 
        return -EINVAL;
 
 
        if (!dvo->panel) {
                dvo->panel = of_drm_find_panel(dvo->panel_node);
-               if (dvo->panel)
+               if (IS_ERR(dvo->panel))
+                       dvo->panel = NULL;
+               else
                        drm_panel_attach(dvo->panel, connector);
        }
 
 
 
        dsi->device = device;
        dsi->panel = of_drm_find_panel(device->dev.of_node);
-       if (!dsi->panel)
-               return -EINVAL;
+       if (IS_ERR(dsi->panel))
+               return PTR_ERR(dsi->panel);
 
        dev_info(host->dev, "Attached device %s\n", device->name);
 
 
                struct tegra_output *output = &dsi->output;
 
                output->panel = of_drm_find_panel(device->dev.of_node);
+               if (IS_ERR(output->panel))
+                       output->panel = NULL;
+
                if (output->panel && output->connector.dev) {
                        drm_panel_attach(output->panel, &output->connector);
                        drm_helper_hpd_irq_event(output->connector.dev);
 
        panel = of_parse_phandle(output->of_node, "nvidia,panel", 0);
        if (panel) {
                output->panel = of_drm_find_panel(panel);
-               if (!output->panel)
-                       return -EPROBE_DEFER;
+               if (IS_ERR(output->panel))
+                       return PTR_ERR(output->panel);
 
                of_node_put(panel);
        }
 
 #else
 static inline struct drm_panel *of_drm_find_panel(const struct device_node *np)
 {
-       return NULL;
+       return ERR_PTR(-ENODEV);
 }
 #endif