Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2173524ybh; Fri, 24 Jul 2020 06:22:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd/xEA2rVHu7PwJr1J4iXtmfO8gIxLMWYtVzicxcSC3uK2J67aRiFFc+It37tmtVZm/edb X-Received: by 2002:aa7:dd14:: with SMTP id i20mr9246652edv.41.1595596975657; Fri, 24 Jul 2020 06:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595596975; cv=none; d=google.com; s=arc-20160816; b=RXjx4NrZ0rZj10FfiLkEPqqiCoonGhWUE1lqfxCNPJahpzwwGKmk78Z/lqhMFkv+ZT GeiJt5fce4RWJJtGyp4WeshkYWUtP5+FNPgOEkzN5S29t0Z3Ug+D5PsveTOfCC8YerQk Q44Xuc6EHR1XT+9PHM73HrEm87QfVbd9lX+ya/THj5idwH58o3pe9e80RCbVQAtbqoyV Rkb9fEBvkjQXvgEhjM1yYGcGG2TZD0WityCCCQPku+VTmTDJh8HNS3ApqR0Sw66O+8Kb xEo45R53S6Ga0Xo3rZ3CcHQHMeIZS+44uMOlnho2mjf4/62Yr59q0NaVRrKugfplp1Yj 7fzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=NRL0UF3/43vslaJwWgTDYbt4jG2vWByUDB6sLPDuLgg=; b=CYNU4KXaGip8Ldiq/jW1976YvehoGIJzxO/u4nIT2qEXhby9MfYjXckBQQHH5GSiDR 0Fzdwsh24FlUiMvHiXIwU1gJV5Qvo1jIgve4T8boflnSkQjVw2mtVD5JLTekzCJt6mGH RzWXEdOBV0/H7OsDXL6bD/2380TfmVbr34Y/ts6ewbzvIHzzb6/fY6ZP4M8rEwbT1q0S /ryXsOuRxgIfhGW/+tqe5PKh1CGIVzIFyIBpeNt2D1WathmTDh2BcdVmHXo00bLR+BZ2 ciwJ2jPKj0PuCl2uSMiXqLWxB6anKfLGovk63eSklWlNvvcDFGCuchU7UKzBf/10osKY 9VVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zGfFL6Gm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si474373eds.173.2020.07.24.06.22.30; Fri, 24 Jul 2020 06:22:55 -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=@linaro.org header.s=google header.b=zGfFL6Gm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726739AbgGXNWV (ORCPT + 99 others); Fri, 24 Jul 2020 09:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbgGXNWU (ORCPT ); Fri, 24 Jul 2020 09:22:20 -0400 Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08A87C0619E4 for ; Fri, 24 Jul 2020 06:22:20 -0700 (PDT) Received: by mail-lf1-x141.google.com with SMTP id s9so5187815lfs.4 for ; Fri, 24 Jul 2020 06:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NRL0UF3/43vslaJwWgTDYbt4jG2vWByUDB6sLPDuLgg=; b=zGfFL6GmKfCKONek4mgXwt+6vzxav2G7E3CLcuQNhfLYOlekFkhc+89MaxLAL7qw3X HCOc3/HQHMtRl9xxbUrickjMs0ht8tRG431uD01gRfGYYmKa5xK7K9tG2cuhV8230kf6 TZPGub5Z/Qm6994apf7zqFR5JT7k/mmb/zuPV3EVQG2Cjy5atgiwXwuMtAegmdOyQ4Dl Muy2DFwUjK8YWKAamgBp0DieYGDljuUJI9aCweRWFLKxqXIGj5zpY6kP654hi8CLwwJ2 kKC1ILn6FXoT+jAdBs7Q/zKSSYq0APnEvjaE2CW1f6xuz08/uOFTak44QG3iKkhJVvz/ izQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NRL0UF3/43vslaJwWgTDYbt4jG2vWByUDB6sLPDuLgg=; b=lbCqdEE/gs051DnlwDGl/t+RrQA6jqBb9id368H6frQmlOUXlciHkUIt0S9RQGmqaJ /P6SqYYqAmyBwj8D1301KePFOhKVMXMnghGGeaGRtF6hEiZXktAlFg5aB6BTNJKr9UoW lYWEx8lVEUmCL5F9lC5elcM6VwPM1v/etLNmBtus5yeuVjgL+kjVWOAvVoXS1tw6np60 mOrucubNkHLxQIfa5lIcmgct/YoeoTEy+3P+fTotmWjNO6owu53xEPup+VDBL16hipjU pdSIQ3eWwWaXMRTqAKqD/uPGNgZVYfWn7e4vU/wMxpxHC7f9dGC39LKBRjvjWjjN44Vz WdgA== X-Gm-Message-State: AOAM531twL7FKPTyO7cX4NDeIQL6CRmaJe+ZHDwH7gUdFKge1b7toJc/ Z2UI5lOhl3dToHYMgEvRB6lA35TSRB9QaLPwvEy27A== X-Received: by 2002:a19:86c3:: with SMTP id i186mr1625844lfd.59.1595596938380; Fri, 24 Jul 2020 06:22:18 -0700 (PDT) MIME-Version: 1.0 References: <20200723084622.31134-1-jorge@foundries.io> <20200723084622.31134-2-jorge@foundries.io> In-Reply-To: <20200723084622.31134-2-jorge@foundries.io> From: Sumit Garg Date: Fri, 24 Jul 2020 18:52:07 +0530 Message-ID: Subject: Re: [PATCHv2 2/2] hwrng: optee: fix wait use case To: Jorge Ramirez-Ortiz Cc: Matt Mackall , Herbert Xu , Jens Wiklander , Arnd Bergmann , ricardo@foundries.io, Michael Scott , Greg Kroah-Hartman , op-tee@lists.trustedfirmware.org, "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, 23 Jul 2020 at 14:16, Jorge Ramirez-Ortiz wrote: > > 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 exits. > > This fix does not wait if all data has been read and reads a second > time if only partial data was retrieved on the first read. > > This fix also does not attempt to read if not data is requested. I am not sure how this is possible, can you elaborate? > > Signed-off-by: Jorge Ramirez-Ortiz > --- > v2: tidy up the while loop to avoid reading when no data is requested > > 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)) If read == max, would there be any sleep? -Sumit > return read; > msleep((1000 * (max - read)) / pvt_data->data_rate); > } else { > -- > 2.17.1 >