diff --git a/drivers/char/random.c b/drivers/char/random.c
index 2c532a6b0a219f53244ee0ef2c0fdb08195027e8..9675821b4b5af05b7c057e90603b329d5232392b 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -984,14 +984,10 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
 		ibytes = 0;
 	} else {
 		/* If limited, never pull more than available */
-		if (r->limit && ibytes + reserved >= have_bytes)
-			ibytes = have_bytes - reserved;
-
-		if (have_bytes >= ibytes + reserved)
-			entropy_count -= ibytes << (ENTROPY_SHIFT + 3);
-		else
-			entropy_count = reserved << (ENTROPY_SHIFT + 3);
-
+		if (r->limit)
+			ibytes = min_t(size_t, ibytes, have_bytes - reserved);
+		entropy_count = max_t(int, 0,
+			    entropy_count - (ibytes << (ENTROPY_SHIFT + 3)));
 		if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
 			goto retry;