From nobody Tue Apr 28 02:27:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD233C433EF for ; Tue, 7 Jun 2022 15:07:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343857AbiFGPHV (ORCPT ); Tue, 7 Jun 2022 11:07:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245029AbiFGPHT (ORCPT ); Tue, 7 Jun 2022 11:07:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 746B31C9 for ; Tue, 7 Jun 2022 08:07:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1C9C2B81FD1 for ; Tue, 7 Jun 2022 15:07:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8933EC385A5 for ; Tue, 7 Jun 2022 15:07:14 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="pgo/j+bD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1654614433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=vWufqBDrGEH9oinZg1h9f5R17E0LqWydN8JYgx2Xdps=; b=pgo/j+bDyXeqb0gNlutNsyNm4qrjzM5ZFYa0lUgtfN8x83mIODWIrWrdlrPuqkNcvhuE0B 7X91zGZ9afnWq4w+S5P7eFTHgZxB90YNMBbwTXTPqmchy7oc9s1WKDwQsSTwmBwEWuije9 Ntox4FGjC7tDo5fNAJvTv2vHFaIgldY= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id fa5a6a1a (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Tue, 7 Jun 2022 15:07:12 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" Subject: [PATCH] random: account for arch randomness in bits Date: Tue, 7 Jun 2022 17:07:03 +0200 Message-Id: <20220607150703.880856-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rather than accounting in bytes and multiplying (shifting), we can just account in bits and avoid the shift. The main motivation for this is there are other patches in flux that expand this code a bit, and avoiding the duplication of "* 8" everywhere makes things a bit clearer. Signed-off-by: Jason A. Donenfeld --- drivers/char/random.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 0d6fb3eaf609..60d701a2516b 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -776,7 +776,7 @@ static struct notifier_block pm_notifier =3D { .notifie= r_call =3D random_pm_notifica int __init random_init(const char *command_line) { ktime_t now =3D ktime_get_real(); - unsigned int i, arch_bytes; + unsigned int i, arch_bits; unsigned long entropy; =20 #if defined(LATENT_ENTROPY_PLUGIN) @@ -784,12 +784,12 @@ int __init random_init(const char *command_line) _mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed)); #endif =20 - for (i =3D 0, arch_bytes =3D BLAKE2S_BLOCK_SIZE; + for (i =3D 0, arch_bits =3D BLAKE2S_BLOCK_SIZE * 8; i < BLAKE2S_BLOCK_SIZE; i +=3D sizeof(entropy)) { if (!arch_get_random_seed_long_early(&entropy) && !arch_get_random_long_early(&entropy)) { entropy =3D random_get_entropy(); - arch_bytes -=3D sizeof(entropy); + arch_bits -=3D sizeof(entropy) * 8; } _mix_pool_bytes(&entropy, sizeof(entropy)); } @@ -801,8 +801,8 @@ int __init random_init(const char *command_line) if (crng_ready()) crng_reseed(); else if (trust_cpu) - _credit_init_bits(arch_bytes * 8); - used_arch_random =3D arch_bytes * 8 >=3D POOL_READY_BITS; + _credit_init_bits(arch_bits); + used_arch_random =3D arch_bits >=3D POOL_READY_BITS; =20 WARN_ON(register_pm_notifier(&pm_notifier)); =20 --=20 2.35.1