From patchwork Sun Jul 2 17:35:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 115109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp73165vqx; Sun, 2 Jul 2023 10:43:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHtG0kpp3Gzaqfv7OOnC7xhnNcIKuIsymDakc93v2jp1V6Qa4l+VPe51e3KOkohKYIckgr X-Received: by 2002:a17:902:eb89:b0:1b8:17e8:5482 with SMTP id q9-20020a170902eb8900b001b817e85482mr8978335plg.1.1688319832344; Sun, 02 Jul 2023 10:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688319832; cv=none; d=google.com; s=arc-20160816; b=cZFzZlD/d8PR0qZ3RjZYY13x+VG/vwhQkAaMqEokck21qDLK3QWQkfXoi6H021jPYP t0sajLCvsuWcGsxH6C+3PP1kXHU4IYPvSVeyy1f8XMWCnE70N6HpENO21+WKhXJ1hQ9Q IU7RgiY0SDNjkImWWE4DgeITgLE6Htz/rF5MgQcz/Kf57LcMu7FExl/GGGWvgbduRCzB +WbdrT785/7+pm+UbFnPp10g1JySoY73sdUvtJTCdKuthqbo/e6FTu//Qbqwne31C1/o NqFro4pEGvj6dFeHAxgrmWELWpFOsL7qOAL6Bz0mRE6UnrNfBJg2xARgRS89d6bi7f7b dNFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=v7UTSOtroxWvQVPsquyzcz7aN73plDfq1nu8i6gYMXE=; fh=SqCs7KZ8ytcbnkiRESvNRChZIthYOwhcUjFjEDfWP4k=; b=t68zSkCBiXxgvDyZFKKBHtX8a2kvS+eSqtZrCDe1P5TKGQ/rsDKph36PjFsVBxuNQY dMBVUDL0QblRLdSaAfiMnXF+McEq82ij+1G4oY9xGcS2jTwXaGjfl/TAuh3N6EnI30Y6 s+sTVtkkRNdCVTv1HAPR3kfuXPG9dNvgj3HYenP5TIvF+pxWVIy5agCLBeOEMz4jKNEX PyqIrguNp+EUTqonY9M/3/vgNnjrP66CYAkinhLhPwRVyoR/YNI5x2wbuRWVeCHw4Yli GqlCCwa+nLHfcvsSH/pZzKw9GD+YkspDHVd+S13v8VhOWvbqFgxNcGeEmCjlWkyy8ZHh ejIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c18-20020a170903235200b001b87b716f87si4722782plh.329.2023.07.02.10.43.39; Sun, 02 Jul 2023 10:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjGBRhD (ORCPT + 99 others); Sun, 2 Jul 2023 13:37:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbjGBRhA (ORCPT ); Sun, 2 Jul 2023 13:37:00 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31413E48; Sun, 2 Jul 2023 10:36:58 -0700 (PDT) Received: from dslb-188-097-041-125.188.097.pools.vodafone-ip.de ([188.97.41.125] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1qG10L-0007s9-4K; Sun, 02 Jul 2023 19:36:57 +0200 From: Martin Kaiser To: Herbert Xu Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH 1/2] hwrng: nomadik - keep clock enabled while hwrng is registered Date: Sun, 2 Jul 2023 19:35:02 +0200 Message-Id: <20230702173503.163152-2-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230702173503.163152-1-martin@kaiser.cx> References: <20230702173503.163152-1-martin@kaiser.cx> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770331656585509544?= X-GMAIL-MSGID: =?utf-8?q?1770331656585509544?= The nomadik driver uses devres to register itself with the hwrng core, the driver will be unregistered from hwrng when its device goes out of scope. This happens after the driver's remove function is called. However, nomadik's clock is disabled in the remove function. There's a short timeframe where nomadik is still registered with the hwrng core although its clock is disabled. I suppose the clock must be active to access the hardware and serve requests from the hwrng core. Switch to devm_clk_get_enabled and let devres disable the clock and unregister the hwrng. This avoids the race condition. Fixes: 3e75241be808 ("hwrng: drivers - Use device-managed registration API") Signed-off-by: Martin Kaiser --- I know that the handling of the amba regions has the same problem as the clk. We release the regions while the driver is still registered with the hwrng core... drivers/char/hw_random/nomadik-rng.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/char/hw_random/nomadik-rng.c b/drivers/char/hw_random/nomadik-rng.c index e8f9621e7954..3774adf903a8 100644 --- a/drivers/char/hw_random/nomadik-rng.c +++ b/drivers/char/hw_random/nomadik-rng.c @@ -13,8 +13,6 @@ #include #include -static struct clk *rng_clk; - static int nmk_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) { void __iomem *base = (void __iomem *)rng->priv; @@ -36,21 +34,20 @@ static struct hwrng nmk_rng = { static int nmk_rng_probe(struct amba_device *dev, const struct amba_id *id) { + struct clk *rng_clk; void __iomem *base; int ret; - rng_clk = devm_clk_get(&dev->dev, NULL); + rng_clk = devm_clk_get_enabled(&dev->dev, NULL); if (IS_ERR(rng_clk)) { dev_err(&dev->dev, "could not get rng clock\n"); ret = PTR_ERR(rng_clk); return ret; } - clk_prepare_enable(rng_clk); - ret = amba_request_regions(dev, dev->dev.init_name); if (ret) - goto out_clk; + return ret; ret = -ENOMEM; base = devm_ioremap(&dev->dev, dev->res.start, resource_size(&dev->res)); @@ -64,15 +61,12 @@ static int nmk_rng_probe(struct amba_device *dev, const struct amba_id *id) out_release: amba_release_regions(dev); -out_clk: - clk_disable_unprepare(rng_clk); return ret; } static void nmk_rng_remove(struct amba_device *dev) { amba_release_regions(dev); - clk_disable_unprepare(rng_clk); } static const struct amba_id nmk_rng_ids[] = { From patchwork Sun Jul 2 17:35:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 115110 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp74028vqx; Sun, 2 Jul 2023 10:46:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGy/XuBlL3qmWyMpJAtxazf7uz/zNnIntc4g2JiVsHQV7TL/LnAkTdw6iUQgoBtsJT/Psx2 X-Received: by 2002:a17:90a:2845:b0:263:a5b5:c538 with SMTP id p5-20020a17090a284500b00263a5b5c538mr4978215pjf.4.1688319974534; Sun, 02 Jul 2023 10:46:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688319974; cv=none; d=google.com; s=arc-20160816; b=qMQ0ZwuUHWG1d5hdTGjmlnZaFufERPrPS2ae03YxaloCyM3AiMZFWA1brDeojKBaEB KoNtTbkTCqvjF2g3JZ4chl7H8chKaV2ueJGrjVVk9pTV57XGyE21q9FQYhNJ8FnHKxQC USvUeWNmc0iwuIZlj8NqHhgOZI9HADacXK6LpDnlSCD3Q+9881IfVsWM2wbAlXPWOWYB ge3OvpAn8Meu+9kOMKQPSlSPtBtuDi6lCqFjrnFSyx77ksn3VteZ8RZvjhmi+54AE4kQ 381fUcFCBFBy96qoWtCvHaAZvkecFd5aSQiCu8PtyFNkOhUu7fBZmGwXEH1cmhrCKjo9 vhgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yPM54quByN8fJuUSQfz/VIaSEo/AtH9BflFKPth17HY=; fh=SqCs7KZ8ytcbnkiRESvNRChZIthYOwhcUjFjEDfWP4k=; b=a2ygQ5sOJnE/4iosr+iYrf6GL0cyrix09KLqpQiQ9RQseDvhUO8xUSnD3YOORuF+nR LfztWjU7/9Iz3BqAh7xwT/zbrQf4VGG1suqjq2dmVAlBUb7myNQBCjpQhYEVVTclgY7k wfIr1eMYJOOZ3epZDt/VA1Sd9DbqY0Kv7og0cQSpk+P5KEh5/osDeZH8kOc/2RdVPAoJ W/ruJQgWSdHPK8W+eLK88TuKUj15cUDwCwk1zx3RQp9OTk1er+V1liavcpEUmbFOyFqn t5KM4zdCqUYxqPj4Ubpg4J1Wql04X2SrcAlsFGZtRDO3aekmXmJM/JDJpw/FEMv/vebm sZ3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a63d809000000b0053f8da90675si16170019pgh.598.2023.07.02.10.45.58; Sun, 02 Jul 2023 10:46:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbjGBRhF (ORCPT + 99 others); Sun, 2 Jul 2023 13:37:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbjGBRhC (ORCPT ); Sun, 2 Jul 2023 13:37:02 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51DE0183; Sun, 2 Jul 2023 10:37:01 -0700 (PDT) Received: from dslb-188-097-041-125.188.097.pools.vodafone-ip.de ([188.97.41.125] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1qG10N-0007s9-Rs; Sun, 02 Jul 2023 19:36:59 +0200 From: Martin Kaiser To: Herbert Xu Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH 2/2] hwrng: nomadik - use dev_err_probe Date: Sun, 2 Jul 2023 19:35:03 +0200 Message-Id: <20230702173503.163152-3-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230702173503.163152-1-martin@kaiser.cx> References: <20230702173503.163152-1-martin@kaiser.cx> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770331805796655138?= X-GMAIL-MSGID: =?utf-8?q?1770331805796655138?= Use dev_err_probe to print a message and return an error. This makes the code a tiny bit shorter. Signed-off-by: Martin Kaiser --- drivers/char/hw_random/nomadik-rng.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/char/hw_random/nomadik-rng.c b/drivers/char/hw_random/nomadik-rng.c index 3774adf903a8..8c6a40d6ce3d 100644 --- a/drivers/char/hw_random/nomadik-rng.c +++ b/drivers/char/hw_random/nomadik-rng.c @@ -39,11 +39,8 @@ static int nmk_rng_probe(struct amba_device *dev, const struct amba_id *id) int ret; rng_clk = devm_clk_get_enabled(&dev->dev, NULL); - if (IS_ERR(rng_clk)) { - dev_err(&dev->dev, "could not get rng clock\n"); - ret = PTR_ERR(rng_clk); - return ret; - } + if (IS_ERR(rng_clk)) + return dev_err_probe(&dev->dev, PTR_ERR(rng_clk), "could not get rng clock\n"); ret = amba_request_regions(dev, dev->dev.init_name); if (ret)