Re: [PATCH 2/5] serial: imx: Remove redundant dev_err()

[email protected]
Newsgroups dev.linux.lists.imx
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The global `imx_uart_ports` array retains a dangling pointer to a freed `sport` structure if `uart_add_one_port()` fails or when the driver is unbound.
- [High] The hrtimers `trigger_start_tx` and `trigger_stop_tx` are never synchronously cancelled during device teardown, leading to a potential Use-After-Free.
--

--- Patch [2]: [PATCH 2/5] serial: imx: Remove redundant dev_err() ---
commit 44174bba1c656c63bfedf3dc6b8ca0b3fa1165cb
Author: Pan Chuang <[email protected]>

serial: imx: Remove redundant dev_err()

This commit removes driver-specific dev_err() calls after devm_request_irq(), 
as the core function already logs detailed error messages on failure since 
commit 55b48e23f5c4.

> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 251a50c8aa387..95fdb60e06a77 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
> @@ -2602,34 +2602,23 @@ static int imx_uart_probe(struct platform_device *pdev)
[ ... ]
>  	} else {
>  		ret = devm_request_irq(&pdev->dev, rxirq, imx_uart_int, 0,
>  				       dev_name(&pdev->dev), sport);
> -		if (ret) {
> -			dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
> +		if (ret)
>  			goto err_clk;
> -		}
>  	}
>  
>  	imx_uart_ports[sport->port.line] = sport;

[Severity: High]
This is a pre-existing issue, but does this leave a dangling pointer in
the global array if uart_add_one_port() fails later in the probe function?

If uart_add_one_port() fails, the function returns an error and devm
automatically frees the sport structure. However, the pointer was already
assigned to imx_uart_ports[sport->port.line] and is never cleared on the
error path. Could this lead to a use-after-free if the console subsystem or
sysrq accesses the array?

Similarly, it looks like imx_uart_remove() does not clear this array entry
before devres frees the memory during driver unbind.

[Severity: High]
This is also a pre-existing issue, but are the trigger_start_tx and
trigger_stop_tx hrtimers synchronously cancelled during device teardown?

Looking at the unbind path in imx_uart_remove():

static void imx_uart_remove(struct platform_device *pdev)
{
        struct imx_port *sport = platform_get_drvdata(pdev);

        uart_remove_one_port(&imx_uart_uart_driver, &sport->port);
}

During unbind, imx_uart_shutdown() tries to stop the port and calls
hrtimer_try_to_cancel() implicitly. However, hrtimer_try_to_cancel() doesn't
wait for a currently executing callback to finish.

Since explicit hrtimer_cancel() is never called in imx_uart_remove(),
could devres free the sport structure while the hrtimer callback is still
running or pending on another CPU, resulting in a use-after-free?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
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.