mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: "Vojtěch Krátký" <vo.kratky@seznam.cz>
Cc: gregkh@linuxfoundation.org, christian.gromm@microchip.com,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: most: video: Use min_t() macro for type safety
Date: Wed, 3 Jun 2026 19:51:30 +0300	[thread overview]
Message-ID: <aiBbkqntNHqD1sct@stanley.mountain> (raw)
In-Reply-To: <20260603131928.44274-1-vo.kratky@seznam.cz>

On Wed, Jun 03, 2026 at 03:19:28PM +0200, Vojtěch Krátký wrote:
> Replace the open-coded ternary operator matching a minimum calculation
> with the standard kernel min_t() macro. Because 'count' is a size_t
> and 'rem' is a signed integer, comparing them directly introduces a
> signed/unsigned comparison risk. Forcing both to size_t via min_t()
> ensures safely typed comparison and fixes a build-time macro assertion.
> 
> Signed-off-by: Vojtěch Krátký <vo.kratky@seznam.cz>
> ---
>  drivers/staging/most/video/video.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c
> index 04351f8ccccf..709f61ed0322 100644
> --- a/drivers/staging/most/video/video.c
> +++ b/drivers/staging/most/video/video.c
> @@ -178,7 +178,7 @@ 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;

This feels like an AI static analysis inspired patch.  The concern here
is that "mbo->processed_length - fh->offs" would result in a negative
value.

> -		int const cnt = rem < count ? rem : count;
> +		int const cnt = min_t(size_t, rem, count);
>  
>  		if (copy_to_user(buf, mbo->virt_address + fh->offs, cnt)) {
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But if "fh->offs" is a crazy value then we're still using it here so it
doesn't make sense as a real solution.

So do some more analysis and figure out if the change is required or
not and if it is then try to find a complete solution.

These days we would tend to use minu() instead of min_t(), btw.

regards,
dan carpenter


      reply	other threads:[~2026-06-03 16:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 13:19 Vojtěch Krátký
2026-06-03 16:51 ` Dan Carpenter [this message]

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=aiBbkqntNHqD1sct@stanley.mountain \
    --to=error27@gmail.com \
    --cc=christian.gromm@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=vo.kratky@seznam.cz \
    /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

Powered by JetHome