diff options
author | Matt Mackall <mpm@selenic.com> | 2008-04-29 04:03:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:06:25 -0400 |
commit | adc782dae6c4c0f6fb679a48a544cfbcd79ae3dc (patch) | |
tree | 67ad14a2905ff12603dd72601c3ee5398f7148fb /drivers | |
parent | e68e5b664ecb9bccf68102557107a6b6d739a97c (diff) |
random: simplify and rename credit_entropy_store
- emphasize bits in the name
- make zero bits lock-free
- simplify logic
Signed-off-by: Matt Mackall <mpm@selenic.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/random.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index d33f52cd437b..2faeef28c209 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -441,7 +441,7 @@ static struct entropy_store nonblocking_pool = { | |||
441 | /* | 441 | /* |
442 | * This function adds bytes into the entropy "pool". It does not | 442 | * This function adds bytes into the entropy "pool". It does not |
443 | * update the entropy estimate. The caller should call | 443 | * update the entropy estimate. The caller should call |
444 | * credit_entropy_store if this is appropriate. | 444 | * credit_entropy_bits if this is appropriate. |
445 | * | 445 | * |
446 | * The pool is stirred with a primitive polynomial of the appropriate | 446 | * The pool is stirred with a primitive polynomial of the appropriate |
447 | * degree, and then twisted. We twist by three bits at a time because | 447 | * degree, and then twisted. We twist by three bits at a time because |
@@ -515,24 +515,22 @@ static void mix_pool_bytes(struct entropy_store *r, const void *in, int bytes) | |||
515 | /* | 515 | /* |
516 | * Credit (or debit) the entropy store with n bits of entropy | 516 | * Credit (or debit) the entropy store with n bits of entropy |
517 | */ | 517 | */ |
518 | static void credit_entropy_store(struct entropy_store *r, int nbits) | 518 | static void credit_entropy_bits(struct entropy_store *r, int nbits) |
519 | { | 519 | { |
520 | unsigned long flags; | 520 | unsigned long flags; |
521 | 521 | ||
522 | if (!nbits) | ||
523 | return; | ||
524 | |||
522 | spin_lock_irqsave(&r->lock, flags); | 525 | spin_lock_irqsave(&r->lock, flags); |
523 | 526 | ||
524 | if (r->entropy_count + nbits < 0) { | 527 | DEBUG_ENT("added %d entropy credits to %s\n", nbits, r->name); |
525 | DEBUG_ENT("negative entropy/overflow (%d+%d)\n", | 528 | r->entropy_count += nbits; |
526 | r->entropy_count, nbits); | 529 | if (r->entropy_count < 0) { |
530 | DEBUG_ENT("negative entropy/overflow\n"); | ||
527 | r->entropy_count = 0; | 531 | r->entropy_count = 0; |
528 | } else if (r->entropy_count + nbits > r->poolinfo->POOLBITS) { | 532 | } else if (r->entropy_count > r->poolinfo->POOLBITS) |
529 | r->entropy_count = r->poolinfo->POOLBITS; | 533 | r->entropy_count = r->poolinfo->POOLBITS; |
530 | } else { | ||
531 | r->entropy_count += nbits; | ||
532 | if (nbits) | ||
533 | DEBUG_ENT("added %d entropy credits to %s\n", | ||
534 | nbits, r->name); | ||
535 | } | ||
536 | 534 | ||
537 | /* should we wake readers? */ | 535 | /* should we wake readers? */ |
538 | if (r == &input_pool && r->entropy_count >= random_read_wakeup_thresh) | 536 | if (r == &input_pool && r->entropy_count >= random_read_wakeup_thresh) |
@@ -619,8 +617,8 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num) | |||
619 | * Round down by 1 bit on general principles, | 617 | * Round down by 1 bit on general principles, |
620 | * and limit entropy entimate to 12 bits. | 618 | * and limit entropy entimate to 12 bits. |
621 | */ | 619 | */ |
622 | credit_entropy_store(&input_pool, | 620 | credit_entropy_bits(&input_pool, |
623 | min_t(int, fls(delta>>1), 11)); | 621 | min_t(int, fls(delta>>1), 11)); |
624 | } | 622 | } |
625 | out: | 623 | out: |
626 | preempt_enable(); | 624 | preempt_enable(); |
@@ -702,7 +700,7 @@ static void xfer_secondary_pool(struct entropy_store *r, size_t nbytes) | |||
702 | bytes = extract_entropy(r->pull, tmp, bytes, | 700 | bytes = extract_entropy(r->pull, tmp, bytes, |
703 | random_read_wakeup_thresh / 8, rsvd); | 701 | random_read_wakeup_thresh / 8, rsvd); |
704 | mix_pool_bytes(r, tmp, bytes); | 702 | mix_pool_bytes(r, tmp, bytes); |
705 | credit_entropy_store(r, bytes*8); | 703 | credit_entropy_bits(r, bytes*8); |
706 | } | 704 | } |
707 | } | 705 | } |
708 | 706 | ||
@@ -1073,7 +1071,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) | |||
1073 | return -EPERM; | 1071 | return -EPERM; |
1074 | if (get_user(ent_count, p)) | 1072 | if (get_user(ent_count, p)) |
1075 | return -EFAULT; | 1073 | return -EFAULT; |
1076 | credit_entropy_store(&input_pool, ent_count); | 1074 | credit_entropy_bits(&input_pool, ent_count); |
1077 | return 0; | 1075 | return 0; |
1078 | case RNDADDENTROPY: | 1076 | case RNDADDENTROPY: |
1079 | if (!capable(CAP_SYS_ADMIN)) | 1077 | if (!capable(CAP_SYS_ADMIN)) |
@@ -1088,7 +1086,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg) | |||
1088 | size); | 1086 | size); |
1089 | if (retval < 0) | 1087 | if (retval < 0) |
1090 | return retval; | 1088 | return retval; |
1091 | credit_entropy_store(&input_pool, ent_count); | 1089 | credit_entropy_bits(&input_pool, ent_count); |
1092 | return 0; | 1090 | return 0; |
1093 | case RNDZAPENTCNT: | 1091 | case RNDZAPENTCNT: |
1094 | case RNDCLEARPOOL: | 1092 | case RNDCLEARPOOL: |