[PATCH v2 4/8] iio: core: Use min() instead of min_t() to make code more robust

Andy Shevchenko posted 8 patches 2 years, 6 months ago
There is a newer version of this series
[PATCH v2 4/8] iio: core: Use min() instead of min_t() to make code more robust
Posted by Andy Shevchenko 2 years, 6 months ago
min() has strict type checking and preferred over min_t() for
unsigned types to avoid overflow. Here it's unclear why min_t()
was chosen since both variables are of the same type. In any
case update to use min().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/industrialio-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 6e28c2a3d223..78cc67efa490 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -389,7 +389,7 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
 	char buf[80];
 	int ret;
 
-	count = min_t(size_t, count, (sizeof(buf)-1));
+	count = min(count, sizeof(buf) - 1);
 	if (copy_from_user(buf, userbuf, count))
 		return -EFAULT;
 
-- 
2.40.0.1.gaa8946217a0b
Re: [PATCH v2 4/8] iio: core: Use min() instead of min_t() to make code more robust
Posted by Jonathan Cameron 2 years, 6 months ago
On Fri, 21 Jul 2023 20:00:18 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> min() has strict type checking and preferred over min_t() for
> unsigned types to avoid overflow. Here it's unclear why min_t()
> was chosen since both variables are of the same type. In any
> case update to use min().
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Applied to the togreg branch of iio.git and pushed out as testing
for 0-day to give it a quick sanity check.

Thanks,

Jonathan

> ---
>  drivers/iio/industrialio-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 6e28c2a3d223..78cc67efa490 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -389,7 +389,7 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
>  	char buf[80];
>  	int ret;
>  
> -	count = min_t(size_t, count, (sizeof(buf)-1));
> +	count = min(count, sizeof(buf) - 1);
>  	if (copy_from_user(buf, userbuf, count))
>  		return -EFAULT;
>