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-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250414-camouflaged-silver-dodo-d0c000-mkl@pengutronix.de>
Date: Mon, 14 Apr 2025 11:55:34 +0200
From: Marc Kleine-Budde <mkl@...gutronix.de>
To: Ciprian Costea <ciprianmarian.costea@....nxp.com>, 
	Maxime Ripard <mripard@...nel.org>
Cc: Vincent Mailhol <mailhol.vincent@...adoo.fr>, 
	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>, Ghennadi Procopciuc <ghennadi.procopciuc@....com>, 
	Michael Turquette <mturquette@...libre.com>, Stephen Boyd <sboyd@...nel.org>, linux-clk@...r.kernel.org, 
	kernel@...gutronix.de
Subject: Re: [PATCH] can: flexcan: enable PER clock before obtaining its rate

On 14.04.2025 10:36:46, Ciprian Costea wrote:
> 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.

In commit bde8870cd8c3 ("clk: Clarify clk_get_rate() expectations")
Maxime Ripard changed the documentation of the of the function in clk.c
to say it's allowed. However clk.h states "This is only valid once the
clock source has been enabled.".

I've added the common clock maintainers to Cc.

Which documentation is correct? Is the clk.h correct for archs not using
the common clock framework?

regards,
Marc

> 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
> 
> 

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ