diff mbox series

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

Message ID 20220309125418.GB11530@kili (mailing list archive)
State New, archived
Headers show
Series media: amphion: malone: prevent divide by zero in vpu_malone_check_ready() | expand

Commit Message

Dan Carpenter March 9, 2022, 12:54 p.m. UTC
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@oracle.com>
---
 drivers/media/platform/amphion/vpu_malone.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

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;