Commit 8dd4e8c4 authored by Maxime Ripard's avatar Maxime Ripard

drm/bridge: panel: Prevent ERR_PTR Dereference

Commit 5ea6b170 ("drm/panel: Add prepare_prev_first flag to
drm_panel") introduced an access to the bridge pointer in the
devm_drm_panel_bridge_add_typed() function.

However, due to the unusual ERR_PTR check when getting that pointer, the
pointer access is done even though the pointer might be an error
pointer.

Rework the function for a more traditional design that will return
immediately if it gets an ERR_PTR so that we never access the pointer in
that case.

Fixes: 5ea6b170 ("drm/panel: Add prepare_prev_first flag to drm_panel")
Reported-by: default avatarkernel test robot <lkp@intel.com>
Reported-by: default avatarDan Carpenter <error27@gmail.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: default avatarAndrzej Hajda <andrzej.hajda@intel.com>
Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
Link: https://patchwork.freedesktop.org/patch/msgid/20230102120123.19062-1-maxime@cerno.tech
Link: https://patchwork.freedesktop.org/patch/msgid/20230102120123.19062-1-maxime@cerno.tech
parent 51342cc0
...@@ -357,15 +357,16 @@ struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, ...@@ -357,15 +357,16 @@ struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
bridge = drm_panel_bridge_add_typed(panel, connector_type); bridge = drm_panel_bridge_add_typed(panel, connector_type);
if (!IS_ERR(bridge)) { if (IS_ERR(bridge)) {
*ptr = bridge;
devres_add(dev, ptr);
} else {
devres_free(ptr); devres_free(ptr);
return bridge;
} }
bridge->pre_enable_prev_first = panel->prepare_prev_first; bridge->pre_enable_prev_first = panel->prepare_prev_first;
*ptr = bridge;
devres_add(dev, ptr);
return bridge; return bridge;
} }
EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed); EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment