This code checks if "size" is zero, but it had already used "size" in a MOD operation on the line before so it would already have crashed. Do the check first and then the MOD operation to prevent a divide by zero bug. Fixes: 145e936380ed ("media: amphion: implement malone decoder rpc interface") Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx> --- drivers/media/platform/amphion/vpu_malone.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/amphion/vpu_malone.c b/drivers/media/platform/amphion/vpu_malone.c index c2b424fb6453..b99a04426816 100644 --- a/drivers/media/platform/amphion/vpu_malone.c +++ b/drivers/media/platform/amphion/vpu_malone.c @@ -1564,9 +1564,13 @@ static bool vpu_malone_check_ready(struct vpu_shared_addr *shared, u32 instance) u32 size = desc->end - desc->start; u32 rptr = desc->rptr; u32 wptr = desc->wptr; - u32 used = (wptr + size - rptr) % size; + u32 used; - if (!size || used < size / 2) + if (!size) + return true; + + used = (wptr + size - rptr) % size; + if (used < size / 2) return true; return false; -- 2.20.1