]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: xilinx-trng - Fix return value of xtrng_hwrng_trng_read()
authorEric Biggers <ebiggers@kernel.org>
Sun, 31 May 2026 19:17:36 +0000 (12:17 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 11 Jun 2026 06:03:13 +0000 (14:03 +0800)
Implementations of hwrng::read are expected to return the number of
bytes generated.  Update xtrng_hwrng_trng_read() to match that.

Fixes: 8979744aca80 ("crypto: xilinx - Add TRNG driver for Versal")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/xilinx/xilinx-trng.c

index a35643baa4899869a7597a04fa83243dbf56cbbf..a30b0b3b3685f2d9360879882bd8bde449e74fed 100644 (file)
@@ -239,18 +239,21 @@ static int xtrng_hwrng_trng_read(struct hwrng *hwrng, void *data, size_t max, bo
 {
        u8 buf[TRNG_SEC_STRENGTH_BYTES];
        struct xilinx_rng *rng;
-       int ret = -EINVAL, i = 0;
+       int ret = 0, i = 0;
 
        rng = container_of(hwrng, struct xilinx_rng, trng);
        while (i < max) {
                ret = xtrng_random_bytes_generate(rng, buf, TRNG_SEC_STRENGTH_BYTES, wait);
-               if (ret < 0)
+               if (ret < 0) {
+                       if (i == 0)
+                               return ret;
                        break;
+               }
 
                memcpy(data + i, buf, min_t(int, ret, (max - i)));
                i += min_t(int, ret, (max - i));
        }
-       return ret;
+       return i;
 }
 
 static int xtrng_hwrng_register(struct hwrng *trng)