Searching for duplicate exception handling code with SmPL?
Quoted 7 lines
But the desire is growing to reduce the presentation of unwanted false positives considerably.
Thus there is a need to switch to more appropriate data formats. It seems then that multiple code occurrences can eventually be taken better into account with the help of SmPL position variables. Their information can be stored in databases probably also according to ACID criteria.
Another SmPL script variant:
@initialize:python@
@@
import sqlalchemy, sys sys.stderr.write("\n".join(["Using SQLAlchemy version:",
sqlalchemy.__version__]))
sys.stderr.write("\n")
from sqlalchemy import Column, Integer, String, create_engine # outdated: from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.orm import sessionmaker
engine = create_engine("sqlite:///:memory:", echo=False) # outdated: base = declarative_base()
class Base(DeclarativeBase):
pass
class action(Base):
__tablename__ = "statements"
name: Mapped[str] = mapped_column(String, primary_key=True)
source_file: Mapped[str] = mapped_column(String, primary_key=True)
line: Mapped[int] = mapped_column(Integer, primary_key=True)
column: Mapped[int] = mapped_column(Integer, primary_key=True)
value1: Mapped[str] = mapped_column(String)
value2: Mapped[str] = mapped_column(String)
def __repr__(self):
return """<action(name='%s',
source_file='%s',
line='%s',
column='%s',
value1='%s',
value2='%s')>""" % (self.name,
self.source_file, self.line, self.column, self.value1, self.value2)
class action2(Base):
__tablename__ = "statements2"
name: Mapped[str] = mapped_column(String, primary_key=True)
source_file: Mapped[str] = mapped_column(String, primary_key=True)
line: Mapped[int] = mapped_column(Integer, primary_key=True)
column: Mapped[int] = mapped_column(Integer, primary_key=True)
value1: Mapped[str] = mapped_column(String)
value2: Mapped[str] = mapped_column(String)
def __repr__(self):
return """<action2(name='%s',
source_file='%s',
line='%s',
column='%s',
value1='%s',
value2='%s')>""" % (self.name,
self.source_file, self.line, self.column, self.value1, self.value2)
configured_session = sessionmaker(bind=engine)
session = configured_session()
# base.metadata.create_all(engine)
#
# See also:
# https://stackoverflow.com/questions/70402667/how-to-use-create-all-for-sqlalchemy-orm-objects-across-files
Base.metadata.create_all(engine)
def store_data(fun, source1, source2, x, y):
"""Add data to internal tables."""
for place in source1:
entry = action(name = fun,
source_file = place.file, line = place.line, column = int(place.column) + 1, value1 = x,
value2 = y)
session.add(entry)
for place in source2:
entry = action2(name = fun,
source_file = place.file, line = place.line, column = int(place.column) + 1, value1 = x,
value2 = y)
session.add(entry)
@searching@
expression e, x;
identifier item, rc, work;
position p1, p2;
type T;
@@
T work(...)
{
... when any
if (...)
{
... when != rc = e
when != item = x
kfree@p1(item);
return rc;
}
... when any
if (...)
{
... when != rc = e
when != item = x kfree@p2(item);
return rc;
}
... when any
}
@script:python collection@
fun << searching.work;
x << searching.item;
y << searching.rc;
p1 << searching.p1;
p2 << searching.p2;
@@store_data(fun, p1, p2, x, y)
@finalize:python@
@@session.commit()
from sqlalchemy import func
entries = session.query(func.count("*")).select_from(action).scalar()
if entries > 0:
from sqlalchemy import Index, Table, MetaData, select, text from sqlalchemy.engine.reflection import Inspector from sqlalchemy.sql import literal_column
pairs = Index("pairs", action.value1, action.value2) pairs.create(engine)
# See also:
# https://stackoverflow.com/questions/30575111/how-to-create-a-new-table-from-select-statement-in-sqlalchemy#answer-30577608
q = session.query(action.value1, action.value2, action.name, action.source_file,
func.count(literal_column("*")).label("C")
).group_by(action.value1,
action.value2,
action.name,
action.source_file) \
.having(func.count(literal_column("*")) > literal_column("1")) session.execute(text('create table t2 as ' + str(q.statement)))
class results(Base):
__table__ = Table("t2", Base.metadata, autoload_with = session.connection())
__mapper_args__ = {
"primary_key": [__table__.c.source_file,
__table__.c.name,
__table__.c.value1,
__table__.c.value2]
}entries2 = session.query(func.count("*")).select_from(results).scalar()
if entries2 > 0:
delimiter = "|"
sys.stdout.write(delimiter.join(["value1",
"value2",
'"function name"',
'"source file"',
"incidence"]))
sys.stdout.write("\r\n")
for value1, value2, name, source_file, incidence \
in session.query(results.value1,
results.value2,
results.name,
results.source_file,
results.C).order_by(results.source_file,
results.name,
results.value1,
results.value2):
sys.stdout.write(delimiter.join([value1,
value2,
name,
source_file,
str(incidence)]))
sys.stdout.write("\r\n")
else:
sys.stderr.write("Duplicate statements were not determined from "
+ str(entries) + " records.\n")
delimiter = "|"
sys.stderr.write(delimiter.join(["value1",
"value2",
'"function name"',
'"source file"',
"line"]))
sys.stderr.write("\r\n")
for value1, value2, name, source_file, line \
in session.query(action.value1,
action.value2,
action.name,
action.source_file,
action.line).order_by(action.source_file,
action.name,
action.value1,
action.value2,
action.line):
sys.stderr.write(delimiter.join([value1,
value2,
name,
source_file,
str(line)]))
sys.stderr.write("\r\n")else:
sys.stderr.write("No result for this analysis!\n")
Corresponding source file example:
https://elixir.bootlin.com/linux/v7.1-rc7/source/sound/core/seq/seq_fifo.c#L17-L47
// SPDX-License-Identifier: GPL-2.0-or-later // deleted part
struct snd_seq_fifo *snd_seq_fifo_new(int poolsize)
{
struct snd_seq_fifo *f;
f = kzalloc_obj(*f);
if (!f)
return NULL;
f->pool = snd_seq_pool_new(poolsize);
if (f->pool == NULL) {
kfree(f);
return NULL;
}
if (snd_seq_pool_init(f->pool) < 0) {
snd_seq_pool_delete(&f->pool);
kfree(f);
return NULL;
}
// deleted part
return f;
}// deleted part
Questionable test results:
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> git checkout next-20260608 && time /usr/bin/spatch …/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches.cocci sound/core/seq/seq_fifo.c …
Using SQLAlchemy version:
2.0.49
…
Duplicate statements were not determined from 1 records.
value1|value2|"function name"|"source file"|line
f|NULL|snd_seq_fifo_new|sound/core/seq/seq_fifo.c|28
real 0m0,816s user 0m0,658s sys 0m0,148s
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time /usr/bin/spatch ../janitor/list_selected_duplicate_statements_in_if_branches.cocci snd_seq_fifo_new-excerpt-20260608.c …
Using SQLAlchemy version:
2.0.49
…
Duplicate statements were not determined from 1 records.
value1|value2|"function name"|"source file"|line
f|NULL|snd_seq_fifo_new|snd_seq_fifo_new-excerpt-20260608.c|13
real 0m0,785s user 0m0,649s sys 0m0,128s
Would anybody like to explain the different determined values?
How can presented expertise challenges be resolved?
Regards,
Markus
As usual, I have not idea what all your python code is supposed to do. Is it something other than the following:
@searching@
expression e, x;
identifier item, rc, work;
position p1, p2;
type T;
@@
T work(...)
{
... when any
if (...)
{
... when != rc = e
when != item = x
kfree@p1(item);
return rc;
}
... when any
if (...)
{
... when != rc = e
when != item = x kfree@p2(item);
return rc;
}
... when any
}
@script:ocaml@
p1 << searching.p1;
p2 << searching.p2;
@@
Printf.eprintf "duplicate on lines %d and %d\n" (List.hd p1).line (List.hd p2).line
This does print a report on your test data.
julia
Quoted 293 lines · Markus Elfring
Quoted 7 lines
But the desire is growing to reduce the presentation of unwanted false positives considerably.
Thus there is a need to switch to more appropriate data formats. It seems then that multiple code occurrences can eventually be taken better into account with the help of SmPL position variables. Their information can be stored in databases probably also according to ACID criteria.Another SmPL script variant:
@initialize:python@
@@
import sqlalchemy, sys sys.stderr.write("\n".join(["Using SQLAlchemy version:",sqlalchemy.__version__]))
sys.stderr.write("\n")
from sqlalchemy import Column, Integer, String,create_engine# outdated: from sqlalchemy.ext.declarative importdeclarative_basefrom sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped,mapped_column
from sqlalchemy.orm import sessionmaker
engine =create_engine("sqlite:///:memory:", echo=False)# outdated: base =declarative_base()class Base(DeclarativeBase):
passclass action(Base):
__tablename__= "statements"
name: Mapped[str] =mapped_column(String, primary_key=True)
source_file: Mapped[str] =mapped_column(String, primary_key=True)
line: Mapped[int] =mapped_column(Integer, primary_key=True)
column: Mapped[int] =mapped_column(Integer, primary_key=True)
value1: Mapped[str] =mapped_column(String)
value2: Mapped[str] =mapped_column(String)def __repr__(self): return """<action(name='%s',source_file='%s',
line='%s',
column='%s',
value1='%s',
value2='%s')>""" % (self.name,
self.source_file, self.line, self.column, self.value1, self.value2)class action2(Base):
__tablename__= "statements2"
name: Mapped[str] =mapped_column(String, primary_key=True)
source_file: Mapped[str] =mapped_column(String, primary_key=True)
line: Mapped[int] =mapped_column(Integer, primary_key=True)
column: Mapped[int] =mapped_column(Integer, primary_key=True)
value1: Mapped[str] =mapped_column(String)
value2: Mapped[str] =mapped_column(String)def __repr__(self): return """<action2(name='%s',source_file='%s',
line='%s',
column='%s',
value1='%s',
value2='%s')>""" % (self.name,
self.source_file, self.line, self.column, self.value1, self.value2)
configured_session= sessionmaker(bind=engine)
session =configured_session()
#base.metadata.create_all(engine)
#
# See also:
# https://stackoverflow.com/questions/70402667/how-to-use-create-all-for-sqlalchemy-orm-objects-across-files
Base.metadata.create_all(engine)def
store_data(fun, source1, source2, x, y):
"""Add data to internal tables."""
for place in source1:
entry = action(name = fun,
source_file= place.file, line = place.line, column = int(place.column) + 1, value1 = x,
value2 = y)
session.add(entry)for place in source2:
entry = action2(name = fun,
source_file= place.file, line = place.line, column = int(place.column) + 1, value1 = x,
value2 = y)
session.add(entry)@searching@
expression e, x;
identifier item, rc, work;
position p1, p2;
type T;
@@
T work(...)
{
... when any
if (...)
{
... when != rc = ewhen != item = x kfree@p1(item); return rc; } ... when any if (...) { ... when != rc = e when != item = xkfree@p2(item);
return rc;
}
... when any
}@script:python collection@
fun << searching.work;
x << searching.item;
y << searching.rc;
p1 << searching.p1;
p2 << searching.p2;
@@store_data(fun, p1, p2, x, y)@finalize:python@
@@session.commit()
from sqlalchemy import func
entries = session.query(func.count("*")).select_from(action).scalar()if entries > 0:
from sqlalchemy import Index, Table, MetaData, select, text from sqlalchemy.engine.reflection import Inspector from sqlalchemy.sql import literal_column pairs = Index("pairs", action.value1, action.value2) pairs.create(engine) # See also: # https://stackoverflow.com/questions/30575111/how-to-create-a-new-table-from-select-statement-in-sqlalchemy#answer-30577608 q = session.query(action.value1, action.value2, action.name, action.source_file, func.count(literal_column("*")).label("C") ).group_by(action.value1, action.value2, action.name, action.source_file) \ .having(func.count(literal_column("*")) > literal_column("1")) session.execute(text('create table t2 as ' + str(q.statement))) class results(Base): __table__ = Table("t2", Base.metadata, autoload_with = session.connection()) __mapper_args__ = { "primary_key": [__table__.c.source_file, __table__.c.name, __table__.c.value1, __table__.c.value2] } entries2 = session.query(func.count("*")).select_from(results).scalar() if entries2 > 0: delimiter = "|" sys.stdout.write(delimiter.join(["value1", "value2", '"function name"', '"source file"', "incidence"])) sys.stdout.write("\r\n") for value1, value2, name, source_file, incidence \ in session.query(results.value1, results.value2, results.name, results.source_file, results.C).order_by(results.source_file, results.name, results.value1, results.value2): sys.stdout.write(delimiter.join([value1, value2, name, source_file, str(incidence)])) sys.stdout.write("\r\n") else: sys.stderr.write("Duplicate statements were not determined from " + str(entries) + " records.\n") delimiter = "|" sys.stderr.write(delimiter.join(["value1", "value2", '"function name"', '"source file"', "line"])) sys.stderr.write("\r\n") for value1, value2, name, source_file, line \ in session.query(action.value1, action.value2, action.name, action.source_file, action.line).order_by(action.source_file, action.name, action.value1, action.value2, action.line): sys.stderr.write(delimiter.join([value1, value2, name, source_file, str(line)])) sys.stderr.write("\r\n")else:
sys.stderr.write("No result for this analysis!\n")Corresponding source file example:
https://elixir.bootlin.com/linux/v7.1-rc7/source/sound/core/seq/seq_fifo.c#L17-L47// SPDX-License-Identifier: GPL-2.0-or-later // deleted part
structsnd_seq_fifo*snd_seq_fifo_new(int poolsize){ struct snd_seq_fifo *f; f = kzalloc_obj(*f); if (!f) return NULL; f->pool = snd_seq_pool_new(poolsize); if (f->pool == NULL) { kfree(f); return NULL; } if (snd_seq_pool_init(f->pool) < 0) { snd_seq_pool_delete(&f->pool); kfree(f); return NULL; } // deleted part return f; }// deleted part
Questionable test results:
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> git checkout next-20260608 && time/usr/bin/spatch…/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches.coccisound/core/seq/seq_fifo.c…
Using SQLAlchemy version:
2.0.49
…
Duplicate statements were not determined from 1 records.
value1|value2|"function name"|"source file"|line
f|NULL|snd_seq_fifo_new|sound/core/seq/seq_fifo.c|28real 0m0,816s user 0m0,658s sys 0m0,148sMarkus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time
/usr/bin/spatch../janitor/list_selected_duplicate_statements_in_if_branches.coccisnd_seq_fifo_new-excerpt-20260608.c…
Using SQLAlchemy version:
2.0.49
…
Duplicate statements were not determined from 1 records.
value1|value2|"function name"|"source file"|line
f|NULL|snd_seq_fifo_new|snd_seq_fifo_new-excerpt-20260608.c|13real 0m0,785s user 0m0,649s sys 0m0,128sWould anybody like to explain the different determined values?
How can presented expertise challenges be resolved?
Regards,
Markus
Quoted 7 lines · Markus Elfring
Quoted 1 line
As usual, I have not idea what all your python code is supposed to do.
I hope that a better common understanding can be achieved by another bit of clarification.
Quoted 1 line
Is it something other than the following:
Quoted 8 lines
I guess that the initial source code search pattern can be clear to some degree.
…
Quoted 2 lines
Quoted 2 lines
Questionable test results:
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> git checkout next-20260608 && time/usr/bin/spatch…/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches.cocci sound/core/seq/seq_fifo.c…Can you benefit any more from a data representation like the following?
No. I have no idea what output you expect, so I don't know what the problem is.
Could you please make something that doesn't involve a database?
Or just explain what you expected as the output and how that relates to the source code.
julia
Quoted 18 lines
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time
/usr/bin/spatch…/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches2.coccisound/core/seq/seq_fifo.c…
Using SQLAlchemy version:
2.0.49
…
value1|value2|"function name"|"source file"|incidence
f|NULL|snd_seq_fifo_new|sound/core/seq/seq_fifo.c|1real 0m0,799s user 0m0,664s sys 0m0,135sRegards,
Markus
Quoted 26 lines · Markus Elfring
Quoted 3 lines
Quoted 1 line
Can you benefit any more from a data representation like the following?
No.
I hope that such a view can be adjusted.
Quoted 1 line
I have no idea what output you expect,
Can you get the impression that I occasionally prefer to work with tabular data output?
Quoted 2 lines
so I don't know what the
problem is.I guess that several technical difficulties can trigger further collateral evolution. I am looking for corresponding solutions.
Quoted 1 line
Could you please make something that doesn't involve a database?
Which programming interfaces do support counting and grouping of data items in convenient and efficient ways?
Quoted 7 lines
Quoted 2 lines
Or just explain what you expected as the output and how that relates to the source code.
I would like to detect duplicate statements somehow.
How would you prefer to point repeated source code elements out accordingly?Is there a field or column like incidence desirable?
Do you agree that my semantic patch finds what you expect to find?
If you agree on that, it would seem that the problem is in your python code.
julia
Quoted 36 lines · Markus Elfring
Quoted 2 lines
Quoted 1 line
Is there a field or column like incidence desirable?
Do you agree that my semantic patch finds what you expect to find?
Your SmPL script variant looks promising.
// See also:
// https://lore.kernel.org/cocci/[email protected]/
// https://sympa.inria.fr/sympa/arc/cocci/2026-06/msg00005.html
@searching_for_OCaml@
expression e, x;
identifier item, rc;
position p1, p2;
@@
if (...)
{
... when != rc = ewhen != item = x kfree@p1(item); return rc; } ... when any if (...) { ... when != rc = e when != item = xkfree@p2(item);
return rc;
}@script:ocaml@
p1 << searching_for_OCaml.p1;
p2 << searching_for_OCaml.p2;
@@
Printf.eprintf "duplicate on lines %d and %d\n" (List.hd p1).line (List.hd p2).line
Quoted 10 lines
Questionable test result on my development system:
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses>/usr/bin/spatch…/Projekte/Coccinelle/janitor/show_duplicate_statements_in_if_branches3.coccisound/core/seq/seq_fifo.c…
Using native version of ocamlc/ocamlopt/ocamldep
ocamlopt.opt -shared -o/tmp/ocaml_cocci_ad6bde.cmxs-g -I/usr/lib64/coccinelle/ocaml-I/home/Markus_Elfring/.opam/5.3.0/lib64-for-packCoccinelle_modules/tmp/ocaml_cocci_ad6bde.mlFile "/tmp/ocaml_cocci_ad6bde.ml", line 1:
Error:/usr/lib64/coccinelle/ocaml/coccilib.cmi
is not a compiled interface for this version of OCaml.
It seems to be for an older version of OCaml.
Fatal error: exceptionCoccinelle_modules.Yes_prepare_ocamlcocci.CompileFailure("/tmp/ocaml_cocci_ad6bde.ml")
OK, so write the codein python. It should be clear in any case what it does.
Quoted 6 lines
Quoted 1 line
If you agree on that,
I would appreciate if an intended data output can be reproduced finally.
But which software functionality would perform counting of repeated items in your data processing approach?
I did't count anything. Since I don't know what you code does, nor what it is intended to do, I didn't bother trying to reproduce it.
Can't you just explain what you hoped would happen and whythe result is not what you expected?
julia
Quoted 9 lines
Quoted 3 lines
it would seem that the problem is in your python code.
Some communication challenges were presented.
Regards,
Markus
Quoted 15 lines · Markus Elfring
…
Quoted 8 lines
@script:ocaml@
p1 << searching.p1;
p2 << searching.p2;
@@Printf.eprintf "duplicate on lines %d and %d\n" (List.hd p1).line (List.hd p2).line
This does print a report on your test data.
A)
It is obvious that the implementation of the function “snd_seq_fifo_new” does not apply a goto chain so far.
https://elixir.bootlin.com/linux/v7.1-rc7/source/sound/core/seq/seq_fifo.c#L17-L47
Quoted 7 lines
B)
How would the test output look like on your development system for another mentioned example with the function “smb3_reconfigure”?
https://elixir.bootlin.com/linux/v7.1-rc7/source/fs/smb/client/fs_context.c#L1060-L1241Will further ideas appear also according to such a clarification approach?
I haven't tried your example, but it is likely that you just want exists on your SmPL rule, ie
@searching exists@
julia
Quoted 4 lines
Regards,
Markus
Quoted 65 lines · Markus Elfring
Quoted 1 line
Could you please make something that doesn't involve a database?
Do you find another test approach helpful for the desired clarification?
SmPL script example:
@initialize:python@
@@
import sys
delimiter = "|"def
display_data(fun, source1, source2, x, y):
sys.stdout.write(delimiter.join(("info", fun, x, y))
+ "\n")
for place in source1:
sys.stdout.write(delimiter.join(("first",
place.file, place.line, str(int(place.column) + 1)))
+ "\n")for place in source2:
sys.stdout.write(delimiter.join(("tail",
place.file, place.line, str(int(place.column) + 1)))
+ "\n")@searching exists@
expression e, x;
identifier item, rc, work;
position p1, p2;
type t;
@@
t work(...)
{
... when any
if (...)
{
... when != rc = ewhen != item = x kfree@p1(item); return rc; } ... when any if (...) { ... when != rc = e when != item = xkfree@p2(item);
return rc;
}
... when any
}@script:python collection@
fun << searching.work;
x << searching.item;
y << searching.rc;
p1 << searching.p1;
p2 << searching.p2;
@@display_data(fun, p1, p2, x, y)
Quoted 1 line
https://elixir.bootlin.com/linux/v7.1-rc7/source/fs/smb/client/fs_context.c#L1060-L1241
Thank you for making a complete example. Now take the huge C function and make a minimal example that illustrates the problem you are concerned about. The function is almost 200 lines long.
julia
Quoted 26 lines
Extracted function implementation
Questionable test result:
Markus_Elfring@Sonne:/home/altes_Heim2/elfring/Projekte/Coccinelle/Probe> time/usr/bin/spatch../janitor/list_selected_duplicate_statements_in_if_branches3.coccismb3_reconfigure-excerpt2-20260608.cinit_defs_builtins:/usr/lib64/coccinelle/standard.h
HANDLING:smb3_reconfigure-excerpt2-20260608.c
info|smb3_reconfigure|old_ctx|rc
first|smb3_reconfigure-excerpt2-20260608.c|34|3
tail|smb3_reconfigure-excerpt2-20260608.c|185|2
info|smb3_reconfigure|old_ctx|rc
first|smb3_reconfigure-excerpt2-20260608.c|185|2
tail|smb3_reconfigure-excerpt2-20260608.c|185|2real 0m0,506s user 0m0,400s sys 0m0,095sHow do you think about to avoid repeated data display here (despite of the applied goto chain)?
Regards,
Markus
Quoted 50 lines · Markus Elfring
Quoted 5 lines
Quoted 3 lines
Do you know any other source file examples already which would also show the application of goto chains nicely?
https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/recommendations/memory-management-mem/mem12-c/No. Take the source code in your example and remove lines one by one until you obtain a small function that still illustrates the problem.
Would you find another source file example (like the following) more inspiring?
int
my_test(void)
{
structmy_data* md1 =kzalloc_obj(*md1);if (!md1)
return -ENOMEM;struct
my_data* md2;
int rc =make_copy(md1, &md2);
if (rc){ kfree(md1); return rc; } // placeholder for other control flow if (1) { goto free_object; } // placeholder for other control flow if (2) { goto release; } // placeholder for other control flow if (3) { goto cleanup;}
cleanup:
my_cleanup();
release:
my_release();free_object:
kfree(my_object);
kfree(md1);
return rc;
}
Quoted 9 lines
Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time/usr/bin/spatch../janitor/list_selected_duplicate_statements_in_if_branches3.coccitest-insufficient_goto_chain_usage.c…
info|my_test|md1|rc
first|test-insufficient_goto_chain_usage.c|12|5
tail|test-insufficient_goto_chain_usage.c|36|2
info|my_test|md1|rc
first|test-insufficient_goto_chain_usage.c|36|2
tail|test-insufficient_goto_chain_usage.c|36|2
Could you please explain what the output actually means?
Quoted 4 lines
real 0m0,288s user 0m0,197s sys 0m0,090s
And don't include this information. It's not relevant to the question at hand.
julia
Quoted 8 lines
Are going to try such a test case out also on your development system?
How will the clarification evolve further?
Regards,
Markus
Quoted 10 lines · Markus Elfring
Quoted 10 lines
Quoted 9 lines
Questionable test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time/usr/bin/spatch../janitor/list_selected_duplicate_statements_in_if_branches3.coccitest-insufficient_goto_chain_usage.c…
info|my_test|md1|rc
first|test-insufficient_goto_chain_usage.c|12|5
tail|test-insufficient_goto_chain_usage.c|36|2
info|my_test|md1|rc
first|test-insufficient_goto_chain_usage.c|36|2
tail|test-insufficient_goto_chain_usage.c|36|2
Quoted 8 lines
Quoted 1 line
Could you please explain what the output actually means?
Data are displayed from fields of SmPL position variables, aren't they?
Did you notice that the data display amount is different between the discussed implementations of the functions “my_test” and “snd_seq_fifo_new”?
How would you explain such a remarkable information difference?
I suspect that your problem is just that the control flow in an if leads across a goto, and two ifs that least to the same place are considered to contain the same code. It should be sufficient to say when != goto l1; and when != goto l2; on the ...s before the kfree calls to avoid this behavior.
julia
Quoted 5 lines · Markus Elfring
Quoted 1 line
Thank you for making a complete example.
Is there a need to port it to OCaml programming interfaces so that any difficulties with the interpretation of a bit of Python code can be avoided?
No.
Quoted 4 lines
Which software components do decide how often an SmPL rule should be evaluated for the supported scripting languages?
The number of times is dependent on the size of the set of tuples of argument values. Each distinct tuple of values triggers exactly one execution.
julia
Quoted 4 lines
Regards,
Markus
Quoted 6 lines · Markus Elfring
Quoted 1 line
Thank you for making a complete example.
I tried it out also with the source files of the software “Linux next-20260612”.
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time
/usr/bin/spatch--timeout 45 -j4 --chunksize 1 --no-loops -dir . …/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches3.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/list_selected_duplicate_statements_in_if_branches3-20260612.diff 2> …/Projekte/Bau/Linux/scripts/Coccinelle/list_selected_duplicate_statements_in_if_branches3-errors-20260612.txt
Quoted 8 lines
real 10m28,171s user 38m40,689s sys 0m15,114sMarkus_Elfring@Sonne:…/Projekte/Bau/Linux/scripts/Coccinelle> rg 'info|' list_selected_duplicate_statements_in_if_branches3-20260612.diff|wc -l 5808
Is such a number suspicious together with the information “9620 files match”?
I think you mention kfree in your semantic patch, so the number of matched files comes from there. I have no idea whether the result is suspicious.
julia
Quoted 10 lines · Markus Elfring
Quoted 3 lines
Quoted 3 lines
I tried it out also with the source files of the software “Linux next-20260612”.
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time
/usr/bin/spatch--timeout 45 -j4 --chunksize 1 --no-loops -dir . …/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches3.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/list_selected_duplicate_statements_in_if_branches3-20260612.diff 2> …/Projekte/Bau/Linux/scripts/Coccinelle/list_selected_duplicate_statements_in_if_branches3-errors-20260612.txt…
Quoted 6 lines
Quoted 5 lines
Markus_Elfring@Sonne:…/Projekte/Bau/Linux/scripts/Coccinelle> rg 'info|' list_selected_duplicate_statements_in_if_branches3-20260612.diff|wc -l 5808
Is such a number suspicious together with the information “9620 files match”?
Quoted 8 lines
Quoted 2 lines
I think you mention kfree in your semantic patch, so the number of matched files comes from there.
This is obvious as usual.
Quoted 1 line
I have no idea whether the result is suspicious.
I am trying to determine once more how plausible the mentioned data processing results are.
It would be better to look at them yourself.
julia
Quoted 5 lines
How many development resources do we dare to invest then for more desirable software adjustments?
Regards,
Markus
Quoted 6 lines · Markus Elfring
Quoted 2 lines
Quoted 1 line
I am trying to determine once more how plausible the mentioned data processing results are.
It would be better to look at them yourself.
I started to take another look at a few of the mentioned function implementations.
Quoted 7 lines
Examples:
info|arch_xen_unpopulated_init|regs|rc
first|./arch/arm/xen/enlighten.c|410|2
tail|./arch/arm/xen/enlighten.c|410|2https://elixir.bootlin.com/linux/v7.1-rc7/source/arch/arm/xen/enlighten.c#L307-L413
False positive
I already explained how to solve this problem. You should forbid a goto before at least one of the kfrees. You may need two rules to forbid a goto before each one.
julia
Quoted 23 lines
info|kvm_eiointc_create|s|ret
first|./arch/loongarch/kvm/intc/eiointc.c|642|3
tail|./arch/loongarch/kvm/intc/eiointc.c|656|3https://elixir.bootlin.com/linux/v7.1-rc7/source/arch/loongarch/kvm/intc/eiointc.c#L614-L658
Appropriate update candidateinfo|device_str_attr_create|s|NULL
first|./arch/powerpc/perf/hv-24x7.c|506|2
tail|./arch/powerpc/perf/hv-24x7.c|506|2https://elixir.bootlin.com/linux/v7.1-rc7/source/arch/powerpc/perf/hv-24x7.c#L470-L507
QuestionableRegards,
Markus
Quoted 24 lines · Markus Elfring
Quoted 9 lines
Quoted 7 lines
Examples:
info|arch_xen_unpopulated_init|regs|rc
first|./arch/arm/xen/enlighten.c|410|2
tail|./arch/arm/xen/enlighten.c|410|2https://elixir.bootlin.com/linux/v7.1-rc7/source/arch/arm/xen/enlighten.c#L307-L413
False positiveI already explained how to solve this problem.
I found your hint too terse.
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-06/msg00012.htmlQuoted 3 lines
You should forbid a goto
before at least one of the kfrees. You may need two rules to forbid a goto before each one.Will such a code exclusion influence the search for goto chains in special ways?
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
info|device_str_attr_create|s|NULL
first|./arch/powerpc/perf/hv-24x7.c|506|2
tail|./arch/powerpc/perf/hv-24x7.c|506|2Should it be avoided anyhow that the mentioned source code positions become the same?
Coccinelle has nothing built in to do that. If you want some effect you have to express that yourself in the rule.
julia
Quoted 12 lines · Markus Elfring
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
info|device_str_attr_create|s|NULL
first|./arch/powerpc/perf/hv-24x7.c|506|2
tail|./arch/powerpc/perf/hv-24x7.c|506|2Should it be avoided anyhow that the mentioned source code positions become the same?
Coccinelle has nothing built in to do that.
I suggest to reconsider such a view in more detail.
I would appreciate more clarity about corresponding software functionality.
Quoted 8 lines
How can separately specified if branches be “merged” into the same place?
Quoted 2 lines
If you want some effect you
have to express that yourself in the rule.I can try to avoid known open issues by additional OCaml/Python scripting.
But it seems that I need to know some technical details better accordingly.
Do whatever you want. It seems that the problem is that gotos lead to the same place where a single kfree is found. So forbidding gotos on the path would avoid false positives. Perhaps it is not a perfect solution. A more perfect solution may require a dedicated tool.
julia
Quoted 20 lines · Markus Elfring
Quoted 1 line
Is such a number suspicious together with the information “9620 files match”?
I adjusted the implementation of the function “display_data” another bit so that a questionable condition can be checked and displayed directly.
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time
/usr/bin/spatch--timeout 23 -j4 --chunksize 1 --no-loops -dir . …/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches4.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/list_selected_duplicate_statements_in_if_branches4-20260612.txt 2> …/Projekte/Bau/Linux/scripts/Coccinelle/list_selected_duplicate_statements_in_if_branches4-errors-20260612.txtreal 10m21,520s user 36m21,220s sys 0m18,622sMarkus_Elfring@Sonne:…/Projekte/Bau/Linux/scripts/Coccinelle> rg 'same position' list_selected_duplicate_statements_in_if_branches4-20260612.txt | wc -l 1682
Goto chains are probably applied at several source code places.
Quoted 6 lines
Markus_Elfring@Sonne:…/Projekte/Bau/Linux/scripts/Coccinelle> rg 'hit' list_selected_duplicate_statements_in_if_branches4-20260612.txt | wc -l 254
Such a number looks more promising for possible update candidates, doesn't it?
I don't know what your semantic patch does, so I don't know whether the result is useful or not.
julia
Quoted 77 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Is such a number suspicious together with the information “9620 files match”?
I adjusted the implementation of the function “display_data” another bit so that a questionable condition can be checked and displayed directly.
…
Quoted 8 lines
Quoted 6 lines
Markus_Elfring@Sonne:…/Projekte/Bau/Linux/scripts/Coccinelle> rg 'hit' list_selected_duplicate_statements_in_if_branches4-20260612.txt | wc -l 254
Such a number looks more promising for possible update candidates, doesn't it?
I don't know what your semantic patch does,
Why did you not forward original background information to the mailing list for Coccinelle so far?
2026-06-14
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-06/msg00010.htmlQuoted 2 lines
so I don't know whether the
result is useful or not.So I hope also again that the following SmPL script variant can influence development ideas in desirable directions.
@initialize:python@
@@
import sys
delimiter = "|"def
display_data(fun, source1, source2, x, y):
sys.stdout.write(delimiter.join(("info", fun, x, y))
+ "\n")
place1 = source1[0]
place2 = source2[0]
# if place1 == place2:if (place1.line == place2.line) and (place1.column == place2.column): sys.stdout.write(delimiter.join(("error", "same position", place1.file, place1.line, str(int(place1.column) + 1))) + "\n") else: sys.stdout.write(delimiter.join(("hit", place1.file, place1.line, str(int(place1.column) + 1), place2.line, str(int(place2.column) + 1))) + "\n")@searching exists@
expression e, x;
identifier item, rc, work;
position p1, p2;
type t;
@@
t work(...)
{
... when any
if (...)
{
... when != rc = ewhen != item = x kfree@p1(item); return rc; } ... when any if (...) { ... when != rc = e when != item = x
Quoted 5 lines
kfree@p2(item);
return rc;
}
... when any
}
So why do you think that the number of relevant files diminshed? Coccinelle informs you of what tokens it has considered, but I don't think you included that.
Furthermore, it seems strange that you declare rc to be an identifier. -ENOMEM, for example, is not an identifier. It is an expression.
And you still have no checks for gotos, so you will still get cases where both kfrees are on the same line. Another approach is to just adjust your python code to discard such cases. I see that you do that already. But why not just ignore such results instead of complaining about them?
Is there really nothing like printf in python? sys.stdout.write(delimiter.join looks very primitive.
julia
Quoted 32 lines
@script:python collection@
fun << searching.work;
x << searching.item;
y << searching.rc;
p1 << searching.p1;
p2 << searching.p2;
@@display_data(fun, p1, p2, x, y)Test result examples:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe>/usr/bin/spatch../janitor/list_selected_duplicate_statements_in_if_branches4.coccisnd_seq_fifo_new-excerpt-20260608.c…
info|snd_seq_fifo_new|f|NULL
hit|snd_seq_fifo_new-excerpt-20260608.c|13|3|18|3
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe>/usr/bin/spatch../janitor/list_selected_duplicate_statements_in_if_branches4.coccitest-insufficient_goto_chain_usage.c…
info|my_test|md1|rc
hit|test-insufficient_goto_chain_usage.c|12|5|36|2
info|my_test|md1|rc
error|same position|test-insufficient_goto_chain_usage.c|36|2
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses>/usr/bin/spatcharch/arm/xen/enlighten.c/home/altes_Heim2/elfring/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches4.cocci…
info|arch_xen_unpopulated_init|regs|rc
error|same position|arch/arm/xen/enlighten.c|410|2Regards,
Markus
Am 16.06.26 um 09:19 schrieb Julia Lawall:
Quoted 87 lines · Markus Elfring
Quoted 78 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Is such a number suspicious together with the information “9620 files match”?
I adjusted the implementation of the function “display_data” another bit so that a questionable condition can be checked and displayed directly.
…
Quoted 8 lines
Quoted 6 lines
Markus_Elfring@Sonne:…/Projekte/Bau/Linux/scripts/Coccinelle> rg 'hit' list_selected_duplicate_statements_in_if_branches4-20260612.txt | wc -l 254
Such a number looks more promising for possible update candidates, doesn't it?
I don't know what your semantic patch does,
Why did you not forward original background information to the mailing list for Coccinelle so far?
2026-06-14
https://lore.kernel.org/cocci/[email protected]/
https://sympa.inria.fr/sympa/arc/cocci/2026-06/msg00010.htmlQuoted 2 lines
so I don't know whether the
result is useful or not.So I hope also again that the following SmPL script variant can influence development ideas in desirable directions.
@initialize:python@
@@
import sys
delimiter = "|"def
display_data(fun, source1, source2, x, y):
sys.stdout.write(delimiter.join(("info", fun, x, y))
+ "\n")
place1 = source1[0]
place2 = source2[0]
# if place1 == place2:if (place1.line == place2.line) and (place1.column == place2.column): sys.stdout.write(delimiter.join(("error", "same position", place1.file, place1.line, str(int(place1.column) + 1))) + "\n") else: sys.stdout.write(delimiter.join(("hit", place1.file, place1.line, str(int(place1.column) + 1), place2.line, str(int(place2.column) + 1))) + "\n")@searching exists@
expression e, x;
identifier item, rc, work;
position p1, p2;
type t;
@@
t work(...)
{
... when any
if (...)
{
... when != rc = ewhen != item = x kfree@p1(item); return rc; } ... when any if (...) { ... when != rc = e when != item = xQuoted 5 lines
kfree@p2(item);
return rc;
}
... when any
}
Quoted 1 line
So why do you think that the number of relevant files diminshed?
I find that further development considerations can become more interesting also according to the presented checks for source code positions.
Quoted 2 lines
Coccinelle informs you of what tokens it has considered, but I don't think you included that.
Which data would you miss at the moment?
Quoted 1 line
Furthermore, it seems strange that you declare rc to be an identifier.
I obviously restricted the source code approach so far.
Quoted 1 line
-ENOMEM, for example, is not an identifier. It is an expression.
This is fine.
The detection of duplicate error code returns can eventually be achieved with another SmPL script variant.
Quoted 1 line
And you still have no checks for gotos,
This is intended so far.
Quoted 2 lines
so you will still get cases where
both kfrees are on the same line.
I hope also that further case distinctions will become helpful for corresponding clarifications.
Quoted 2 lines
Another approach is to just adjust your
python code to discard such cases. I see that you do that already.
Interesting …
Quoted 1 line
But why not just ignore such results instead of complaining about them?
I see opportunities for corresponding data processing improvements.
Quoted 1 line
Is there really nothing like printf in python?
There are constraints to consider for the application of such programming interfaces.
https://docs.python.org/3/library/functions.html#print
Quoted 1 line
sys.stdout.write(delimiter.join looks very primitive.
See also:
https://docs.python.org/3/library/sys.html#sys.stdout
Regards,
Markus
Quoted 66 lines · Markus Elfring
Quoted 1 line
So why do you think that the number of relevant files diminshed?
I got into the mood to try another SmPL script variant out.
@initialize:python@
@@
import sys
delimiter = "|"def
display_data(source1, source2):place1 = source1[0] place2 = source2[0] # if place1 == place2: if (place1.line == place2.line) and (place1.column == place2.column): sys.stdout.write(delimiter.join(("same position", place1.current_element, place1.file, place1.line, str(int(place1.column) + 1), "-", "-" )) + "\n") else: sys.stdout.write(delimiter.join(("update candidate", place1.current_element, place1.file, place1.line, str(int(place1.column) + 1), place2.line, str(int(place2.column) + 1))) + "\n")@searching exists@
expression e, x;
identifier item, rc;
position p1, p2;
@@
if (...)
{
... when != rc = ewhen != item = x kfree@p1(item); return rc; } ... when any if (...) { ... when != rc = e when != item = xkfree@p2(item);
return rc;
}@script:python collection@
p1 << searching.p1;
p2 << searching.p2;
@@display_data(p1, p2)Test result:
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time/usr/bin/spatch--timeout 23 -j4 --chunksize 1 --no-loops -dir . …/Projekte/Coccinelle/janitor/list_selected_duplicate_statements_in_if_branches5.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/list_selected_duplicate_statements_in_if_branches5-20260615.txt 2> …/Projekte/Bau/Linux/scripts/Coccinelle/list_selected_duplicate_statements_in_if_branches5-errors-20260615.txt
Quoted 7 lines
real 9m40,850s user 32m55,318s sys 0m17,383sThe provided data could be converted into a pivot table. I transformed such information into the following report.
Which means what?
Quoted 47 lines
file|function name|incidence fs/hpfs/dnode.c|map_fnode_dirent|40 drivers/media/dvb-frontends/cxd2880/cxd2880_top.c|cxd2880_attach|15 drivers/mtd/tests/pagetest.c|crosstest|10 drivers/media/pci/cx88/cx88-cards.c|cx88_core_create|10 drivers/usb/serial/io_ti.c|do_download_mode|9
|wmid3_set_device_status|6 mm/vmalloc.c|pcpu_get_vm_areas|5 drivers/net/ethernet/intel/idpf/idpf_lib.c|idpf_vport_alloc|4 fs/jfs/jfs_dtree.c|jfs_readdir|4 sound/soc/amd/acp/acp-platform.c|acp_dma_open|3 drivers/gpu/drm/amd/amdgpu/atom.c|amdgpu_atom_parse|3 drivers/gpu/drm/radeon/atom.c|atom_parse|3 drivers/s390/net/ctcm_mpc.c|ctcmpc_init_mpc_group|3 drivers/tty/n_gsm.c|gsm_alloc_mux|3 |hp_init_bios_package_attribute|3 net/mac80211/iface.c|ieee80211_add_virtual_monitor|3 drivers/nvme/target/fabrics-cmd-auth.c|nvmet_auth_reply|3 net/sched/act_ife.c|tcf_ife_init|3 drivers/iommu/tegra-smmu.c|tegra_smmu_domain_alloc_paging|3 drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c|ttusb_probe|3 drivers/scsi/device_handler/scsi_dh_alua.c|alua_rtpg|2 drivers/media/pci/cobalt/cobalt-driver.c|cobalt_probe|2 drivers/media/pci/cx18/cx18-driver.c|cx18_probe|2 drivers/media/dvb-frontends/dib9000.c|dib9000_attach|2 kernel/trace/trace_events_trigger.c|event_enable_trigger_parse|2 net/sched/cls_fw.c|fw_change|2 arch/powerpc/platforms/powernv/opal-imc.c|imc_pmu_create|2 drivers/media/pci/ivtv/ivtv-driver.c|ivtv_probe|2 drivers/gpu/drm/gma500/psb_intel_sdvo.c|psb_intel_sdvo_init|2 drivers/staging/rtl8723bs/core/rtw_xmit.c|rtw_mgmt_xmitframe_coalesce|2 drivers/soundwire/intel_init.c|sdw_intel_probe_controller|2 drivers/crypto/hisilicon/sec/sec_algs.c|sec_alg_skcipher_crypto|2 sound/sh/aica.c|snd_aica_probe|2 |sof_link_load|2 drivers/platform/x86/toshiba_bluetooth.c|toshiba_bt_rfkill_probe|2 net/wireless/core.c|wiphy_new_nm|2Can such technical details be helpful for further improvements also according to the Coccinelle software?
Regards,
Markus
Quoted 61 lines · Markus Elfring
Quoted 2 lines
Quoted 2 lines
file|function name|incidence
fs/hpfs/dnode.c|map_fnode_dirent|40…
Quoted 1 line
How will the software run time characteristics evolve further?
I hope again that this information can trigger more constructive clarifications also with the help of the following SmPL script variant.
@initialize:python@
@@
import sys, time
delimiter = "|"def
convert_to_seconds(x):return x / (10 ** 9)def
get_seconds():
return convert_to_seconds(time.time_ns())def
display_data(source1, source2):x = time.time_ns() sys.stderr.write(f"display_data() was called after {x - init_time} ns from initialisation.\n") place1 = source1[0] place2 = source2[0] if (place1.line == place2.line) and (place1.column == place2.column): sys.stdout.write(delimiter.join(('"same position"', place1.current_element, place1.file, place1.line, str(int(place1.column) + 1), '"-"', '"-"' )) + "\n") else: sys.stdout.write(delimiter.join(('"update candidate"', place1.current_element, place1.file, place1.line, str(int(place1.column) + 1), place2.line, str(int(place2.column) + 1))) + "\n") sys.stderr.write(f"display_data() was finished after {time.time_ns() - x} ns.\n")
init_time=time.time_ns()sys.stderr.write(f"{convert_to_seconds(init_time)}: Initialisation was finished.\n")@searching exists@
expression e, x;
identifier item, rc;
position p1, p2;
@@
if (...)
{
... when != rc = e
Quoted 9 lines
when != item = x
kfree@p1(item);
return rc;
}
... when any
if (...)
{
... when != rc = e
when != item = xDo you really require that e and x bind to the same things at the two occurrences? If the running time is slow, that is probably why?
julia
Quoted 63 lines
kfree@p2(item);
return rc;
}@script:python collection@
p1 << searching.p1;
p2 << searching.p2;
@@display_data(p1, p2)Function implementation example:
https://elixir.bootlin.com/linux/v7.1/source/fs/hpfs/dnode.c#L994-L1095Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time/usr/bin/spatch--no-loops../janitor/list_selected_duplicate_statements_in_if_branches9.coccimap_fnode_dirent-excerpt-20260618.c…
1781883816.6302867: Initialisation was finished.
HANDLING:map_fnode_dirent-excerpt-20260618.cdisplay_data()was called after 3163180203 ns from initialisation.
"update candidate"|map_fnode_dirent|map_fnode_dirent-excerpt-20260618.c|31|3|37|3display_data()was finished after 108330 ns.display_data()was called after 3163385848 ns from initialisation.
"update candidate"|map_fnode_dirent|map_fnode_dirent-excerpt-20260618.c|31|3|46|3display_data()was finished after 33643 ns.display_data()was called after 3163493101 ns from initialisation.
"update candidate"|map_fnode_dirent|map_fnode_dirent-excerpt-20260618.c|31|3|58|3display_data()was finished after 25862 ns.display_data()was called after 3163597031 ns from initialisation.
"update candidate"|map_fnode_dirent|map_fnode_dirent-excerpt-20260618.c|31|3|72|5display_data()was finished after 23952 ns.
…real 0m3,433s user 0m3,321s sys 0m0,107sCan such measurements influence any development approaches?
Would you occasionally observe also in your test environments that data processing durations would look prohibitive?
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time
/usr/bin/spatch--no-loops../janitor/list_selected_duplicate_statements_in_if_branches8.coccimap_fnode_dirent-excerpt-20260618.c…
Using SQLAlchemy version:
2.0.50
1781884889.1493413: Initialisation was finished.
HANDLING:map_fnode_dirent-excerpt-20260618.c
^C C-c intercepted, will do some cleaning before exitingreal 22m54,500s user 22m47,974s sys 0m2,294sHow can the software situation be improved further here?
Regards,
Markus
Quoted 21 lines · Markus Elfring
…
Quoted 20 lines
Quoted 19 lines
sys.stderr.write(f"{convert_to_seconds(init_time)}: Initialisation was finished.\n")@searching exists@
expression e, x;
identifier item, rc;
position p1, p2;
@@
if (...)
{
... when != rc = ewhen != item = x kfree@p1(item); return rc; } ... when any if (...) { ... when != rc = e when != item = x
Quoted 5 lines
Quoted 2 lines
Do you really require that e and x bind to the same things at the two occurrences?
I would expect more that mentioned identifier variables should usually match distinct things.
What you expect doesn't matter. The semantics of Coccinelle is that if there are two occurrences of a metavariable and they are not in different branches of a disjunction, they have to match the same thing.
julia
Quoted 12 lines
Quoted 3 lines
If the running time is slow, that is probably why?
I got the impression that other factors should be also reconsidered.
How much can you follow presented execution duration measurements for corresponding test reproductions?
Regards,
Markus
Quoted 77 lines · Markus Elfring
Quoted 1 line
Can such measurements influence any development approaches?
I suggest to take also information from another SmPL script variant better into account.
@initialize:python@
@@
import sys, time
records = []def
convert_to_seconds(x):return x / (10 ** 9)def
store_data(source):
"""Add data to the list."""
x =time.monotonic_ns()
sys.stderr.write(f"store_data() was called after {x - init_time} ns from initialisation.\n")for place in source:
records.append(1)
sys.stderr.write(f"store_data() was finished after {time.monotonic_ns() - x} ns.\n")
init_time=time.monotonic_ns()sys.stderr.write(f"{convert_to_seconds(init_time)}: Initialisation was finished.\n")@searching exists@
expression e, x;
identifier item, rc;
position p;
@@
if (...)
{
... when != rc = ewhen != item = xkfree@p(item);
return rc;
}@script:python collection@
p << searching.p;
@@store_data(p)@finalize:python@
@@
if records:
sys.stdout.write(f"{len(records)} selected statement combinations were found after {time.monotonic_ns()-init_time} ns from initialisation.\n")
else:
sys.stderr.write("No result for this analysis!\n")Test result:
Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time echo $(grep -E 'kfree\(name2\);'map_fnode_dirent-excerpt-20260618.c| wc -l) 9real 0m0,007s user 0m0,002s sys 0m0,005sMarkus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time
/usr/bin/spatch--no-loops../janitor/count_selected_if_branches.coccimap_fnode_dirent-excerpt-20260618.c…
5647.095966535: Initialisation was finished.
HANDLING:map_fnode_dirent-excerpt-20260618.cstore_data()was called after 365741113 ns from initialisation.store_data()was finished after 46703 ns.
…store_data()was called after 366355893 ns from initialisation.store_data()was finished after 13051 ns.
9 selected statement combinations were found after 366512248 ns from initialisation.real 0m0,602s user 0m0,517s sys 0m0,081s
Quoted 5 lines
The last
kfree()call is counted here despite of the implementation detail that it is actually not explicitly specified within a known if branch.How would you determine the incidence distribution for discussed if branches from all Linux source files then?
As now mentioned numerous times, you have to prevent the ... from matching a goto.
julia
Quoted 4 lines
Regards,
Markus
Quoted 10 lines · Markus Elfring
Quoted 7 lines
Quoted 5 lines
The last
kfree()call is counted here despite of the implementation detail that it is actually not explicitly specified within a known if branch.How would you determine the incidence distribution for discussed if branches from all Linux source files then?
As now mentioned numerous times, you have to prevent the ... from matching a goto.
Does this suggestion indicate a known data processing conflict for which we would be looking for a better solution than a code exclusion?
No. Its a nice and indtended feature of Coccinelle that if branch patterns drift over gotos. Because often you want to know what is reachable from the if branch, not exactly what is between the {}. If you want something different, you have to specify that.
julia