Skip to contentSkip to conversation

media: amphion: malone: prevent divide by zero in vpu_malone_check_ready()

PATCH New Dan Carpenter 1 participant 1 message Mar 9, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: amphion: malone: prevent divide by zero in vpu_malone_check_ready()

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")
---
 drivers/media/platform/amphion/vpu_malone.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/media/platform/amphion/vpu_malone.c +6 -2
index c2b424fb6453..b99a04426816 100644
@@ -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;
Signature · 1 line
2.20.1