Avoiding duplicate statements with SmPL?
Hello,
A source code search approach pointed a specific function implementation out as another update candidate.
Source file example:
// SPDX-License-Identifier: GPL-2.0+
// See also:
// https://elixir.bootlin.com/linux/v6.11/source/drivers/tty/serial/fsl_lpuart.c#L2788
// deleted part
static int lpuart_global_reset(struct lpuart_port *sport)
{
struct uart_port *port = &sport->port;
void __iomem *global_addr;
unsigned long ctrl, bd;
unsigned int val = 0;
int ret;
// deleted part
ret = clk_prepare_enable(sport->ipg_clk);
// deleted part
if (is_imx7ulp_lpuart(sport) || is_imx8ulp_lpuart(sport) || is_imx8qxp_lpuart(sport)) {
/*
* If the transmitter is used by earlycon, wait for transmit engine to
* complete and then reset.
*/
ctrl = lpuart32_read(port, UARTCTRL);
if (ctrl & UARTCTRL_TE) {
bd = lpuart32_read(&sport->port, UARTBAUD);
if (read_poll_timeout(lpuart32_tx_empty, val, val, 1, 100000, false,
port)) {
dev_warn(sport->port.dev,
"timeout waiting for transmit engine to complete\n");
clk_disable_unprepare(sport->ipg_clk);
return 0;
}
}
// deleted part
}
clk_disable_unprepare(sport->ipg_clk);
return 0;
}// deleted part
I constructed another small script variant for the semantic patch language.
SmPL script example:
@adjustment@
expression list el;
idexpression result;
identifier action, work;
type t;
@@
t work(...)
{
<+...
-action(el);
-return result
+goto action
;
...+>
+action:
action(el);
return result;
}
A corresponding test run did not generate the expected patch so far with the software combination “Coccinelle 1.2-00038-g2297fc0f”.
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch ../janitor/goto_last_function_call12.cocci fsl_lpuart-excerpt-20240925.c …
May I expect that such a simple source code transformation should also work?
Regards,
Markus