drm/msm/mdp5: Fix negative SMP block allocation
authorStephane Viau <sviau@codeaurora.org>
Fri, 16 Jan 2015 18:22:14 +0000 (13:22 -0500)
committerRob Clark <robdclark@gmail.com>
Sun, 1 Feb 2015 20:32:47 +0000 (15:32 -0500)
In case we request a number of SMP blocks which is lower than
the already reserved blocks, we should not try to allocate a
negative number, but 0 blocks instead.

Signed-off-by: Stephane Viau <sviau@codeaurora.org>
Signed-off-by: Rob Clark <robdclark@gmail.com>
drivers/gpu/drm/msm/mdp/mdp5/mdp5_smp.c

index bf551885e0197ed7421f32ab8976b66580e41dd5..1f795af89680103211878ac48f77d506981395a6 100644 (file)
@@ -119,9 +119,10 @@ static int smp_request_block(struct mdp5_smp *smp,
 
        spin_lock_irqsave(&smp->state_lock, flags);
 
-       nblks -= reserved;
-       if (reserved)
+       if (reserved) {
+               nblks = max(0, nblks - reserved);
                DBG("%d MMBs allocated (%d reserved)", nblks, reserved);
+       }
 
        avail = cnt - bitmap_weight(smp->state, cnt);
        if (nblks > avail) {