drivers/staging/most/video/video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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;
- 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)) {
v4l2_err(&mdev->v4l2_dev, "read: copy_to_user failed\n");
--
2.54.0
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
© 2016 - 2026 Red Hat, Inc.