Subject: Re: [PATCH] crypto: atmel-tdes - use min3 to simplify sg_copy and crypt_start

From: Thorsten Blum <[email-masked]>
Date: Mon, 1 Jun 2026 21:13:49 +0200

On Mon, May 25, 2026 at 11:29:27AM +0200, Thorsten Blum wrote:
> Replace multiple min() and min_t() calls with min3() to simplify the
> code. Using min3() instead of min_t() in atmel_tdes_crypt_start() is
> safe since the values are all unsigned and compatible.
> 
> Signed-off-by: Thorsten Blum <[email-masked]>
> ---
>  drivers/crypto/atmel-tdes.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c
> index 643e507f9c02..834c6d3e1b06 100644
> --- a/drivers/crypto/atmel-tdes.c
> +++ b/drivers/crypto/atmel-tdes.c
> @@ -143,8 +143,7 @@ static int atmel_tdes_sg_copy(struct scatterlist **sg, size_t *offset,
>  	size_t count, off = 0;
>  
>  	while (buflen && total) {
> -		count = min((*sg)->length - *offset, total);
> -		count = min(count, buflen);
> +		count = min3((*sg)->length - *offset, total, buflen);
>  
>  		if (!count)
>  			return off;
> @@ -469,8 +468,8 @@ static int atmel_tdes_crypt_start(struct atmel_tdes_dev *dd)
>  
>  
>  	if (fast)  {
> -		count = min_t(size_t, dd->total, sg_dma_len(dd->in_sg));
> -		count = min_t(size_t, count, sg_dma_len(dd->out_sg));
> +		count = min3(sg_dma_len(dd->in_sg), sg_dma_len(dd->out_sg),
> +			     dd->total);
>  
>  		err = dma_map_sg(dd->dev, dd->in_sg, 1, DMA_TO_DEVICE);
>  		if (!err) {

This should probably be dropped for now because of this fix:
https://lore.kernel.org/lkml/[email-masked]/

Thanks,
Thorsten