* [PATCH] media: amphion: malone: prevent divide by zero in vpu_malone_check_ready()
@ 2022-03-09 12:54 Dan Carpenter
0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2022-03-09 12:54 UTC (permalink / raw)
To: Ming Qian
Cc: Shijie Qin, Zhou Peng, Mauro Carvalho Chehab, Hans Verkuil,
linux-media, kernel-janitors
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 --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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-09 12:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-09 12:54 [PATCH] media: amphion: malone: prevent divide by zero in vpu_malone_check_ready() Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox