Re: [01/16] coccinelle: misc: secs_to_jiffies: Patch expressions too

Markus Elfring
2025-02-03T07:24:24Z

> I tend also to present possibilities for succinct SmPL code.
> Unfortunately, software dependencies can trigger corresponding target conflicts.

@adjustment@
expression e;
@@
-msecs_to_jiffies
+secs_to_jiffies
(
(
-e * 1000
|
-e * MSEC_PER_SEC
)
+e
)

A command (like the following) can indicate how isomorphisms are applied
for the transformation of some data into SmPL disjunctions.
https://gitlab.inria.fr/coccinelle/coccinelle/-/blob/bd08cad3f802229dc629a13eefef2018c620e905/standard.iso#L252-257

Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> spatch --parse-cocci suggestion3_for_Easwar_Hariharan-20250128.cocci
…
@adjustment@
expression e;
@@

(
-msecs_to_jiffies
>>> secs_to_jiffies
(-e -* -1000
<<< e
)
|
-msecs_to_jiffies
>>> secs_to_jiffies
(-1000 -* -e
<<< e
)
|
-msecs_to_jiffies
>>> secs_to_jiffies
(-e -* -MSEC_PER_SEC
<<< e
)
|
-msecs_to_jiffies
>>> secs_to_jiffies
(-MSEC_PER_SEC -* -e
<<< e
)
)

Grep query
msecs_to_jiffies

I find parts of such a data representation improvable.
I would usually expect here that parentheses for the selection of call parameters
will not appear in the first text column
(so that confusion will be avoided for the usage of delimiters according to SmPL disjunctions).

The isomorphism specifications represent also a software development status.
It seems that they do not contain direct support for SmPL disjunctions so far
(as an explicit entity).

The identifier “HZ” is used by the referenced macro.
https://elixir.bootlin.com/linux/v6.13/source/include/linux/jiffies.h#L530-L540
https://lore.kernel.org/linux-kernel/173831299312.31546.8797889985487965830.tip-bot2@tip-bot2/

Is there a need to take further (preprocessor symbol) variations better into account?

How do you think about the handling of multiplication factors within bigger expressions
(and not only at the beginning or end of a term)?

Would you be looking for further restrictions on expression combinations?

Regards,
Markus