From: Matt Mackall <mpm@selenic.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 12 of 12] random: simplify and rename credit_entropy_store
Date: Thu, 17 Jan 2008 20:33:54 -0600 [thread overview]
Message-ID: <218e9dac90b1b81b167e.1200623634@cinder.waste.org> (raw)
In-Reply-To: <patchbomb.1200623622@cinder.waste.org>
- emphasize bits in the name
- make zero bits lock-free
- simplify logic
diff -r a0689714301a -r 218e9dac90b1 drivers/char/random.c
--- a/drivers/char/random.c Thu Jan 17 20:25:24 2008 -0600
+++ b/drivers/char/random.c Thu Jan 17 20:25:24 2008 -0600
@@ -441,7 +441,7 @@
/*
* This function adds bytes into the entropy "pool". It does not
* update the entropy estimate. The caller should call
- * credit_entropy_store if this is appropriate.
+ * credit_entropy_bits if this is appropriate.
*
* The pool is stirred with a primitive polynomial of the appropriate
* degree, and then twisted. We twist by three bits at a time because
@@ -515,24 +515,22 @@
/*
* Credit (or debit) the entropy store with n bits of entropy
*/
-static void credit_entropy_store(struct entropy_store *r, int nbits)
+static void credit_entropy_bits(struct entropy_store *r, int nbits)
{
unsigned long flags;
+ if (!nbits)
+ return;
+
spin_lock_irqsave(&r->lock, flags);
- if (r->entropy_count + nbits < 0) {
- DEBUG_ENT("negative entropy/overflow (%d+%d)\n",
- r->entropy_count, nbits);
+ DEBUG_ENT("added %d entropy credits to %s\n", nbits, r->name);
+ r->entropy_count += nbits;
+ if (r->entropy_count < 0) {
+ DEBUG_ENT("negative entropy/overflow\n");
r->entropy_count = 0;
- } else if (r->entropy_count + nbits > r->poolinfo->POOLBITS) {
+ } else if (r->entropy_count > r->poolinfo->POOLBITS)
r->entropy_count = r->poolinfo->POOLBITS;
- } else {
- r->entropy_count += nbits;
- if (nbits)
- DEBUG_ENT("added %d entropy credits to %s\n",
- nbits, r->name);
- }
/* should we wake readers? */
if (r == &input_pool && r->entropy_count >= random_read_wakeup_thresh)
@@ -619,8 +617,8 @@
* Round down by 1 bit on general principles,
* and limit entropy entimate to 12 bits.
*/
- credit_entropy_store(&input_pool,
- min_t(int, fls(delta>>1), 11));
+ credit_entropy_bits(&input_pool,
+ min_t(int, fls(delta>>1), 11));
}
out:
preempt_enable();
@@ -703,7 +701,7 @@
bytes = extract_entropy(r->pull, tmp, bytes,
random_read_wakeup_thresh / 8, rsvd);
mix_pool_bytes(r, tmp, bytes);
- credit_entropy_store(r, bytes*8);
+ credit_entropy_bits(r, bytes*8);
}
}
@@ -1074,7 +1072,7 @@
return -EPERM;
if (get_user(ent_count, p))
return -EFAULT;
- credit_entropy_store(&input_pool, ent_count);
+ credit_entropy_bits(&input_pool, ent_count);
return 0;
case RNDADDENTROPY:
if (!capable(CAP_SYS_ADMIN))
@@ -1089,7 +1087,7 @@
size);
if (retval < 0)
return retval;
- credit_entropy_store(&input_pool, ent_count);
+ credit_entropy_bits(&input_pool, ent_count);
return 0;
case RNDZAPENTCNT:
case RNDCLEARPOOL:
prev parent reply other threads:[~2008-01-18 2:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-18 2:33 [PATCH 00 of 12] random cleanups for 2.6.25 Matt Mackall
2008-01-18 2:33 ` [PATCH 01 of 12] random: clean up checkpatch complaints Matt Mackall
2008-01-18 2:33 ` [PATCH 02 of 12] random: consolidate wakeup logic Matt Mackall
2008-01-18 2:33 ` [PATCH 03 of 12] random: use unlocked_ioctl Matt Mackall
2008-01-18 2:33 ` [PATCH 04 of 12] random: reuse rand_initialize Matt Mackall
2008-01-18 2:33 ` [PATCH 05 of 12] random: improve variable naming, clear extract buffer Matt Mackall
2008-01-18 2:33 ` [PATCH 06 of 12] random: make backtracking attacks harder Matt Mackall
2008-01-18 2:33 ` [PATCH 07 of 12] random: remove cacheline alignment for locks Matt Mackall
2008-01-18 2:33 ` [PATCH 08 of 12] random: eliminate redundant new_rotate variable Matt Mackall
2008-01-18 2:33 ` [PATCH 09 of 12] random: remove some prefetch logic Matt Mackall
2008-01-18 2:33 ` [PATCH 10 of 12] random: simplify add_ptr logic Matt Mackall
2008-01-18 2:33 ` [PATCH 11 of 12] random: make mixing interface byte-oriented Matt Mackall
2008-01-18 2:33 ` Matt Mackall [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=218e9dac90b1b81b167e.1200623634@cinder.waste.org \
--to=mpm@selenic.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®