From: Dan Carpenter <dan.carpenter@oracle.com>
To: Ming Qian <ming.qian@nxp.com>
Cc: Shijie Qin <shijie.qin@nxp.com>, Zhou Peng <eagle.zhou@nxp.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>,
linux-media@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] media: amphion: malone: prevent divide by zero in vpu_malone_check_ready()
Date: Wed, 9 Mar 2022 15:54:18 +0300 [thread overview]
Message-ID: <20220309125418.GB11530@kili> (raw)
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
reply other threads:[~2022-03-09 12:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220309125418.GB11530@kili \
--to=dan.carpenter@oracle.com \
--cc=eagle.zhou@nxp.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ming.qian@nxp.com \
--cc=shijie.qin@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).