drm: Add checks for NULL drm_*_helper_funcs
Subsystems (2)
PATCH v2 1/1 drm: Add checks for NULL drm_*_helper_funcs
This patch add checks for NULL drm_[connector/crtc/plane]_helper_funcs pointers before derefrencing the variable to avoid NULL pointer dereference and make the helper functions optional in the following cases:
1) when using drm_helper_probe_single_connector_modes for fill_modes callback in the drm_connector_funcs.
2) using drm_atomic_helper_[check/commit] for atomic_[check/commit] callbacks in the drm_mode_config_funcs.
The dependency is as follow:
drm_connector_funcs:
* fill_modes = drm_helper_probe_single_connector_modes
b) drm_helper_probe_detect -> drm_connector_helper_funcs
drm_mode_config_funcs:
* atomic_check = drm_atomic_helper_check
a) drm_atomic_helper_check_modeset -> drm_connector helper_funcs a) handle_conflicting_encoders -> drm_connector_helper_funcs b) mode_fixup -> drm_crtc_helper_funcs c) update_connector_routing -> drm_connectot_helper_funcs
* atomic_commit = drm_atomic_helper_commit
a) drm_atomic_helper_prepare_planes -> drm_plane_helper_funcs b) drm_atomic_helper_cleanup_planes -> drm_plane_helper_funcs
---
Chanes in v2:
- add the least amount of checks to make the helpers optional for vkms
drivers/gpu/drm/drm_atomic_helper.c | 16 ++++++++-------- drivers/gpu/drm/drm_probe_helper.c | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +8 -8
@@ -112,9 +112,9 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,if (!new_conn_state->crtc)continue ; -if (funcs->atomic_best_encoder) +if (funcs && funcs->atomic_best_encoder) new_encoder = funcs->atomic_best_encoder (connector, new_conn_state); -else if (funcs->best_encoder) +else if (funcs && funcs->best_encoder) new_encoder = funcs->best_encoder (connector);else new_encoder =drm_atomic_helper_best_encoder (connector);
@@ -308,10 +308,10 @@ update_connector_routing(struct drm_atomic_state *state, funcs = connector->helper_private; -if (funcs->atomic_best_encoder) +if (funcs && funcs->atomic_best_encoder) new_encoder = funcs->atomic_best_encoder (connector, new_connector_state); -else if (funcs->best_encoder) +else if (funcs && funcs->best_encoder) new_encoder = funcs->best_encoder (connector);else new_encoder =drm_atomic_helper_best_encoder (connector);
@@ -438,7 +438,7 @@ mode_fixup(struct drm_atomic_state *state)continue ; funcs = crtc->helper_private; -if (!funcs->mode_fixup) +if (!funcs || !funcs->mode_fixup)continue ; ret = funcs->mode_fixup(crtc, &new_crtc_state->mode,
@@ -639,7 +639,7 @@ drm_atomic_helper_check_modeset(struct drm_device *dev, new_crtc_state->connectors_changed = true; } -if (funcs->atomic_check) +if (funcs && funcs->atomic_check) ret = funcs->atomic_check (connector, new_connector_state);if (ret)return ret;
@@ -2117,7 +2117,7 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev, funcs = plane->helper_private; -if (funcs->prepare_fb) { +if (funcs && funcs->prepare_fb) { ret = funcs->prepare_fb (plane, new_plane_state);if (ret) goto fail;
@@ -2412,7 +2412,7 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev, funcs = plane->helper_private; -if (funcs->cleanup_fb) +if (funcs && funcs->cleanup_fb) funcs->cleanup_fb (plane, plane_state); } }
drivers/gpu/drm/drm_probe_helper.c +3 -2
@@ -320,7 +320,7 @@ drm_helper_probe_detect(struct drm_connector *connector,if (ret)return ret; -if (funcs->detect_ctx) +if (funcs && funcs->detect_ctx)return funcs->detect_ctx (connector, ctx, force);else if (connector->funcs->detect)return connector->funcs->detect (connector, force);
@@ -480,7 +480,8 @@ int drm_helper_probe_single_connector_modes(struct drm_connector *connector, goto prune; } - count = (*connector_funcs->get_modes)(connector); +if (connector_funcs && connector_funcs->get_modes) + count = (*connector_funcs->get_modes)(connector);if (count ==0 && connector->status == connector_status_connected) count =drm_add_modes_noedid (connector,1024 ,768 );
Signature · 6 lines
2.17.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 23 lines · Haneen Mohammed
This patch add checks for NULL drm_[connector/crtc/plane]_helper_funcs pointers before derefrencing the variable to avoid NULL pointer dereference and make the helper functions optional in the following cases:
1) when using
drm_helper_probe_single_connector_modesforfill_modescallback in thedrm_connector_funcs.
2) using drm_atomic_helper_[check/commit] for atomic_[check/commit] callbacks in thedrm_mode_config_funcs.The dependency is as follow:
drm_connector_funcs:
*fill_modes=drm_helper_probe_single_connector_modesb) drm_helper_probe_detect -> drm_connector_helper_funcs
drm_mode_config_funcs:
*atomic_check=drm_atomic_helper_checka) drm_atomic_helper_check_modeset -> drm_connector helper_funcs a) handle_conflicting_encoders -> drm_connector_helper_funcs b) mode_fixup -> drm_crtc_helper_funcs c) update_connector_routing -> drm_connectot_helper_funcs
Quoted 5 lines
*
atomic_commit=drm_atomic_helper_commita) drm_atomic_helper_prepare_planes -> drm_plane_helper_funcs b) drm_atomic_helper_cleanup_planes -> drm_plane_helper_funcsSigned-off-by Haneen Mohammed <[email protected]>
Ok, I think making drm_connector_helper_funcs optional makes some sense - ->best_connector has a default implemenation that works for almost everyone, and if you don't have a way to detect the output it's silly to have a default implementation that does nothing.
But making the plane/crtc funcs optional gives you a driver which does exactly nothing, and that's not terribly useful.
I think respinning this to just make drm_connector_helper_funcs optional is reasonable, and for all others we need to start making vkms functional :-)
Cheers, Daniel
Quoted 99 lines
---
Chanes in v2:
- add the least amount of checks to make the helpers optional for vkmsdrivers/gpu/drm/drm_atomic_helper.c | 16 ++++++++-------- drivers/gpu/drm/drm_probe_helper.c | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-)drivers/gpu/drm/drm_atomic_helper.c +8
-8@@ -112,9 +112,9 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,if (!new_conn_state->crtc)continue ; -if (funcs->atomic_best_encoder) +if (funcs && funcs->atomic_best_encoder) new_encoder = funcs->atomic_best_encoder (connector, new_conn_state); -else if (funcs->best_encoder) +else if (funcs && funcs->best_encoder) new_encoder = funcs->best_encoder (connector);else new_encoder =drm_atomic_helper_best_encoder (connector);@@ -308,10 +308,10 @@ update_connector_routing(struct drm_atomic_state *state, funcs = connector->helper_private; -if (funcs->atomic_best_encoder) +if (funcs && funcs->atomic_best_encoder) new_encoder = funcs->atomic_best_encoder (connector, new_connector_state); -else if (funcs->best_encoder) +else if (funcs && funcs->best_encoder) new_encoder = funcs->best_encoder (connector);else new_encoder =drm_atomic_helper_best_encoder (connector);@@ -438,7 +438,7 @@ mode_fixup(struct drm_atomic_state *state)continue ; funcs = crtc->helper_private; -if (!funcs->mode_fixup) +if (!funcs || !funcs->mode_fixup)continue ; ret = funcs->mode_fixup(crtc, &new_crtc_state->mode,@@ -639,7 +639,7 @@ drm_atomic_helper_check_modeset(struct drm_device *dev, new_crtc_state->connectors_changed = true; } -if (funcs->atomic_check) +if (funcs && funcs->atomic_check) ret = funcs->atomic_check (connector, new_connector_state);if (ret)return ret;@@ -2117,7 +2117,7 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev, funcs = plane->helper_private; -if (funcs->prepare_fb) { +if (funcs && funcs->prepare_fb) { ret = funcs->prepare_fb (plane, new_plane_state);if (ret) goto fail;@@ -2412,7 +2412,7 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev, funcs = plane->helper_private; -if (funcs->cleanup_fb) +if (funcs && funcs->cleanup_fb) funcs->cleanup_fb (plane, plane_state); } }drivers/gpu/drm/drm_probe_helper.c +3
-2@@ -320,7 +320,7 @@ drm_helper_probe_detect(struct drm_connector *connector,if (ret)return ret; -if (funcs->detect_ctx) +if (funcs && funcs->detect_ctx)return funcs->detect_ctx (connector, ctx, force);else if (connector->funcs->detect)return connector->funcs->detect (connector, force);@@ -480,7 +480,8 @@ int drm_helper_probe_single_connector_modes(struct drm_connector *connector, goto prune; } - count = (*connector_funcs->get_modes)(connector); +if (connector_funcs && connector_funcs->get_modes) + count = (*connector_funcs->get_modes)(connector);if (count ==0 && connector->status == connector_status_connected) count =drm_add_modes_noedid (connector,1024 ,768 );Signature · 1 line
2.17.0
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel