drm/msm/sde: apply correct zpos range for sde clients

Maximum value of zpos should be maxblendstages-1 and not max
blend stages.

Change-Id: I0d991dea29c77cff672f5fd5564e750cafd18e60
Signed-off-by: Clarence Ip <cip@codeaurora.org>
diff --git a/drivers/gpu/drm/msm/sde/sde_plane.c b/drivers/gpu/drm/msm/sde/sde_plane.c
index 8dc31a5..3927515 100644
--- a/drivers/gpu/drm/msm/sde/sde_plane.c
+++ b/drivers/gpu/drm/msm/sde/sde_plane.c
@@ -1443,8 +1443,12 @@
 	}
 
 	if (sde_is_custom_client()) {
-		if (catalog->mixer_count && catalog->mixer)
-			zpos_max = catalog->mixer[0].sblk->maxblendstages;
+		if (catalog->mixer_count && catalog->mixer &&
+				catalog->mixer[0].sblk->maxblendstages) {
+			zpos_max = catalog->mixer[0].sblk->maxblendstages - 1;
+			if (zpos_max > SDE_STAGE_MAX - SDE_STAGE_0 - 1)
+				zpos_max = SDE_STAGE_MAX - SDE_STAGE_0 - 1;
+		}
 	} else if (plane->type != DRM_PLANE_TYPE_PRIMARY) {
 		/* reserve zpos == 0 for primary planes */
 		zpos_def = drm_plane_index(plane) + 1;