lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250414073646.1473157-1-ciprianmarian.costea@oss.nxp.com>
Date: Mon, 14 Apr 2025 10:36:46 +0300
From: Ciprian Costea <ciprianmarian.costea@....nxp.com>
To: Marc Kleine-Budde <mkl@...gutronix.de>,
	Vincent Mailhol <mailhol.vincent@...adoo.fr>
Cc: linux-can@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	NXP S32 Linux Team <s32@....com>,
	imx@...ts.linux.dev,
	Christophe Lizzi <clizzi@...hat.com>,
	Alberto Ruiz <aruizrui@...hat.com>,
	Enric Balletbo <eballetb@...hat.com>,
	Eric Chanudet <echanude@...hat.com>,
	Ciprian Marian Costea <ciprianmarian.costea@....nxp.com>,
	Ghennadi Procopciuc <ghennadi.procopciuc@....com>
Subject: [PATCH] can: flexcan: enable PER clock before obtaining its rate

From: Ciprian Marian Costea <ciprianmarian.costea@....nxp.com>

The FlexCan driver assumes that the frequency of the 'per' clock can be
obtained even on disabled clocks, which is not always true.

According to 'clk_get_rate' documentation, it is only valid once the clock
source has been enabled.

Co-developed-by: Ghennadi Procopciuc <ghennadi.procopciuc@....com>
Signed-off-by: Ghennadi Procopciuc <ghennadi.procopciuc@....com>
Signed-off-by: Ciprian Marian Costea <ciprianmarian.costea@....nxp.com>
---
 drivers/net/can/flexcan/flexcan-core.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index 6d80c341b26f..b142aa60620e 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -2056,6 +2056,26 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)
 	return 0;
 }
 
+static unsigned long get_per_clk_rate(struct clk *clk)
+{
+	unsigned long rate;
+	int err;
+
+	rate = clk_get_rate(clk);
+	if (rate)
+		return rate;
+
+	/* Just in case this clock is disabled by default */
+	err = clk_prepare_enable(clk);
+	if (err)
+		return 0;
+
+	rate = clk_get_rate(clk);
+	clk_disable_unprepare(clk);
+
+	return rate;
+}
+
 static const struct of_device_id flexcan_of_match[] = {
 	{ .compatible = "fsl,imx8qm-flexcan", .data = &fsl_imx8qm_devtype_data, },
 	{ .compatible = "fsl,imx8mp-flexcan", .data = &fsl_imx8mp_devtype_data, },
@@ -2137,7 +2157,7 @@ static int flexcan_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev, "no per clock defined\n");
 			return PTR_ERR(clk_per);
 		}
-		clock_freq = clk_get_rate(clk_per);
+		clock_freq = get_per_clk_rate(clk_per);
 	}
 
 	irq = platform_get_irq(pdev, 0);
-- 
2.45.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ