Re: [PATCH v2 2/3] serial: mtk: guard clk ops on clk.dev

Julien Stephan <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <CAEHHSva1mtgsRZ2-OAZ7qBP0wfHBVsvUECtRu6-n15aY2OEwOg@mail.gmail.com>
Le ven. 31 juil. 2026 à 21:39, David Lechner <[email protected]> a écrit :
>
> 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 | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/serial/serial_mtk.c b/drivers/serial/serial_mtk.c
> index 28e87f485a2..fff2f639cf6 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 (priv->clk.dev) {

What about using  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);
>
> @@ -255,7 +259,8 @@ static int mtk_serial_probe(struct udevice *dev)
>         writel(UART_MCRVAL, &priv->regs->mcr);
>         writel(UART_FCRVAL, &priv->regs->fcr);
>
> -       clk_enable(&priv->clk);
> +       if (priv->clk.dev)
> +               clk_enable(&priv->clk);

Same here,  clk_valid()?
Also, this change is purely cosmetic, since clk_enable() already call
clk_valid()

>         if (priv->clk_bus.dev)
>                 clk_enable(&priv->clk_bus);
>
>
> --
> 2.43.0
>
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.