From patchwork Fri Jun 16 08:58:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 108970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1196091vqr; Fri, 16 Jun 2023 02:27:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7d1fXr4Lhn1Gk6URxh2MHX3ooYx+DEzume+h9tf0A/DqOiddPbjt7HmKQbhyt8ZOxh248Z X-Received: by 2002:a9d:63d0:0:b0:6b2:dd5b:8c1a with SMTP id e16-20020a9d63d0000000b006b2dd5b8c1amr1888974otl.32.1686907657889; Fri, 16 Jun 2023 02:27:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686907657; cv=none; d=google.com; s=arc-20160816; b=aGJJPUDUeUhdLveCyhaCOt1PcSiHzcM3CPL7undEjXAo/nAJfO5BEK0PcEYRdGSKzD HdY+iqylZmE7PT2v8pwn3QvYOBRnbDdsYg4ah5IYNCHxJ4VnpOwdHYn1LQ35/6V/3pOY 3+hrC7ZrVK+V+9+O6606XbC7wC3oeoNKcwr2+55G94bLiNei8HVmp7xmhcL5f/NNdxlw UjhFt89vvLogI6X+h8bWmoCyfGOGKooL8eFEJIuUOVVP64AEo7Ywsf+sbrAUgX8Zu/2k 81Te/HOo19N9bZBEAPGKqxPaYK7pVQ2DYQ6cIvfNwbK8OC2Mg2g5A5AOaxjYVO5oQrRm 4TYA== 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=uv8fkDW7kRD45N6HMFaRb7Gj2oU10mMKyixfXcXAsY/geo3uNkt49xH6nFqrrMVlk3 tb+dOpsXZibJUj4Yr//fwAvISiNcV0ZQ7GTzAumnA5qUSZkyMYIRNb36n5SElbI17+wt FwW5OxU+LtBsu7wdigGt5WIKzEfS49qT6VyCvuVAVG+SZDLOx10eGeZjtMQuYtebkaj+ ncQv6MncHX4sfDTVM3wAkv++x1clqzZLQ9dhHU+hLmFYw4nfQdYGquHsL3KR/9iMzINp IeMFtXsWyrqtZaA632iqVN8mI5mTG36E81isLBTCojt+Cwd0sZz8PTAXsmwTYa/jnNkd /nAQ== 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 l128-20020a633e86000000b005533f9527c2si1039136pga.433.2023.06.16.02.27.22; Fri, 16 Jun 2023 02:27:37 -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 S1344210AbjFPJBE (ORCPT + 99 others); Fri, 16 Jun 2023 05:01:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343904AbjFPI7t (ORCPT ); Fri, 16 Jun 2023 04:59:49 -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 8115E30D5; Fri, 16 Jun 2023 01:59:39 -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 1qA5Iv-0000d1-Bl; Fri, 16 Jun 2023 10:59: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 v2 1/2] hwrng: st - support compile-testing Date: Fri, 16 Jun 2023 09:58:12 +0100 Message-Id: <20230616085813.1323082-2-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230616085813.1323082-1-martin@kaiser.cx> References: <20230616083618.1320824-1-martin@kaiser.cx> <20230616085813.1323082-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?1768850884172455309?= 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:58:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 108955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1188998vqr; Fri, 16 Jun 2023 02:11:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4aL3gI9MEC8kt6/8zb22TNE2l1shI1Or9z7z67qxFYHOGFv/5cW7DjvwtmUs8rcAI3Xule X-Received: by 2002:a05:6a21:338a:b0:106:4197:b7ff with SMTP id yy10-20020a056a21338a00b001064197b7ffmr1897224pzb.30.1686906661665; Fri, 16 Jun 2023 02:11:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686906661; cv=none; d=google.com; s=arc-20160816; b=WnZYxUXqAO6hq2B9Dz7CK4p5V3qmfWz79kCpMqMrX31DYwxplG6TVbF+WjIBayA5YT A3GWxKzvUC38k9B8ieVd/UZ1AtaJr3BeqqoL9iz8hy+iz/DWHQtCEGs4xVYIWtrLURQG r3QYFZtLE1IjZOXTbH1am5puNWF9BX8Qw/URA1aMNY1qQr23oUmiEvO/1v4BDoZzX1u5 d4ohawTWx6TE1blYTEP0Ly8QtGuDWuw/NuGHOhUDwh5TROcdaVZW0tmQg9yLd4ZylcW4 JbOj7P9P9RVnrIQHDwM6hPEn54KoWfmHx4qdpDmx4ijmd+dNpCRf5WP3CYvjBgo1FAVg QHMA== 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=6T77tKvuFLVvz0J4i9lYZiO/BwdxJrXLSI4SwO0Q+bc=; b=QInvswptxld5dGSMfeiusZdVQf03KBmIXHtmKGcWgUUcOgnSIX7PNqky5nNiT8+HiR ub/6fW/4FSeNeHfNbPSZLjMQyHa48k0wDUhS2CZdb+XSLw1oWB2f2ZezzB/Wfk0RS+B2 aKFIJrPI9KwigvkoTI42KXA9idO7H23nuXJEPz/Aup1qMvyiREE7e6QaunaoHI+ZTHd2 ExAmYs/jtII+85vFnQRJ9SYp0+BFpFtVqNajEaCPNlcNscN6B31oDBTl++x2Lpb66r57 ePxwyptzqhrj3EGDicx4l9Ok9/pYOF+qb8AMZOOhxO/1f1Chc2tVsfkC0RpgLJOp7IcI WBgg== 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 b10-20020a170902b60a00b001b18ec6ddfcsi10229066pls.294.2023.06.16.02.10.47; Fri, 16 Jun 2023 02:11:01 -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 S1344254AbjFPJBI (ORCPT + 99 others); Fri, 16 Jun 2023 05:01:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343928AbjFPI7t (ORCPT ); Fri, 16 Jun 2023 04:59:49 -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 8AFC530CF; Fri, 16 Jun 2023 01:59:40 -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 1qA5Iw-0000d1-Op; Fri, 16 Jun 2023 10:59:38 +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 v2 2/2] hwrng: st - keep clock enabled while hwrng is registered Date: Fri, 16 Jun 2023 09:58:13 +0100 Message-Id: <20230616085813.1323082-3-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230616085813.1323082-1-martin@kaiser.cx> References: <20230616083618.1320824-1-martin@kaiser.cx> <20230616085813.1323082-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?1768849839850313716?= 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 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 --- v2: - don't unprepare the clock if devm_hwrng_register fails - don't set driver data, it was used only in the remove function that's now gone - rephrase the commit message, the clock is now disabled by devres drivers/char/hw_random/st-rng.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/drivers/char/hw_random/st-rng.c b/drivers/char/hw_random/st-rng.c index 15ba1e6fae4d..6e9dfac9fc9f 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,26 +84,18 @@ 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); ret = devm_hwrng_register(&pdev->dev, &ddata->ops); if (ret) { dev_err(&pdev->dev, "Failed to register HW RNG\n"); - clk_disable_unprepare(clk); return ret; } @@ -113,15 +104,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 +116,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);