From patchwork Fri Jun 16 08:36:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 108931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1180796vqr; Fri, 16 Jun 2023 01:52:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4gbl5Q4PMRwn3HaSBLNmbELiaZuXwP5qHI5uI8KlNBsgGCnTiiDiSrOIkjdlxYGeoDfQ++ X-Received: by 2002:a17:90a:7641:b0:25b:ca75:8f44 with SMTP id s1-20020a17090a764100b0025bca758f44mr1062438pjl.4.1686905549193; Fri, 16 Jun 2023 01:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686905549; cv=none; d=google.com; s=arc-20160816; b=cTID3Lm+vF1lb0FOABFvCO39vAv4aeSur5qPhX3UyxEWGUtLevg16O4PPusMYN6p0n LlLJddYOcI0YaQtIx/vEUsKrQpADyH8FQ0e/AsCSLmvPzepCU9gxHLzCCv8ndo70g6ND pJKsBJp4UJlis9z/jMLZ2tNKBKztLzxKGS2zjVYqz0jZfwoedvxL1FmPJomQB7FR3slb ASCPwwD4fTnxM4sGcC0+ilEoCSdfyNOpTh0PIsveifzxuNsqEbeRp55gqhOqycfRUD7/ 0EKtohJ6UQrSIYO4HWFhKo/PU56+5aS4eVpPRG3Eq+MtmkFMEOjTxBhPs8ENb23NYwt6 gT7g== 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=0dqlqltfb+eA0HK9C+h3BSlAItrQzz+SAzoTPEuzFqY=; b=vAikBUXreb8VGPNW0FCmMwjxmj3G2R09ukf3JatFSm6hmRDxpTQ4SchE35e0ZcAuEI uaGKuibNIDZ/QZrceSh44q/0J/LcDEM+SVGUVu0VeCWaZIDXtEhaNoPSjBV0ZTw2y6Fb JLlxw+5wTR16IynyTATvw5+SnKKdWxglhUfrYI4sQN0DsetkRfjXff5wjwUUQoSYJOLI toszTlcYAL482hJNQkBAhiS6uHukTxUllQtYejeD/JNg8JHqKr/7eLakSBSsJXWBpGpZ 4mskNw7pVJugQoV8UMvBzZ2sXcK5jwoWJCT4MpzQQmUQWVver3cIgP/GiyH4gTEAukNn i5nw== 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 pc16-20020a17090b3b9000b002465d98f18csi1179689pjb.170.2023.06.16.01.52.15; Fri, 16 Jun 2023 01:52:29 -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 S245623AbjFPIhq (ORCPT + 99 others); Fri, 16 Jun 2023 04:37:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245465AbjFPIhk (ORCPT ); Fri, 16 Jun 2023 04:37:40 -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 077A7194; Fri, 16 Jun 2023 01:37:38 -0700 (PDT) Received: from [167.98.155.120] (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 1qA4xd-0000Wd-Ig; Fri, 16 Jun 2023 10:37:37 +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: st - support compile-testing Date: Fri, 16 Jun 2023 09:36:17 +0100 Message-Id: <20230616083618.1320824-2-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230616083618.1320824-1-martin@kaiser.cx> References: <20230616083618.1320824-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?1768848672844306048?= X-GMAIL-MSGID: =?utf-8?q?1768848672844306048?= Allow compile-testing the st-rng driver if we're not running on an ST chipset. Signed-off-by: Martin Kaiser --- drivers/char/hw_random/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index baefa2e0edbc..e0b3786ca51b 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -348,7 +348,7 @@ config HW_RANDOM_HISTB config HW_RANDOM_ST tristate "ST Microelectronics HW Random Number Generator support" - depends on HW_RANDOM && ARCH_STI + depends on HW_RANDOM && (ARCH_STI || COMPILE_TEST) help This driver provides kernel-side support for the Random Number Generator hardware found on STi series of SoCs. From patchwork Fri Jun 16 08:36:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 108930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1180352vqr; Fri, 16 Jun 2023 01:51:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6k+b0XteF0nwPO2Sw6rnTnn+h3JPQxJ0S6lW1XOZU/NAKNeMevEkGGOxWnZITn8PkbGMde X-Received: by 2002:a05:620a:470d:b0:75e:b8b0:a4b2 with SMTP id bs13-20020a05620a470d00b0075eb8b0a4b2mr1156939qkb.69.1686905475228; Fri, 16 Jun 2023 01:51:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686905475; cv=none; d=google.com; s=arc-20160816; b=rDKikF8lueugk/15C5qs0/uEr9TyFAw1/D5SPu05I4IiIMPNDmgZvYbhipyrHUbfAr oV4jNbi9A+Cu56HAaJBITd/X3/JKFE5wOUiXUYAMvi+KOimhRQLxhuuQg4IuaLW94OV1 03tSJUU8J6b9BTwQp2l0KSXB3jpA3DlPdlz4R7Ev6uzN7lYZxPJlH+EhemvupaAhvqBU hKnVyykgndMPEvE481SFxLdxFQxaLN57c+OsFANb7RvfZIapgC4L2Dn/SQHO29epwwNZ W8d/Aeo5oeTi4cMjJTCCsbI5zopwbtlP1jriVDexYLFqEYT3Mc3LFCgoK+2ds0/4nLQ3 lTTg== 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=jHKC03D6iiF76v0tUWDqWxpPyrXmk4xr5Pvuhb2O3M8=; b=lRUvWSs0ogjswowQQp1V1NJ2/LDMsMz3MGyWxnOpt+e8Mp2Oq+s0HBANk6HH0teDdZ 2itEaidOmGZkdWsakZ0b9BTNbhUHVC1KDGgP204Qd0W8l2gX3mKDb/uNWGEHrI9K0uX/ nLJKkYk+miAdryw43kLiNkVD+vpSAf6gSSc4gaXDz/qUX51lj3vYLYu7XI8XzAk2vRyJ oGQSO9rKAKex+LSJQpKZj9QS4GGY8dwD6op67J4AtnpHJEgGc6KVGi3bvF+lWIAIl5qA fthDGKBtzo3E7L+4lcH+pSteboLool291zf2vFsub+4aohCbayxRx5pT61jTZY/9pV0C 3plA== 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 24-20020a631258000000b0050726756edesi11109125pgs.76.2023.06.16.01.51.02; Fri, 16 Jun 2023 01:51:15 -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 S245423AbjFPIhu (ORCPT + 99 others); Fri, 16 Jun 2023 04:37:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245619AbjFPIho (ORCPT ); Fri, 16 Jun 2023 04:37:44 -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 30672194; Fri, 16 Jun 2023 01:37:41 -0700 (PDT) Received: from [167.98.155.120] (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 1qA4xg-0000Wd-Io; Fri, 16 Jun 2023 10:37:40 +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: st - keep clock enabled while hwrng is registered Date: Fri, 16 Jun 2023 09:36:18 +0100 Message-Id: <20230616083618.1320824-3-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230616083618.1320824-1-martin@kaiser.cx> References: <20230616083618.1320824-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,URIBL_BLOCKED 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?1768848595634279743?= X-GMAIL-MSGID: =?utf-8?q?1768848595634279743?= The st-rng 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, st-rng's clock is disabled in the remove function. There's a short timeframe where st-rng 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 handle both clock and hwrng registration. This avoids the race condition. Fixes: 3e75241be808 ("hwrng: drivers - Use device-managed registration API") Signed-off-by: Martin Kaiser --- drivers/char/hw_random/st-rng.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/drivers/char/hw_random/st-rng.c b/drivers/char/hw_random/st-rng.c index 15ba1e6fae4d..7a4e439d34d7 100644 --- a/drivers/char/hw_random/st-rng.c +++ b/drivers/char/hw_random/st-rng.c @@ -42,7 +42,6 @@ struct st_rng_data { void __iomem *base; - struct clk *clk; struct hwrng ops; }; @@ -85,19 +84,14 @@ static int st_rng_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); - clk = devm_clk_get(&pdev->dev, NULL); + clk = devm_clk_get_enabled(&pdev->dev, NULL); if (IS_ERR(clk)) return PTR_ERR(clk); - ret = clk_prepare_enable(clk); - if (ret) - return ret; - ddata->ops.priv = (unsigned long)ddata; ddata->ops.read = st_rng_read; ddata->ops.name = pdev->name; ddata->base = base; - ddata->clk = clk; dev_set_drvdata(&pdev->dev, ddata); @@ -113,15 +107,6 @@ static int st_rng_probe(struct platform_device *pdev) return 0; } -static int st_rng_remove(struct platform_device *pdev) -{ - struct st_rng_data *ddata = dev_get_drvdata(&pdev->dev); - - clk_disable_unprepare(ddata->clk); - - return 0; -} - static const struct of_device_id st_rng_match[] __maybe_unused = { { .compatible = "st,rng" }, {}, @@ -134,7 +119,6 @@ static struct platform_driver st_rng_driver = { .of_match_table = of_match_ptr(st_rng_match), }, .probe = st_rng_probe, - .remove = st_rng_remove }; module_platform_driver(st_rng_driver);