Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2715902rwd; Fri, 19 May 2023 09:13:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7o9OGVYNgq+xP9w4syEZn7nJrT0y2dZBcwTap4bc0X/K2tdjPTag6B9WOP4TUp5qghgwk9 X-Received: by 2002:a17:902:c3cc:b0:1ac:94b3:3aaa with SMTP id j12-20020a170902c3cc00b001ac94b33aaamr2814213plj.6.1684512815756; Fri, 19 May 2023 09:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684512815; cv=none; d=google.com; s=arc-20160816; b=KlTxm+fjjp8wpoqp8F9M9Eymgs13fzuEHFoZMX7DBDh76h1doGBndec6TahCtUDA/C E+P4yjad/Nf5xaveHBGQ9R5W3+jdGOfZpu0oikE/zhCxx72wddtM2L3SN/CVOaIWi1SH Vwh7Oo7iE1/Z0B4RxthRW8d582dFMs2dnfnKZrWQGUfT3UKOZy5xNVljdhsmuCaUF5Uh H0rGwhh8qR6XNADQFV8LjdYtE16+SCj/4a4Yd6DRrF4YKIopD9YANCBvQdHFM0C3QiYb BmrqDqErLmJhtz7jYpCzvi4iN4v8rWD3JbU1tMyqbha51MR3fQklYMJZHthLvdJ9ibrv X8Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3X/KbCrm7Ku674Hj6AITqyLbyWd77+1V3G/mXM5JuRI=; b=aK/XiUk4IJTJOMqtqr6rKuceGKhZrEIL6b19OGnbbD38wNDMXr/mfGF+DA040mmpeq +APllHAq/5YC+b0e/MxMpMKk5dDzaooGAzuUXEGc6AzyekbdIZI33yupDnNHpmUtvqWT IZe1FUVR1efc3D9iGINyV2AaiYiYRVwU5EjH4yG1AnEOAXHI7NYJ9pEpZk06ZmynFVC+ M5zPgNEGvT+bYrVwUhXvvnv0HxsDmVj45Vv2KfaClFgMWI0ykzlGcEtt/ByYn/g9MhRP sXODGwKJwnqcuGYraVwo2/v0i0ntedM2o/cQXTJK1LEGFVhXuXYaL71d0uXDHZ+3M1CZ eGKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l1-20020a170902f68100b001ae6112dcecsi4024573plg.294.2023.05.19.09.13.22; Fri, 19 May 2023 09:13:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229526AbjESQFf (ORCPT + 99 others); Fri, 19 May 2023 12:05:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjESQFe (ORCPT ); Fri, 19 May 2023 12:05:34 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BDECC9; Fri, 19 May 2023 09:05:32 -0700 (PDT) Received: from ipservice-092-217-072-086.092.217.pools.vodafone-ip.de ([92.217.72.86] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1q02bg-0001Ah-Vs; Fri, 19 May 2023 18:05:29 +0200 From: Martin Kaiser To: Herbert Xu Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH v2 1/3] hwrng: imx-rngc - simpler check for available random bytes Date: Fri, 19 May 2023 18:04:31 +0200 Message-Id: <20230519160433.287161-2-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230519160433.287161-1-martin@kaiser.cx> References: <20230427185357.923412-1-martin@kaiser.cx> <20230519160433.287161-1-martin@kaiser.cx> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The "level" field in the status register contains the number of random bytes that are available in the FIFO. Use GENMASK to extract this field. We only want to check if level is 0 or if we can read another byte. There's no need for the shift or the level variable. Signed-off-by: Martin Kaiser --- v2: - remove the shift when checking the fifo level field drivers/char/hw_random/imx-rngc.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c index a1c24148ed31..cf29c323453a 100644 --- a/drivers/char/hw_random/imx-rngc.c +++ b/drivers/char/hw_random/imx-rngc.c @@ -17,6 +17,7 @@ #include #include #include +#include #define RNGC_VER_ID 0x0000 #define RNGC_COMMAND 0x0004 @@ -44,8 +45,7 @@ #define RNGC_CTRL_AUTO_SEED 0x00000010 #define RNGC_STATUS_ERROR 0x00010000 -#define RNGC_STATUS_FIFO_LEVEL_MASK 0x00000f00 -#define RNGC_STATUS_FIFO_LEVEL_SHIFT 8 +#define RNGC_STATUS_FIFO_LEVEL_MASK GENMASK(11, 8) #define RNGC_STATUS_SEED_DONE 0x00000020 #define RNGC_STATUS_ST_DONE 0x00000010 @@ -122,7 +122,6 @@ static int imx_rngc_read(struct hwrng *rng, void *data, size_t max, bool wait) { struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); unsigned int status; - unsigned int level; int retval = 0; while (max >= sizeof(u32)) { @@ -132,11 +131,7 @@ static int imx_rngc_read(struct hwrng *rng, void *data, size_t max, bool wait) if (status & RNGC_STATUS_ERROR) break; - /* how many random numbers are in FIFO? [0-16] */ - level = (status & RNGC_STATUS_FIFO_LEVEL_MASK) >> - RNGC_STATUS_FIFO_LEVEL_SHIFT; - - if (level) { + if (status & RNGC_STATUS_FIFO_LEVEL_MASK) { /* retrieve a random number from FIFO */ *(u32 *)data = readl(rngc->base + RNGC_FIFO); -- 2.30.2