Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: cocci@inria.fr
Subject: [cocci] Avoiding duplicate statements with SmPL?
Date: Wed, 25 Sep 2024 14:40:28 +0200	[thread overview]
Message-ID: <b18aa73c-0c3b-449d-bd81-a1b6e604b6fa@web.de> (raw)

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

                 reply	other threads:[~2024-09-25 12:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b18aa73c-0c3b-449d-bd81-a1b6e604b6fa@web.de \
    --to=markus.elfring@web.de \
    --cc=cocci@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).