Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1238654pxa; Thu, 6 Aug 2020 03:06:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJws46pXXYp+Ang0OBjc5+4rzAaREuCR+L06PNE2A/Jf78SjJ/EYJBghjIkmw+EXYPiK6Zwl X-Received: by 2002:a17:906:288d:: with SMTP id o13mr3378599ejd.199.1596708392341; Thu, 06 Aug 2020 03:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596708392; cv=none; d=google.com; s=arc-20160816; b=hNi8Q0giWZcQXis3DxcVenqLFHt0gM4nnywBx5Kv3zlzFJHmBoQHLvwN4SpULp/Bxr ztPySC6rlePk10RvBlPHKkMofr8mNzUnECIm0xd2XdLGB/LfCnMBlJSLqmKNAPhcNm1B a0BKL2sIbsbC5bInNUH6mz7bMoJ7QEq23ZmSKdGKETXbbsgp63vx4guATQ4WmAbhkmYU P7nocxKFWxM6HIJMlxiD9i+bQ38iW2S06j9WSFYMG8oZd+U06lfLggbRvBkl18HIKOQl UMFEkGEpiCGkScoWjta6RfJZWDMUWOqw4tJH+pGYNul5KtGDxpcQBUf5epYTQu80xCaH pZuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=IjCAb6ElutCFPhXtiRRhexkYUeHi/3Oyyo9f5qPCuTw=; b=vu7puI74bwlMwXNQeNM4FYM/MRkLTHo8YAeYwTfGWPdrdUdy0ev+/RS/iRhSi4/fyI 26IHzz46UsLba0GA5C10MGoWMVkUXksBJIR3H1HjhaFgBYa/AAKfsSqbqNyd/pCUWzwo MHe9vymOo2mQ5waCsGxKZKhWH+Ya4apD8y5ltko42ft/SZb6YyRbB1DUrlwTaQvA2IxO BOMmZK8hZwyXJbl8trgxux4S8VIozN2XZYxgllxqOKrwXpHu9WCw4gasCW6QR9ITCjwU Z+WvCp2+/Dz/wZh+qjOBg/69yYBGx4KPbrGuP4E3Ue7bgep9HiOyJ0UUHe84aSNDIqbA 061Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foundries-io.20150623.gappssmtp.com header.s=20150623 header.b=07ssaopV; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di27si1670277edb.195.2020.08.06.03.06.07; Thu, 06 Aug 2020 03:06:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@foundries-io.20150623.gappssmtp.com header.s=20150623 header.b=07ssaopV; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729322AbgHFKC2 (ORCPT + 99 others); Thu, 6 Aug 2020 06:02:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729311AbgHFKAg (ORCPT ); Thu, 6 Aug 2020 06:00:36 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B283DC06179F for ; Thu, 6 Aug 2020 03:00:16 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id r4so40420155wrx.9 for ; Thu, 06 Aug 2020 03:00:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foundries-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IjCAb6ElutCFPhXtiRRhexkYUeHi/3Oyyo9f5qPCuTw=; b=07ssaopVlpy25M08Sfu8/Ed2KaEWKD7qpGWYm9QQsMA5sjGrjsDEg2rNUkOkeFqb+W E51HB2POCciK3fXe+LVmMAMbYu+08znf/dSU3+QzzliE3YIlxf3l/aiFYRCF/nzSJmbe nZI4TjWfA9aCvbvYAlnZyBtmW5qh5/PkFnRL6V1I+Cc/7PQ/Ine1LrRKCEfcvBuYRsdg 0fRn19HfsnOyGGVrutacfiZkr1jXoQ4B5spsLH61a490BqxKsYA5R40F9Iglc+bSC4jM MhicEySUJqULV14ucCB1y29WSWTHVjAZiO8d2/r9fgaPcvewP8SLBg1vxsxwSa4B0FgL 1BBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IjCAb6ElutCFPhXtiRRhexkYUeHi/3Oyyo9f5qPCuTw=; b=O97IbNfNt86HCf6cXiLSMHrsu++3WqiXvQDMP3UEcw7sqUfBwDYPRQDHM21/542MAI 7AI/RQA5Awbjot9r4ozgZUbo37dPDE1kXu2E+xAZ7/CM21rv/xtrfBqA/zewIhzhTcSS GDjih2laroukP5py/lYneLOO55ciep0r8tW4k/nRn69j7XGcN+1iTeH5NNhw+oIthxWR pux/hiWjIZvqkZQqGY8sHSS2iY3LDfj+qW0Jcls+4cf7rO31A13Uw2v5BFCKfp/Srmu0 HnTOdUuJW87cpN0KnfqzhculO3ONRUps2lfXJMgQODWzxE7SLwqytYhcX/pG02sN9lp4 GeJw== X-Gm-Message-State: AOAM533gyTFR6gY5Hk1wY/XCSzDebAB2PeoGcTK0alTSBB+9gnIJaGNd GjihlBlMlo5G9cxvSWMn+ypvXA== X-Received: by 2002:a5d:6744:: with SMTP id l4mr7288655wrw.105.1596708015448; Thu, 06 Aug 2020 03:00:15 -0700 (PDT) Received: from localhost.localdomain (239.red-83-34-184.dynamicip.rima-tde.net. [83.34.184.239]) by smtp.gmail.com with ESMTPSA id p3sm5741376wma.44.2020.08.06.03.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 03:00:15 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge@foundries.io, sumit.garg@linaro.org, jens.wiklander@linaro.org Cc: mpm@selenic.com, herbert@gondor.apana.org.au, arnd@arndb.de, ricardo@foundries.io, mike@foundries.io, gregkh@linuxfoundation.org, op-tee@lists.trustedfirmware.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv3 2/2] hwrng: optee: fix wait use case Date: Thu, 6 Aug 2020 12:00:10 +0200 Message-Id: <20200806100010.20509-2-jorge@foundries.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806100010.20509-1-jorge@foundries.io> References: <20200806100010.20509-1-jorge@foundries.io> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The current code waits for data to be available before attempting a second read. However the second read would not be executed as the while loop will exit. This fix does not wait if all data has been read (skips the call to msleep(0)) and reads a second time if partial data was retrieved on the first read. Worth noticing that since msleep(0) schedules a one jiffy timeout is better to skip such a call. Signed-off-by: Jorge Ramirez-Ortiz Reviewed-by: Sumit Garg --- drivers/char/hw_random/optee-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/optee-rng.c b/drivers/char/hw_random/optee-rng.c index 5bc4700c4dae..a99d82949981 100644 --- a/drivers/char/hw_random/optee-rng.c +++ b/drivers/char/hw_random/optee-rng.c @@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) if (max > MAX_ENTROPY_REQ_SZ) max = MAX_ENTROPY_REQ_SZ; - while (read == 0) { + while (read < max) { rng_size = get_optee_rng_data(pvt_data, data, (max - read)); data += rng_size; read += rng_size; if (wait && pvt_data->data_rate) { - if (timeout-- == 0) + if ((timeout-- == 0) || (read == max)) return read; msleep((1000 * (max - read)) / pvt_data->data_rate); } else { -- 2.17.1