Re: [PATCH v2 1/3] serial: mtk: use ulong for clk_rate

Julien Stephan <[email protected]>
Newsgroups gmane.comp.boot-loaders.u-boot
Message-ID <CAEHHSvZKMF3rN0ttOStEL0vR2eRDXx3wZsnuQX_k6=sNwKZDyQ__809.779546555944$1786096161$gmane$org@mail.gmail.com>
Le ven. 31 juil. 2026 à 21:39, David Lechner <[email protected]> a écrit :
>
> From: Suhrid Subramaniam <[email protected]>
>
> Use ulong for return value of clk_get_rate() in the MediaTek serial
> driver.
>
> IS_ERR_VALUE() does a signed 64-bit comparison against the range of
> possible error codes. If clk_get_rate() returns an error, assigning this
> to a u32 truncates the top 32 bits making the value smaller, defeating
> IS_ERR_VALUE() and producing a garbage divisor that hangs the UART.
>
> 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 | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/serial/serial_mtk.c b/drivers/serial/serial_mtk.c
> index 01cc415efdd..28e87f485a2 100644
> --- a/drivers/serial/serial_mtk.c
> +++ b/drivers/serial/serial_mtk.c
> @@ -213,7 +213,7 @@ static int _mtk_serial_pending(struct mtk_serial_priv *priv, bool input)
>  static int mtk_serial_setbrg(struct udevice *dev, int baudrate)
>  {
>         struct mtk_serial_priv *priv = dev_get_priv(dev);
> -       u32 clk_rate;
> +       ulong clk_rate;
>
>         clk_rate = clk_get_rate(&priv->clk);
>         if (IS_ERR_VALUE(clk_rate) || clk_rate == 0)
> @@ -266,6 +266,7 @@ static int mtk_serial_of_to_plat(struct udevice *dev)
>  {
>         struct mtk_serial_priv *priv = dev_get_priv(dev);
>         fdt_addr_t addr;
> +       ulong clk_rate;
>         int err;
>
>         addr = dev_read_addr(dev);
> @@ -282,8 +283,8 @@ static int mtk_serial_of_to_plat(struct udevice *dev)
>                         return -EINVAL;
>                 }
>         } else {
> -               err = clk_get_rate(&priv->clk);
> -               if (IS_ERR_VALUE(err)) {
> +               clk_rate = clk_get_rate(&priv->clk);
> +               if (IS_ERR_VALUE(clk_rate)) {
>                         dev_err(dev, "invalid baud clock\n");
>                         return -EINVAL;
>                 }
>
> --
> 2.43.0
>
Reviewed-by: Julien Stephan <[email protected]>
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.