[PATCH] drm/kms/crtc: Saving crtc->primary into a drm_plane pointer instead of dereferencing it every time.

From: Satendra Singh Thakur
Date: Mon Jul 30 2018 - 02:06:18 EST


In the func __drm_mode_set_config_internal,
objects (fb, old_fb, crtc) of crtc->primary are used at many places.
To access the objects of primary, it is dereferenced from crtc every
time. It's better to save it into drm_plane pointer.
This will make the code look simple.

Signed-off-by: Satendra Singh Thakur <satendra.t@xxxxxxxxxxx>
---
drivers/gpu/drm/drm_crtc.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 98a36e6..9644f5b 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -462,6 +462,7 @@ static int __drm_mode_set_config_internal(struct drm_mode_set *set,
struct drm_crtc *crtc = set->crtc;
struct drm_framebuffer *fb;
struct drm_crtc *tmp;
+ struct drm_plane *plane;
int ret;

/*
@@ -469,23 +470,27 @@ static int __drm_mode_set_config_internal(struct drm_mode_set *set,
* connectors from it), hence we need to refcount the fbs across all
* crtcs. Atomic modeset will have saner semantics ...
*/
- drm_for_each_crtc(tmp, crtc->dev)
- tmp->primary->old_fb = tmp->primary->fb;
+ drm_for_each_crtc(tmp, crtc->dev) {
+ plane = tmp->primary;
+ plane->old_fb = plane->fb;
+ }

fb = set->fb;
-
ret = crtc->funcs->set_config(set, ctx);
if (ret == 0) {
- crtc->primary->crtc = fb ? crtc : NULL;
- crtc->primary->fb = fb;
+ plane = crtc->primary;
+ plane->crtc = fb ? crtc : NULL;
+ plane->fb = fb;
}

drm_for_each_crtc(tmp, crtc->dev) {
- if (tmp->primary->fb)
- drm_framebuffer_get(tmp->primary->fb);
- if (tmp->primary->old_fb)
- drm_framebuffer_put(tmp->primary->old_fb);
- tmp->primary->old_fb = NULL;
+ plane = tmp->primary;
+ if (plane->fb)
+ drm_framebuffer_get(plane->fb);
+ if (plane->old_fb) {
+ drm_framebuffer_put(plane->old_fb);
+ plane->old_fb = NULL;
+ }
}

return ret;
--
2.7.4