dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Haneen Mohammed <hamohammed.sa@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>,
	David Airlie <airlied@linux.ie>,
	Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH v2] drm: Add checks for NULL drm_*_helper_funcs
Date: Wed, 30 May 2018 03:42:59 +0300	[thread overview]
Message-ID: <20180530004259.GA7981@haneen-vb> (raw)

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

Signed-off-by: Haneen Mohammed <hamohammed.sa@gmail.com>
---
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(-)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 2a7ceca82b9e..ff3684c4a83c 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -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);
 	}
 }
diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c
index 527743394150..2fea54d16ebb 100644
--- a/drivers/gpu/drm/drm_probe_helper.c
+++ b/drivers/gpu/drm/drm_probe_helper.c
@@ -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);
-- 
2.17.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

             reply	other threads:[~2018-05-30  0:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-30  0:42 Haneen Mohammed [this message]
2018-05-31  8:01 ` [PATCH v2] drm: Add checks for NULL drm_*_helper_funcs Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180530004259.GA7981@haneen-vb \
    --to=hamohammed.sa@gmail.com \
    --cc=airlied@linux.ie \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=rodrigosiqueiramelo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).