Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2307609rwd; Fri, 16 Jun 2023 02:04:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7anYAHy3oQAyULPUu89k5HAQAdw/u5ZKmHAvLL2AYMbWCCzHosNLDkil/r6pZ0vqUfYbqj X-Received: by 2002:a05:6a20:440c:b0:111:a0e5:d29d with SMTP id ce12-20020a056a20440c00b00111a0e5d29dmr2344761pzb.4.1686906252778; Fri, 16 Jun 2023 02:04:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686906252; cv=none; d=google.com; s=arc-20160816; b=HSaNFv6X47qDFb26SwqgR3ru+OgeOB5zzkfN8v5YBN6P4OYc631RBFyIqH+t/nXNzr E8PkgA3BadL+KiYLE0p8nr/kfh42smk64g9Kz09VfXN58hiCzsqqRd9iFcJ2hLA111xU Rpmy9L9nQfn2Z479RrSqrjvGEIK0NiYIftIiowu4PGR3yn4jpBCGSvfsLAoQ7qGBtYRU s+fyVtsXpwVtOGNUenV2yjUdVib3ToeE4+8PwcVdp5kWtD6qCrldqFO8XYQlN7CpxunN QJn/GDfAaZMnY//yDKkObERSz6kXGYjgMqJEGx2RhanAu6RZMY/clQD3n0lzOYA7lwjB FWag== 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=tsHQVfwylBrApakqBzC1uSnASHNJNGgpZIM3ko6kFytwQvwymUnfrT80IqiCze6UKI trxBMl+iLdqBSNuwasMA48mg8EOXhIbGJ+th+M26zFLr/0ZAoxabgEXc1uWI60e7tPeO Ib1WvY8fPohk3SmDEr33YVP2V3uapToAHxRhhd739Rl0ewog9oXYwppItS6MIBQAKUva 6Syax0uxnVvnfbwtPWuy0K9JpbQwnuDTGpld22SbqLEFl9STdqaAwh8GZyHtDZJU9wOS PLyj+P3NWFzg+irNztiQBU7gvtsxjqRaygNCYGUR4PstuJMxPgRmf9LxAovOFseLW1tu +Csg== 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 p29-20020aa79e9d000000b006636be3bc45si10904508pfq.120.2023.06.16.02.03.48; Fri, 16 Jun 2023 02:04:12 -0700 (PDT) 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 S245491AbjFPJAk (ORCPT + 99 others); Fri, 16 Jun 2023 05:00:40 -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 Content-Transfer-Encoding: 8bit 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-crypto@vger.kernel.org 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); -- 2.30.2