]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: atmel - use min3 to simplify atmel_sha_append_sg
authorThorsten Blum <thorsten.blum@linux.dev>
Tue, 12 May 2026 14:51:24 +0000 (16:51 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 22 May 2026 12:25:28 +0000 (20:25 +0800)
Replace two consecutive min() calls with min3() to simplify the code.

And since count is unsigned and cannot be less than zero, adjust the if
check and update the comment accordingly.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/atmel-sha.c

index 002b629025534486e74d82e04d84e8b391fb7e47..7e7c83a3d8cda8169bbb5340a74fad674c2308f0 100644 (file)
@@ -305,12 +305,12 @@ static size_t atmel_sha_append_sg(struct atmel_sha_reqctx *ctx)
        size_t count;
 
        while ((ctx->bufcnt < ctx->buflen) && ctx->total) {
-               count = min(ctx->sg->length - ctx->offset, ctx->total);
-               count = min(count, ctx->buflen - ctx->bufcnt);
+               count = min3(ctx->sg->length - ctx->offset, ctx->total,
+                            ctx->buflen - ctx->bufcnt);
 
-               if (count <= 0) {
+               if (count == 0) {
                        /*
-                       * Check if count <= 0 because the buffer is full or
+                       * Check if count == 0 because the buffer is full or
                        * because the sg length is 0. In the latest case,
                        * check if there is another sg in the list, a 0 length
                        * sg doesn't necessarily mean the end of the sg list.