Skip to content

Commit c0f6eeb

Browse files
ldtsherbertx
authored andcommitted
hwrng: optee - fix wait use case
The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop will exit. This fix does not wait if all data has been read (skips the call to msleep(0)) and reads a second time if partial data was retrieved on the first read. Worth noticing that since msleep(0) schedules a one jiffy timeout is better to skip such a call. Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 3409399 commit c0f6eeb

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎drivers/char/hw_random/optee-rng.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
122122
if (max > MAX_ENTROPY_REQ_SZ)
123123
max = MAX_ENTROPY_REQ_SZ;
124124

125-
while (read == 0) {
125+
while (read < max) {
126126
rng_size = get_optee_rng_data(pvt_data, data, (max - read));
127127

128128
data += rng_size;
129129
read += rng_size;
130130

131131
if (wait && pvt_data->data_rate) {
132-
if (timeout-- == 0)
132+
if ((timeout-- == 0) || (read == max))
133133
return read;
134134
msleep((1000 * (max - read)) / pvt_data->data_rate);
135135
} else {

0 commit comments

Comments
 (0)