Re: [PATCH v3 2/4] serial: mtk: guard clk ops on clk.dev

David Lechner <[email protected]>
Newsgroups gmane.comp.boot-loaders.u-boot
Message-ID <1873add4-8848-4b54-af92-df734529cb41__3189.91477122239$1786132101$gmane$org@baylibre.com>
On 8/7/26 1:59 PM, David Lechner wrote:
> From: Suhrid Subramaniam <[email protected]>
> 
> Check that priv->clk has been populated before trying to use it in the
> MediaTek serial driver.
> 
> The clock is optional and may not be populated in all cases (in which
> case it is expected that there was a fixed clock rate provided.)
> 
> Fixes: 3b17f2e2c2a9 ("serial: mtk: add support for using dynamic baud clock souce")
> Signed-off-by: Suhrid Subramaniam <[email protected]>
> Signed-off-by: David Lechner <[email protected]>
> ---
>  drivers/serial/serial_mtk.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/serial/serial_mtk.c b/drivers/serial/serial_mtk.c
> index 28e87f485a2..0f1d3b63f23 100644
> --- a/drivers/serial/serial_mtk.c
> +++ b/drivers/serial/serial_mtk.c
> @@ -215,9 +215,13 @@ static int mtk_serial_setbrg(struct udevice *dev, int baudrate)
>  	struct mtk_serial_priv *priv = dev_get_priv(dev);
>  	ulong clk_rate;
>  
> -	clk_rate = clk_get_rate(&priv->clk);
> -	if (IS_ERR_VALUE(clk_rate) || clk_rate == 0)
> +	if (clk_is_valid(&priv->clk)) {

Bah, I got moving too fast and didn't test properly. This is supposed
to be clk_valid().

> +		clk_rate = clk_get_rate(&priv->clk);
> +		if (IS_ERR_VALUE(clk_rate) || clk_rate == 0)
> +			return -EINVAL;
> +	} else {
>  		clk_rate = priv->fixed_clk_rate;
> +	}
>  
>  	_mtk_serial_setbrg(priv, baudrate, clk_rate);
>  
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.