From: Greg KH <gregkh@linuxfoundation.org>
To: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
Cc: parthiban.veerasooran@microchip.com,
christian.gromm@microchip.com, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org, akhileshpatilvnit@gmail.com,
skhan@linuxfoundation.org
Subject: Re: [PATCH] staging: most: video: improve arguments to copy_to_user()
Date: Wed, 13 Aug 2025 16:24:22 +0200 [thread overview]
Message-ID: <2025081323-paralyses-monetary-89f0@gregkh> (raw)
In-Reply-To: <aJx6OF6L2Nza9zQ0@bhairav-test.ee.iitb.ac.in>
On Wed, Aug 13, 2025 at 05:12:48PM +0530, Akhilesh Patil wrote:
> Define cnt constant as unsigned long as expected by copy_to_user()
> to avoid implicit type conversion. Define rem constant as unsigned long
> to compare it with the same type size_t of count variable.
> Use standard helper min() to carry out careful comparison to achive
> same functionality.
>
> Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
> ---
> This patch is motivated from coccinelle report which suggested to use
> kernel standard helper min(). During build check, I found that
> comparison max() showing error while comparing variables of
> different types. Hence this patch also fixes that to make comparison of
> save types.
>
> Compile tested only.
> ---
> drivers/staging/most/video/video.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c
> index 2b3cdb1ce140..4b15c390c32d 100644
> --- a/drivers/staging/most/video/video.c
> +++ b/drivers/staging/most/video/video.c
> @@ -172,8 +172,8 @@ static ssize_t comp_vdev_read(struct file *filp, char __user *buf,
>
> while (count > 0 && data_ready(mdev)) {
> struct mbo *const mbo = get_top_mbo(mdev);
> - int const rem = mbo->processed_length - fh->offs;
> - int const cnt = rem < count ? rem : count;
> + unsigned long const rem = mbo->processed_length - fh->offs;
Why is this unsigned long now? processed_length is a u16 and offs is a
u32. So really this could have gone negative :(
> + unsigned long const cnt = min(rem, count);
But count is size_t, so again, why unsigned long?
I understand the goal of using min(), but it feels like you just might
have broken something with the loss of the overflow check :(
thanks,
greg k-h
next prev parent reply other threads:[~2025-08-13 14:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 11:42 [PATCH] staging: most: video: improve arguments to copy_to_user() Akhilesh Patil
2025-08-13 14:24 ` Greg KH [this message]
2025-08-13 15:40 ` Dan Carpenter
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=2025081323-paralyses-monetary-89f0@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=akhilesh@ee.iitb.ac.in \
--cc=akhileshpatilvnit@gmail.com \
--cc=christian.gromm@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=parthiban.veerasooran@microchip.com \
--cc=skhan@linuxfoundation.org \
/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