Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7408536rwl; Mon, 9 Jan 2023 23:54:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRojAIYTZ2EHF9l4qRtP8J0SorRWPxVTO6KiarbBtvsKpJBcqNmEqMzA0Kk38PVxC0LjWH X-Received: by 2002:a17:90b:48c3:b0:226:cefc:270d with SMTP id li3-20020a17090b48c300b00226cefc270dmr16815843pjb.5.1673337277304; Mon, 09 Jan 2023 23:54:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673337277; cv=none; d=google.com; s=arc-20160816; b=YuD6znGhhYUR394EOKl6DVi7chJzUx9qiP7EXJTAjyb4qjzUYy4vkDt3xPgZztgifg lE44oVm8b2PnGVDEwyRfitzmuj2mqCCYP8Hn7FAJI5xEgUb28VIhBxkJGEUlktRWb7Ny IMewhcTUFNym3SSlqFL6W+1vweUApmXV3mWh2YwD9gboxzleqUVBVb2PVU9Hxm8QS3CV KEkOhTJLuATQoXc2AFLH1MImvnpakEIzj6F/CgvYNTWSo3foQ3NOXhptSW05xFdWrB+O j9AWeqiZ1NjMNl2853dWVsgKfJU9PDBt3IM25S0+mllphdyOE4lXi2H7fPegTQnY7RyR Ou2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=+VIm5CeeLau673vlzqeUDoX6Zk7fFKyQV8pg8bsDmEs=; b=q4ZI/8GOU/jc4FSk6PkyTC+IE362tL3ev4o2lWBVEBFuwqWnunp2WnaKfrrkZdXV0n U+0auD7u6xH1iTnBVctLv7pmK/ts8IhoqkPqlyL6sjfMhEeWLlmuGESlpx3zH50IwqgU IIxwQo7tnl2ClSCA5VaB/vIcFU/t1ecn0YbYeLY57/qx+vFftmoEr1CVSbthNfJEswmm 4mEvfejLl87q1gOSVwhAey1hvl6hV4N0VooS9vrzvsYLY83fDZ0aT5kyQZsNvWl5ceyu 9Ma2AMljvPa/rvCf8obfz+GbJFxfrvlXxE8aGTEdzzM5nnASdr+Fwf0Nuz5Skl6PS2K9 YhgQ== 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 gl14-20020a17090b120e00b002262a74af32si10808402pjb.40.2023.01.09.23.54.22; Mon, 09 Jan 2023 23:54:37 -0800 (PST) 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 S231182AbjAJHlT (ORCPT + 99 others); Tue, 10 Jan 2023 02:41:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbjAJHlS (ORCPT ); Tue, 10 Jan 2023 02:41:18 -0500 Received: from formenos.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98E3D17595; Mon, 9 Jan 2023 23:41:16 -0800 (PST) Received: from loth.rohan.me.apana.org.au ([192.168.167.2]) by formenos.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1pF9FZ-00FwmE-1Y; Tue, 10 Jan 2023 15:40:50 +0800 Received: by loth.rohan.me.apana.org.au (sSMTP sendmail emulation); Tue, 10 Jan 2023 15:40:49 +0800 Date: Tue, 10 Jan 2023 15:40:49 +0800 From: Herbert Xu To: Jia Jie Ho Cc: Olivia Mackall , Rob Herring , Krzysztof Kozlowski , Emil Renner Berthing , Conor Dooley , linux-crypto@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v3 2/3] hwrng: starfive - Add TRNG driver for StarFive SoC Message-ID: References: <20230109165249.110279-1-jiajie.ho@starfivetech.com> <20230109165249.110279-3-jiajie.ho@starfivetech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230109165249.110279-3-jiajie.ho@starfivetech.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 On Tue, Jan 10, 2023 at 12:52:48AM +0800, Jia Jie Ho wrote: > > +static irqreturn_t starfive_trng_irq(int irq, void *priv) > +{ > + u32 status; > + struct starfive_trng *trng = (struct starfive_trng *)priv; > + > + status = readl(trng->base + STARFIVE_ISTAT); > + if (status & STARFIVE_ISTAT_RAND_RDY) { > + writel(STARFIVE_ISTAT_RAND_RDY, trng->base + STARFIVE_ISTAT); > + complete(&trng->random_done); > + } > + > + if (status & STARFIVE_ISTAT_SEED_DONE) { > + writel(STARFIVE_ISTAT_SEED_DONE, trng->base + STARFIVE_ISTAT); > + complete(&trng->reseed_done); > + } > + > + if (status & STARFIVE_ISTAT_LFSR_LOCKUP) { > + writel(STARFIVE_ISTAT_LFSR_LOCKUP, trng->base + STARFIVE_ISTAT); > + /* SEU occurred, reseeding required*/ > + writel(STARFIVE_CTRL_EXEC_RANDRESEED, trng->base + STARFIVE_CTRL); This could occur at the same time as a GENE_RANDNUM write so perhaps you should add some locking? > + ret = devm_request_irq(&pdev->dev, irq, starfive_trng_irq, 0, pdev->name, > + (void *)trng); > + if (ret) > + return dev_err_probe(&pdev->dev, irq, > + "Failed to register interrupt handler\n"); ... > + init_completion(&trng->random_done); > + init_completion(&trng->reseed_done); These completion initialisations should be moved above the IRQ registration because you should always be prepared to get spurious interrupts. Otherwise the patch looks good. Thanks, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt