From patchwork Fri Sep 13 22:09:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 11145405 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4443C184E for ; Fri, 13 Sep 2019 22:09:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 267822084F for ; Fri, 13 Sep 2019 22:09:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390572AbfIMWJd (ORCPT ); Fri, 13 Sep 2019 18:09:33 -0400 Received: from muru.com ([72.249.23.125]:60742 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390550AbfIMWJd (ORCPT ); Fri, 13 Sep 2019 18:09:33 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 18DC681A1; Fri, 13 Sep 2019 22:10:03 +0000 (UTC) From: Tony Lindgren To: Matt Mackall , Herbert Xu , linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org Cc: linux-crypto@vger.kernel.org, Aaro Koskinen , Adam Ford , =?utf-8?q?Pali_Roh=C3=A1r?= , Tero Kristo , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH 3/6] hwrng: omap3-rom - Call clk_prepare() on init and exit only Date: Fri, 13 Sep 2019 15:09:19 -0700 Message-Id: <20190913220922.29501-4-tony@atomide.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190913220922.29501-1-tony@atomide.com> References: <20190913220922.29501-1-tony@atomide.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org When unloading omap3-rom-rng, we'll get the following: WARNING: CPU: 0 PID: 100 at drivers/clk/clk.c:948 clk_core_disable This is because the clock is already disabled by omap3_rom_rng_idle(). Also, we should not call prepare and unprepare except during init, and only call enable and disable during use. Cc: Aaro Koskinen Cc: Adam Ford Cc: Pali Rohár Cc: Tero Kristo Fixes: 1c6b7c2108bd ("hwrng: OMAP3 ROM Random Number Generator support") Signed-off-by: Tony Lindgren --- drivers/char/hw_random/omap3-rom-rng.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c --- a/drivers/char/hw_random/omap3-rom-rng.c +++ b/drivers/char/hw_random/omap3-rom-rng.c @@ -44,7 +44,7 @@ static void omap3_rom_rng_idle(struct work_struct *work) pr_err("reset failed: %d\n", r); return; } - clk_disable_unprepare(rng_clk); + clk_disable(rng_clk); rng_idle = 1; } @@ -55,13 +55,13 @@ static int omap3_rom_rng_get_random(void *buf, unsigned int count) cancel_delayed_work_sync(&idle_work); if (rng_idle) { - r = clk_prepare_enable(rng_clk); + r = clk_enable(rng_clk); if (r) return r; r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT); if (r != 0) { - clk_disable_unprepare(rng_clk); + clk_disable(rng_clk); pr_err("HW init failed: %d\n", r); return -EIO; } @@ -114,20 +114,32 @@ static int omap3_rom_rng_probe(struct platform_device *pdev) return PTR_ERR(rng_clk); } + ret = clk_prepare(rng_clk); + if (ret < 0) { + dev_err(&pdev->dev, "clk_prepare failed: %i\n", ret); + return ret; + } + /* Leave the RNG in reset state. */ - ret = clk_prepare_enable(rng_clk); + ret = clk_enable(rng_clk); if (ret) - return ret; + goto err_unprepare; omap3_rom_rng_idle(0); return hwrng_register(&omap3_rom_rng_ops); + +err_unprepare: + clk_unprepare(rng_clk); + + return ret; } static int omap3_rom_rng_remove(struct platform_device *pdev) { cancel_delayed_work_sync(&idle_work); hwrng_unregister(&omap3_rom_rng_ops); - clk_disable_unprepare(rng_clk); + clk_unprepare(rng_clk); + return 0; }