Re: [PATCH] serial: core: check if uart_get_info succeeds before using

From: Andy Shevchenko
Date: Tue Jun 07 2022 - 06:15:57 EST


On Sun, May 29, 2022 at 4:09 PM Tom Rix <trix@xxxxxxxxxx> wrote:
>
> clang static analysis reports this representative issue
> drivers/tty/serial/serial_core.c:2818:9: warning: 3rd function call argument is an uninitialized value [core.CallAndMessage]
> return sprintf(buf, "%d\n", tmp.iomem_reg_shift);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> uart_get_info() is used the *show() functions. When uart_get_info() fails, what is reported

in the ?

> is garbage. So check if uart_get_info() succeeded.

...

> - uart_get_info(port, &tmp);
> + if (uart_get_info(port, &tmp))
> + return 0;

I don't think this is correct. If something fails we need to inform the caller.

I think more about

int ret;

ret = uart_get_info(...);
if (ret)
return ret;

But I haven't looked at the uart_get_info() implementation, so the
above might be wrong.

> return sprintf(buf, "%d\n", tmp.baud_base * 16);

Ditto for the rest.

--
With Best Regards,
Andy Shevchenko