From patchwork Mon Feb 1 15:14:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Henrik Weinstock X-Patchwork-Id: 374329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C53CEC433E0 for ; Mon, 1 Feb 2021 15:18:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8751664E97 for ; Mon, 1 Feb 2021 15:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230022AbhBAPRU (ORCPT ); Mon, 1 Feb 2021 10:17:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbhBAPQs (ORCPT ); Mon, 1 Feb 2021 10:16:48 -0500 X-Greylist: delayed 62 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 01 Feb 2021 07:16:07 PST Received: from mail-out-2.itc.rwth-aachen.de (mail-out-2.itc.rwth-aachen.de [IPv6:2a00:8a60:1:e501::5:47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC787C061573 for ; Mon, 1 Feb 2021 07:16:07 -0800 (PST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2D+CwBvGhhg/5oagoZiHgEBCxIMg2KBeixlhECRKZxzCwEBAQEBAQEBAQQEAS0CBAEBhkQCJTgTAhABAQYBAQEBAQYEhl+GHQSBLwIEWwEMBgIBAYMiAYJ3DwGwUH8ziRuBNBAJAYEugVOMEYFcP4E4D4MhhAWDUoJgBIJHdBq7XQeBaIERhGKCapQlBSmTJY9tAS2TfZU8jCsCAgICCQIWgW2Bek0kXAmCU1AXAg2OLReNawE7QTI3AgYKAQEDCXyIU4JGAQE X-IPAS-Result: A2D+CwBvGhhg/5oagoZiHgEBCxIMg2KBeixlhECRKZxzCwEBAQEBAQEBAQQEAS0CBAEBhkQCJTgTAhABAQYBAQEBAQYEhl+GHQSBLwIEWwEMBgIBAYMiAYJ3DwGwUH8ziRuBNBAJAYEugVOMEYFcP4E4D4MhhAWDUoJgBIJHdBq7XQeBaIERhGKCapQlBSmTJY9tAS2TfZU8jCsCAgICCQIWgW2Bek0kXAmCU1AXAg2OLReNawE7QTI3AgYKAQEDCXyIU4JGAQE X-IronPort-AV: E=Sophos;i="5.79,392,1602540000"; d="p7s'?scan'208";a="133954439" Received: from rwthex-s2-a.rwth-ad.de ([134.130.26.154]) by mail-in-2.itc.rwth-aachen.de with ESMTP; 01 Feb 2021 16:15:02 +0100 Received: from [IPv6:2a02:908:1089:e060:bd31:5e5a:6687:b1da] (2a02:908:1089:e060:bd31:5e5a:6687:b1da) by rwthex-s2-a.rwth-ad.de (2a00:8a60:1:e500::26:154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2044.4; Mon, 1 Feb 2021 16:14:58 +0100 From: Jan Henrik Weinstock Subject: [PATCH] hw_random/timeriomem-rng: Fix cooldown period calculation To: , , , , "Jan Henrik Weinstock" Date: Mon, 1 Feb 2021 16:14:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 X-Originating-IP: [2a02:908:1089:e060:bd31:5e5a:6687:b1da] X-ClientProxiedBy: rwthex-w1-b.rwth-ad.de (2a00:8a60:1:e500::26:157) To rwthex-s2-a.rwth-ad.de (2a00:8a60:1:e500::26:154) Message-ID: <947aa0ab-1f0c-44d6-943a-cf83a56ac5b8@rwthex-s2-a.rwth-ad.de> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Ensure cooldown period tolerance of 1% is actually accounted for. Signed-off-by: Jan Henrik Weinstock --- Before patch, if period_us was less than 100us, no extra sleep time was added. If it was more than 100us, only 1us extra time (and not 1%) is slept. drivers/char/hw_random/timeriomem-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) retval += sizeof(u32); diff --git a/drivers/char/hw_random/timeriomem-rng.c b/drivers/char/hw_random/timeriomem-rng.c index e262445fe..f35f0f31f 100644 --- a/drivers/char/hw_random/timeriomem-rng.c +++ b/drivers/char/hw_random/timeriomem-rng.c @@ -69,7 +69,7 @@ static int timeriomem_rng_read(struct hwrng *hwrng, void *data, */ if (retval > 0) usleep_range(period_us, - period_us + min(1, period_us / 100)); + period_us + max(1, period_us / 100)); *(u32 *)data = readl(priv->io_base);