mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: linux-kernel@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH 4/7] random: remove unused reserved argument
Date: Sun, 16 Jan 2022 17:22:32 +0100	[thread overview]
Message-ID: <YeRGSPTpJlSTJdgO@zx2c4.com> (raw)
In-Reply-To: <YeQcpzxKWLuJ9Kcz@owl.dominikbrodowski.net>

On Sun, Jan 16, 2022 at 2:45 PM Dominik Brodowski <linux@dominikbrodowski.net> wrote:
> > @@ -1342,7 +1341,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
> >       /* never pull more than available */
> >       have_bytes = entropy_count >> (ENTROPY_SHIFT + 3);
> > 
> > -     if ((have_bytes -= reserved) < 0)
> > +     if (have_bytes < 0)
> >               have_bytes = 0;
> >       ibytes = min_t(size_t, ibytes, have_bytes);
>
> Hmm. We already WARN_ON(entropy_count < 0) a few lines below. Maybe move
> that assertion before the assignement of have_bytes? Then, have_bytes can
> never be lower than zero, and the code becomes even simpler. What do you
> think?

Can you send a separate patch for this that we can apply on top? It
seems reasonable anyhow. Something like:

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 327086b35797..419156d2146d 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1329,7 +1329,7 @@ EXPORT_SYMBOL_GPL(add_disk_randomness);
  */
 static size_t account(struct entropy_store *r, size_t nbytes, int min)
 {
-	int entropy_count, orig, have_bytes;
+	int entropy_count, orig;
 	size_t ibytes, nfrac;

 	BUG_ON(r->entropy_count > POOL_FRACBITS);
@@ -1337,21 +1337,17 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min)
 	/* Can we pull enough? */
 retry:
 	entropy_count = orig = READ_ONCE(r->entropy_count);
-	ibytes = nbytes;
-	/* never pull more than available */
-	have_bytes = entropy_count >> (ENTROPY_SHIFT + 3);
-
-	if (have_bytes < 0)
-		have_bytes = 0;
-	ibytes = min_t(size_t, ibytes, have_bytes);
-	if (ibytes < min)
-		ibytes = 0;
-
 	if (WARN_ON(entropy_count < 0)) {
 		pr_warn("negative entropy count: pool %s count %d\n",
 			r->name, entropy_count);
 		entropy_count = 0;
 	}
+
+	/* never pull more than available */
+	ibytes = min_t(size_t, nbytes, entropy_count >> (ENTROPY_SHIFT + 3));
+	if (ibytes < min)
+		ibytes = 0;
+
 	nfrac = ibytes << (ENTROPY_SHIFT + 3);
 	if ((size_t) entropy_count > nfrac)
 		entropy_count -= nfrac;



  reply	other threads:[~2022-01-16 16:22 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 15:44 [PATCH 0/7] first in overall series of rng code house cleaning Jason A. Donenfeld
2022-01-13 15:44 ` [PATCH 1/7] random: cleanup poolinfo abstraction Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 2/7] random: cleanup integer types Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 3/7] random: remove incomplete last_data logic Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 4/7] random: remove unused reserved argument Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-16 16:22     ` Jason A. Donenfeld [this message]
2022-01-17 17:28       ` Dominik Brodowski
2022-01-17 17:52         ` [PATCH] random: simplify arithmetic function flow in account() Jason A. Donenfeld
2022-01-17 17:55           ` Jason A. Donenfeld
2022-01-13 15:44 ` [PATCH 5/7] random: rather than entropy_store abstraction, use global Jason A. Donenfeld
2022-01-16 13:24   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 6/7] random: remove unused OUTPUT_POOL constants Jason A. Donenfeld
2022-01-16 13:25   ` Dominik Brodowski
2022-01-13 15:44 ` [PATCH 7/7] random: de-duplicate INPUT_POOL constants Jason A. Donenfeld
2022-01-16 13:25   ` Dominik Brodowski
2022-01-14 15:33 ` [PATCH] random: cleanup fractional entropy shift constants Jason A. Donenfeld
2022-01-14 15:39   ` David Laight
2022-01-14 15:46     ` Jason A. Donenfeld
2022-01-16 16:35 ` [PATCH 1/4] random: prepend remaining pool constants with POOL_ Jason A. Donenfeld
2022-01-16 16:35   ` [PATCH 2/4] random: cleanup fractional entropy shift constants Jason A. Donenfeld
2022-01-17 17:31     ` Dominik Brodowski
2022-01-16 16:35   ` [PATCH 3/4] random: access input_pool_data directly rather than through pointer Jason A. Donenfeld
2022-01-17 17:32     ` Dominik Brodowski
2022-01-16 16:35   ` [PATCH 4/4] random: selectively clang-format where it makes sense Jason A. Donenfeld
2022-01-17 17:34     ` Dominik Brodowski
2022-01-17 17:29   ` [PATCH 1/4] random: prepend remaining pool constants with POOL_ Dominik Brodowski

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=YeRGSPTpJlSTJdgO@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=tytso@mit.edu \
    /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

Powered by JetHome