From: PrasannaKumar Muralidharan Subject: Re: [PATCH] hwrng: do not warn when there are no devices Date: Fri, 12 May 2017 13:49:52 +0530 Message-ID: References: <20170512041734.31945-1-vapier@gentoo.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Cc: Mike Frysinger , Matt Mackall , Herbert Xu , linux-crypto@vger.kernel.org To: Mike Frysinger Return-path: Received: from mail-ua0-f177.google.com ([209.85.217.177]:32855 "EHLO mail-ua0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756237AbdELITx (ORCPT ); Fri, 12 May 2017 04:19:53 -0400 Received: by mail-ua0-f177.google.com with SMTP id e28so42720822uah.0 for ; Fri, 12 May 2017 01:19:53 -0700 (PDT) In-Reply-To: Sender: linux-crypto-owner@vger.kernel.org List-ID: On 12 May 2017 at 13:17, Mike Frysinger wrote: >> Completely untested patch below. Will something like this work? >> >> --- a/drivers/char/hw_random/tpm-rng.c >> +++ b/drivers/char/hw_random/tpm-rng.c >> @@ -35,7 +35,13 @@ static int tpm_rng_read(struct hwrng *rng, void >> *data, size_t max, bool wait) >> >> static int __init rng_init(void) >> { >> - return hwrng_register(&tpm_rng); >> + struct tpm_chip *tpm_rng_chip = tpm_chip_find_get(TPM_ANY_NUM); >> + if (tpm_chip) { >> + tpm_put_ops(tpm_rng_chip); >> + return hwrng_register(&tpm_rng); >> + } >> + >> + return -ENODEV; >> } >> module_init(rng_init); > > keep in mind that TPMs are often on slow buses like I2C, so i suspect > rng_init runs before those have been initialized. so this patch would > break them. > > it would also break if the tpm drivers are modules that don't get > loaded until later, but tpm-rng is built in. or tpm-rng is loaded > first. Hmm. I am not aware of the tpm hardware or driver behavior. Based on your explanation I see that this patch is not useful. It looks like it is possible to detect the presence of tpm device and call hwrng_register once the corresponding driver is loaded. I leave it to Herbert to decide whether to accept this patch in current form or not. Regardless of whether this patch gets accepted or not I can work on a better fix if you can provide instructions on how to setup and use tpm. But that will be only after a couple of months. Regards, PrasannaKumar