struct mdp5_crtc {
        struct drm_crtc base;
        char name[8];
-       struct drm_plane *planes[8];
        int id;
        bool enabled;
 
        struct mdp5_crtc *mdp5_crtc = to_mdp5_crtc(crtc);
        struct mdp5_kms *mdp5_kms = get_kms(crtc);
        int id = mdp5_crtc->id;
-       uint32_t i, flush = 0;
+       struct drm_plane *plane;
+       uint32_t flush = 0;
 
-       for (i = 0; i < ARRAY_SIZE(mdp5_crtc->planes); i++) {
-               struct drm_plane *plane = mdp5_crtc->planes[i];
-               if (plane) {
-                       enum mdp5_pipe pipe = mdp5_plane_pipe(plane);
-                       flush |= pipe2flush(pipe);
-               }
+       for_each_plane_on_crtc(crtc, plane) {
+               enum mdp5_pipe pipe = mdp5_plane_pipe(plane);
+               flush |= pipe2flush(pipe);
        }
+
        flush |= mixer2flush(mdp5_crtc->id);
        flush |= MDP5_CTL_FLUSH_CTL;
 
        struct mdp5_crtc *mdp5_crtc = to_mdp5_crtc(crtc);
        struct drm_device *dev = crtc->dev;
        struct drm_pending_vblank_event *event;
-       unsigned long flags, i;
+       struct drm_plane *plane;
+       unsigned long flags;
 
        spin_lock_irqsave(&dev->event_lock, flags);
        event = mdp5_crtc->event;
        }
        spin_unlock_irqrestore(&dev->event_lock, flags);
 
-       for (i = 0; i < ARRAY_SIZE(mdp5_crtc->planes); i++) {
-               struct drm_plane *plane = mdp5_crtc->planes[i];
-               if (plane)
-                       mdp5_plane_complete_flip(plane);
-       }
+       for_each_plane_on_crtc(crtc, plane)
+               mdp5_plane_complete_flip(plane);
 }
 
 static void pageflip_cb(struct msm_fence_cb *cb)
 {
        struct mdp5_crtc *mdp5_crtc = to_mdp5_crtc(crtc);
 
-       BUG_ON(pipe_id >= ARRAY_SIZE(mdp5_crtc->planes));
-
-       if (mdp5_crtc->planes[pipe_id] == plane)
-               return;
-
-       mdp5_crtc->planes[pipe_id] = plane;
        blend_setup(crtc);
        if (mdp5_crtc->enabled && (plane != crtc->primary))
                crtc_flush(crtc);
 
        drm_crtc_init_with_planes(dev, crtc, plane, NULL, &mdp5_crtc_funcs);
        drm_crtc_helper_add(crtc, &mdp5_crtc_helper_funcs);
+       plane->crtc = crtc;
 
        mdp5_plane_install_properties(plane, &crtc->base);