@@ -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);
@@ -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;
@@ -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);
This patch add checks for NULL drm_connector_helper_funcs pointers before derefrencing the variable to avoid NULL pointer dereference and make the helper function 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 for atomic_check 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_mode_config_func: * atomic_check = drm_atomic_helper_check a) drm_atomic_helper_check_modeset a) handle_conflicting_encoders c) update_connector_routing Signed-off-by: Haneen Mohammed <hamohammed.sa@gmail.com> --- Changes in v3: - add checks for drm_connector_helper_funcs only since plane/crtc helper funcs are necessary for a functional driver Changes in v2: - add the least amount of checks to make the helpers optional for vkms drivers/gpu/drm/drm_atomic_helper.c | 10 +++++----- drivers/gpu/drm/drm_probe_helper.c | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-)