public inbox for cocci@systeme.lip6.fr
 help / color / mirror / Atom feed
From: Tobias Deiminger <tobias.deiminger@posteo.de>
To: cocci@inria.fr
Subject: [cocci] bug: Matching a specific declarer actually matches any declarer
Date: Mon, 01 Dec 2025 15:28:36 +0000	[thread overview]
Message-ID: <7bb043f9fd00c7e20ebc75353e697a51@posteo.de> (raw)

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

             reply	other threads:[~2025-12-01 15:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-01 15:28 Tobias Deiminger [this message]
2025-12-01 15:35 ` [cocci] bug: Matching a specific declarer actually matches any declarer 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

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=7bb043f9fd00c7e20ebc75353e697a51@posteo.de \
    --to=tobias.deiminger@posteo.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