|
@@ -1725,26 +1725,28 @@ EXPORT_SYMBOL(del_random_ready_callback);
|
|
|
* key known by the NSA). So it's useful if we need the speed, but
|
|
|
* only if we're willing to trust the hardware manufacturer not to
|
|
|
* have put in a back door.
|
|
|
+ *
|
|
|
+ * Return number of bytes filled in.
|
|
|
*/
|
|
|
-void get_random_bytes_arch(void *buf, int nbytes)
|
|
|
+int __must_check get_random_bytes_arch(void *buf, int nbytes)
|
|
|
{
|
|
|
+ int left = nbytes;
|
|
|
char *p = buf;
|
|
|
|
|
|
- trace_get_random_bytes_arch(nbytes, _RET_IP_);
|
|
|
- while (nbytes) {
|
|
|
+ trace_get_random_bytes_arch(left, _RET_IP_);
|
|
|
+ while (left) {
|
|
|
unsigned long v;
|
|
|
- int chunk = min(nbytes, (int)sizeof(unsigned long));
|
|
|
+ int chunk = min_t(int, left, sizeof(unsigned long));
|
|
|
|
|
|
if (!arch_get_random_long(&v))
|
|
|
break;
|
|
|
|
|
|
memcpy(p, &v, chunk);
|
|
|
p += chunk;
|
|
|
- nbytes -= chunk;
|
|
|
+ left -= chunk;
|
|
|
}
|
|
|
|
|
|
- if (nbytes)
|
|
|
- get_random_bytes(p, nbytes);
|
|
|
+ return nbytes - left;
|
|
|
}
|
|
|
EXPORT_SYMBOL(get_random_bytes_arch);
|
|
|
|