aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorGreg Price <price@MIT.EDU>2013-11-29 15:02:33 -0500
committerTheodore Ts'o <tytso@mit.edu>2014-03-19 22:18:50 -0400
commit12ff3a517ab92b5496c731a3c354caa1f16c569f (patch)
tree598dfb6d4e4caa8ae10e8f04b76cd36d868e6ad3 /drivers/char/random.c
parent18e9cea74951b64282964f9625db94c5d5a007bd (diff)
random: simplify loop in random_read
The loop condition never changes until just before a break, so we might as well write it as a constant. Also since a996996dd75a ("random: drop weird m_time/a_time manipulation") we don't do anything after the loop finishes, so the 'break's might as well return directly. Some other simplifications. There should be no change in behavior introduced by this commit. Signed-off-by: Greg Price <price@mit.edu> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c57
1 files changed, 18 insertions, 39 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index fcda7d3937e0..fcc2bff8f887 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1285,53 +1285,32 @@ void rand_initialize_disk(struct gendisk *disk)
1285static ssize_t 1285static ssize_t
1286random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 1286random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
1287{ 1287{
1288 ssize_t n, retval = 0, count = 0; 1288 ssize_t n;
1289 1289
1290 if (nbytes == 0) 1290 if (nbytes == 0)
1291 return 0; 1291 return 0;
1292 1292
1293 while (nbytes > 0) { 1293 nbytes = min_t(size_t, nbytes, SEC_XFER_SIZE);
1294 n = nbytes; 1294 while (1) {
1295 if (n > SEC_XFER_SIZE) 1295 n = extract_entropy_user(&blocking_pool, buf, nbytes);
1296 n = SEC_XFER_SIZE; 1296 if (n < 0)
1297 1297 return n;
1298 n = extract_entropy_user(&blocking_pool, buf, n);
1299
1300 if (n < 0) {
1301 retval = n;
1302 break;
1303 }
1304
1305 trace_random_read(n*8, (nbytes-n)*8, 1298 trace_random_read(n*8, (nbytes-n)*8,
1306 ENTROPY_BITS(&blocking_pool), 1299 ENTROPY_BITS(&blocking_pool),
1307 ENTROPY_BITS(&input_pool)); 1300 ENTROPY_BITS(&input_pool));
1308 1301 if (n > 0)
1309 if (n == 0) { 1302 return n;
1310 if (file->f_flags & O_NONBLOCK) { 1303 /* Pool is (near) empty. Maybe wait and retry. */
1311 retval = -EAGAIN; 1304
1312 break; 1305 if (file->f_flags & O_NONBLOCK)
1313 } 1306 return -EAGAIN;
1314 1307
1315 wait_event_interruptible(random_read_wait, 1308 wait_event_interruptible(random_read_wait,
1316 ENTROPY_BITS(&input_pool) >= 1309 ENTROPY_BITS(&input_pool) >=
1317 random_read_wakeup_thresh); 1310 random_read_wakeup_thresh);
1318 1311 if (signal_pending(current))
1319 if (signal_pending(current)) { 1312 return -ERESTARTSYS;
1320 retval = -ERESTARTSYS;
1321 break;
1322 }
1323
1324 continue;
1325 }
1326
1327 count += n;
1328 buf += n;
1329 nbytes -= n;
1330 break; /* This break makes the device work */
1331 /* like a named pipe */
1332 } 1313 }
1333
1334 return (count ? count : retval);
1335} 1314}
1336 1315
1337static ssize_t 1316static ssize_t