From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: linux-kernel@vger.kernel.org, Peng Fan <peng.fan@nxp.com>,
linux-trace-kernel@vger.kernel.org
Subject: [PATCH] tracing: use assign_bit() where applicable
Date: Sun, 20 Sep 2026 10:28:10 +0800 [thread overview]
Message-ID: <20260920022810.3145921-1-peng.fan@oss.nxp.com> (raw)
From: Peng Fan <peng.fan@nxp.com>
Convert open-coded if/else with set_bit/clear_bit the assign_bit API.
Done with Coccinelle semantic patch:
// set_bit -> clear_bit => assign_bit
@@
expression cond, bit, addr;
@@
-if (cond)
- set_bit(bit, addr);
-else
- clear_bit(bit, addr);
+assign_bit(bit, addr, cond);
// clear_bit -> set_bit => assign_bit
@@
expression cond, bit, addr;
@@
-if (cond)
- clear_bit(bit, addr);
-else
- set_bit(bit, addr);
+assign_bit(bit, addr, !cond);
// __set_bit -> __clear_bit => __assign_bit
@@
expression cond, bit, addr;
@@
-if (cond)
- __set_bit(bit, addr);
-else
- __clear_bit(bit, addr);
+__assign_bit(bit, addr, cond);
// __clear_bit -> __set_bit => __assign_bit
@@
expression cond, bit, addr;
@@
-if (cond)
- __clear_bit(bit, addr);
-else
- __set_bit(bit, addr);
+__assign_bit(bit, addr, !cond);
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
kernel/trace/trace_events.c | 12 ++++--------
kernel/trace/trace_events_trigger.c | 11 +++--------
kernel/trace/trace_events_user.c | 5 +----
3 files changed, 8 insertions(+), 20 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 30c0ddf90887..72a210da67d6 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -859,10 +859,8 @@ static int __ftrace_event_enable_disable(struct trace_event_file *file,
WARN_ON_ONCE(ret);
}
/* If in soft mode, just set the SOFT_DISABLE_BIT, else clear it */
- if (soft_mode)
- set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
- else
- clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags);
+ assign_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags,
+ soft_mode);
break;
case 1:
/*
@@ -4273,10 +4271,8 @@ struct event_probe_data {
static void update_event_probe(struct event_probe_data *data)
{
- if (data->enable)
- clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
- else
- set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
+ assign_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags,
+ !data->enable);
}
static void
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index 4d2fde996c0f..3b5e14fd0dd9 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -674,10 +674,7 @@ void update_cond_flag(struct trace_event_file *file)
}
}
- if (set_cond)
- set_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags);
- else
- clear_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags);
+ assign_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags, set_cond);
}
/**
@@ -1673,10 +1670,8 @@ event_enable_trigger(struct event_trigger_data *data,
{
struct enable_trigger_data *enable_data = data->private_data;
- if (enable_data->enable)
- clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags);
- else
- set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags);
+ assign_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags,
+ !enable_data->enable);
}
static bool
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index f658c3a77aa7..055894cb999c 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -590,10 +590,7 @@ static int user_event_enabler_write(struct user_event_mm *mm,
ptr = kaddr + (uaddr & ~PAGE_MASK);
/* Update bit atomically, user tracers must be atomic as well */
- if (enabler->event && enabler->event->status)
- set_bit(bit, ptr);
- else
- clear_bit(bit, ptr);
+ assign_bit(bit, ptr, enabler->event && enabler->event->status);
kunmap_local(kaddr);
unpin_user_pages_dirty_lock(&page, 1, true);
--
2.51.0
next reply other threads:[~2026-09-20 2:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 2:28 Peng Fan (OSS) [this message]
2026-09-20 11:21 ` [PATCH] tracing: use assign_bit() where applicable Steven Rostedt
2026-09-21 6:31 ` Peng Fan
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=20260920022810.3145921-1-peng.fan@oss.nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=peng.fan@nxp.com \
--cc=rostedt@goodmis.org \
/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 NNTP newsgroup(s).