public inbox for cocci@systeme.lip6.fr
 help / color / mirror / Atom feed
* [cocci] bug: Matching a specific declarer actually matches any declarer
@ 2025-12-01 15:28 Tobias Deiminger
  2025-12-01 15:35 ` Julia Lawall
  2025-12-01 16:00 ` [cocci] Matching a specific declarer? Markus Elfring
  0 siblings, 2 replies; 6+ messages in thread
From: Tobias Deiminger @ 2025-12-01 15:28 UTC (permalink / raw)
  To: cocci

Hi,

to reproduce the issue, try mutex2.cocci from coccinellery [1] with the 
code below.

Expectation: Only spin_lock calls where the variable was declared with 
DEFINE_MUTEX() are patched.

Actual: The declarer name seems to be ignored. All spin_lock calls are 
patched, regardless of the declarer name

// mutex2.c
DEFINE_MUTEX(my_mutex);
OTHER_DECLARER(other_mutex);

void main() {
     // this should be changed, declarer was DEFINE_MUTEX
     spin_lock(&my_mutex);

     // this should not be changed, declarer was OTHER_DECLARER
     spin_lock(&other_mutex)
}

// mutex2.cocci
@def@
declarer DEFINE_MUTEX;
identifier m;
@@

DEFINE_MUTEX(m);

@@
identifier def.m;
@@

(
- spin_lock(&m)
+ mutex_lock(&m)
|
- spin_unlock(&m)
+ mutex_unlock(&m)
)

The unexpected result:

$ spatch --sp-file mutex2.cocci mutex2.c
init_defs_builtins: /usr/lib/coccinelle/standard.h
HANDLING: mutex2.c
SPECIAL NAMES: adding OTHER_DECLARER as a declarer
diff =
--- mutex2.c
+++ /tmp/cocci-output-71243-6eaa4e-my.c
@@ -3,8 +3,8 @@ OTHER_DECLARER(other_mutex);

  void main() {
      // this should be changed, declarer was DEFINE_MUTEX
-    spin_lock(&my_mutex);
+    mutex_lock(&my_mutex);

      // this should not be changed, declarer was OTHER_DECLARER
-    spin_lock(&other_mutex)
+    mutex_lock(&other_mutex)
  }


Could you confirm, and maybe suggest a workaround? I used the 
coccinellery example as reproducer because it's public, but actually 
stumbled upon the issue in a simpler case: I searched for all 
occurrences of DEVICE_ATTR_RO(attr) in the Linux kernel, but actually 
found every place where *any* macro was used to declare something.

Cheers
Tobias

PS: I'm using spatch 1.3 from Debian trixie.

[1] 
https://github.com/coccinelle/coccinellery/blob/master/cris/mutex2.cocci

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-12-01 17:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-01 15:28 [cocci] bug: Matching a specific declarer actually matches any declarer Tobias Deiminger
2025-12-01 15:35 ` Julia Lawall
2025-12-01 16:18   ` Tobias Deiminger
2025-12-01 16:00 ` [cocci] Matching a specific declarer? Markus Elfring
2025-12-01 16:53   ` Tobias Deiminger
2025-12-01 17:21     ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox