mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: most: video: Use min_t() macro for type safety
@ 2026-06-03 13:19 Vojtěch Krátký
  2026-06-03 16:51 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Vojtěch Krátký @ 2026-06-03 13:19 UTC (permalink / raw)
  To: gregkh, christian.gromm
  Cc: linux-staging, linux-kernel, Vojtěch Krátký

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] staging: most: video: Use min_t() macro for type safety
  2026-06-03 13:19 [PATCH] staging: most: video: Use min_t() macro for type safety Vojtěch Krátký
@ 2026-06-03 16:51 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2026-06-03 16:51 UTC (permalink / raw)
  To: Vojtěch Krátký
  Cc: gregkh, christian.gromm, linux-staging, linux-kernel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-03 16:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-03 13:19 [PATCH] staging: most: video: Use min_t() macro for type safety Vojtěch Krátký
2026-06-03 16:51 ` Dan Carpenter

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