aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorTobin C. Harding <me@tobin.cc>2018-06-21 19:15:32 -0400
committerTheodore Ts'o <tytso@mit.edu>2018-07-17 21:32:48 -0400
commit753d433b586d1d43c487e3d660f5778c7c8d58ea (patch)
tree7f1a030f66811359e8c12c7e4d3668564d919684 /drivers/char/random.c
parent8ddd6efa56c3fe23df9fe4cf5e2b49cc55416ef4 (diff)
random: Return nbytes filled from hw RNG
Currently the function get_random_bytes_arch() has return value 'void'. If the hw RNG fails we currently fall back to using get_random_bytes(). This defeats the purpose of requesting random material from the hw RNG in the first place. There are currently no intree users of get_random_bytes_arch(). Only get random bytes from the hw RNG, make function return the number of bytes retrieved from the hw RNG. Acked-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Tobin C. Harding <me@tobin.cc> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 8e53e9515a1d..34ddfd57419b 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1725,26 +1725,28 @@ EXPORT_SYMBOL(del_random_ready_callback);
1725 * key known by the NSA). So it's useful if we need the speed, but 1725 * key known by the NSA). So it's useful if we need the speed, but
1726 * only if we're willing to trust the hardware manufacturer not to 1726 * only if we're willing to trust the hardware manufacturer not to
1727 * have put in a back door. 1727 * have put in a back door.
1728 *
1729 * Return number of bytes filled in.
1728 */ 1730 */
1729void get_random_bytes_arch(void *buf, int nbytes) 1731int __must_check get_random_bytes_arch(void *buf, int nbytes)
1730{ 1732{
1733 int left = nbytes;
1731 char *p = buf; 1734 char *p = buf;
1732 1735
1733 trace_get_random_bytes_arch(nbytes, _RET_IP_); 1736 trace_get_random_bytes_arch(left, _RET_IP_);
1734 while (nbytes) { 1737 while (left) {
1735 unsigned long v; 1738 unsigned long v;
1736 int chunk = min(nbytes, (int)sizeof(unsigned long)); 1739 int chunk = min_t(int, left, sizeof(unsigned long));
1737 1740
1738 if (!arch_get_random_long(&v)) 1741 if (!arch_get_random_long(&v))
1739 break; 1742 break;
1740 1743
1741 memcpy(p, &v, chunk); 1744 memcpy(p, &v, chunk);
1742 p += chunk; 1745 p += chunk;
1743 nbytes -= chunk; 1746 left -= chunk;
1744 } 1747 }
1745 1748
1746 if (nbytes) 1749 return nbytes - left;
1747 get_random_bytes(p, nbytes);
1748} 1750}
1749EXPORT_SYMBOL(get_random_bytes_arch); 1751EXPORT_SYMBOL(get_random_bytes_arch);
1750 1752