[PATCH 01/12] hw_random: support ctrlc()
Ahmad Fatoum
a.fatoum at pengutronix.de
Wed Mar 13 03:56:20 PDT 2024
It's valid for HWRNG drivers to return 0 bytes read, thereby instructing
the caller to try again. We do that for the cdev_read operation, but in
case the driver never returns a non-zero value, barebox will keep
waiting indefinitely. Check ctrlc() in that case and return a short read
if the user interrupts the operation.
We don't need ctrlc() in the general case, as the caller is free to
check for ctrlc() between reads to the device.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
drivers/hw_random/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hw_random/core.c b/drivers/hw_random/core.c
index 89b979ade8b1..7bc3c33319f9 100644
--- a/drivers/hw_random/core.c
+++ b/drivers/hw_random/core.c
@@ -44,10 +44,10 @@ static ssize_t rng_dev_read(struct cdev *cdev, void *buf, size_t size,
while (count) {
int max = min(count, (size_t)RNG_BUFFER_SIZE);
len = hwrng_get_data(rng, rng->buf, max, true);
- if (len < 0) {
- cur = len;
- break;
- }
+ if (len < 0)
+ return len;
+ if (!len && ctrlc())
+ return cur;
memcpy(buf + cur, rng->buf, len);
--
2.39.2
More information about the barebox
mailing list