2024-03-26 18:45:32

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 0/8] kernel: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Maxim Moskalets (8):
bpf: replace seq_puts by seq_putc
cgroup: replace seq_puts by seq_putc
trace: replace seq_puts by seq_putc
module: replace seq_puts by seq_putc
sched: replace seq_puts by seq_putc
locking: replace seq_puts by seq_putc
time: replace seq_puts by seq_putc
kernel: replace seq_puts by seq_putc

kernel/bpf/arraymap.c | 6 +++---
kernel/bpf/bpf_struct_ops.c | 2 +-
kernel/bpf/hashtab.c | 4 ++--
kernel/bpf/local_storage.c | 4 ++--
kernel/cgroup/cgroup.c | 2 +-
kernel/cgroup/debug.c | 6 +++---
kernel/latencytop.c | 2 +-
kernel/locking/lockdep_proc.c | 24 ++++++++++++------------
kernel/module/procfs.c | 4 ++--
kernel/module/tracking.c | 2 +-
kernel/sched/cpuacct.c | 4 ++--
kernel/sched/debug.c | 14 +++++++-------
kernel/time/test_udelay.c | 2 +-
kernel/trace/trace_events_hist.c | 26 +++++++++++++-------------
kernel/trace/trace_events_user.c | 8 ++++----
kernel/trace/trace_hwlat.c | 4 ++--
16 files changed, 57 insertions(+), 57 deletions(-)


base-commit: 928a87efa42302a23bb9554be081a28058495f22
--
2.39.2



2024-03-26 18:46:01

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 1/8] bpf: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Signed-off-by: Maxim Moskalets <[email protected]>
---
kernel/bpf/arraymap.c | 6 +++---
kernel/bpf/bpf_struct_ops.c | 2 +-
kernel/bpf/hashtab.c | 4 ++--
kernel/bpf/local_storage.c | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
index 13358675ff2e..d45bffe49dea 100644
--- a/kernel/bpf/arraymap.c
+++ b/kernel/bpf/arraymap.c
@@ -457,7 +457,7 @@ static void array_map_seq_show_elem(struct bpf_map *map, void *key,
if (map->btf_key_type_id)
seq_printf(m, "%u: ", *(u32 *)key);
btf_type_seq_show(map->btf, map->btf_value_type_id, value, m);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');

rcu_read_unlock();
}
@@ -478,7 +478,7 @@ static void percpu_array_map_seq_show_elem(struct bpf_map *map, void *key,
seq_printf(m, "\tcpu%d: ", cpu);
btf_type_seq_show(map->btf, map->btf_value_type_id,
per_cpu_ptr(pptr, cpu), m);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
seq_puts(m, "}\n");

@@ -955,7 +955,7 @@ static void prog_array_map_seq_show_elem(struct bpf_map *map, void *key,
prog_id = prog_fd_array_sys_lookup_elem(ptr);
btf_type_seq_show(map->btf, map->btf_value_type_id,
&prog_id, m);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
}

diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index 43356faaa057..bf94043f0975 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -833,7 +833,7 @@ static void bpf_struct_ops_map_seq_show_elem(struct bpf_map *map, void *key,
btf_type_seq_show(st_map->btf,
map->btf_vmlinux_value_type_id,
value, m);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}

kfree(value);
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 3a088a5349bc..db5105275545 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -1577,7 +1577,7 @@ static void htab_map_seq_show_elem(struct bpf_map *map, void *key,
btf_type_seq_show(map->btf, map->btf_key_type_id, key, m);
seq_puts(m, ": ");
btf_type_seq_show(map->btf, map->btf_value_type_id, value, m);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');

rcu_read_unlock();
}
@@ -2421,7 +2421,7 @@ static void htab_percpu_map_seq_show_elem(struct bpf_map *map, void *key,
seq_printf(m, "\tcpu%d: ", cpu);
btf_type_seq_show(map->btf, map->btf_value_type_id,
per_cpu_ptr(pptr, cpu), m);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
seq_puts(m, "}\n");

diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
index a04f505aefe9..3969eb0382af 100644
--- a/kernel/bpf/local_storage.c
+++ b/kernel/bpf/local_storage.c
@@ -431,7 +431,7 @@ static void cgroup_storage_seq_show_elem(struct bpf_map *map, void *key,
seq_puts(m, ": ");
btf_type_seq_show(map->btf, map->btf_value_type_id,
&READ_ONCE(storage->buf)->data[0], m);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
} else {
seq_puts(m, ": {\n");
for_each_possible_cpu(cpu) {
@@ -439,7 +439,7 @@ static void cgroup_storage_seq_show_elem(struct bpf_map *map, void *key,
btf_type_seq_show(map->btf, map->btf_value_type_id,
per_cpu_ptr(storage->percpu_buf, cpu),
m);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
seq_puts(m, "}\n");
}
--
2.39.2


2024-03-26 18:46:22

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 2/8] cgroup: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Signed-off-by: Maxim Moskalets <[email protected]>
---
kernel/cgroup/cgroup.c | 2 +-
kernel/cgroup/debug.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index a66c088c851c..011db8474d69 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -6300,7 +6300,7 @@ int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns,

seq_puts(m, buf);
} else {
- seq_puts(m, "/");
+ seq_putc(m, '/');
}

if (cgroup_on_dfl(cgrp) && cgroup_is_dead(cgrp))
diff --git a/kernel/cgroup/debug.c b/kernel/cgroup/debug.c
index 80aa3f027ac3..d18f7dcb4def 100644
--- a/kernel/cgroup/debug.c
+++ b/kernel/cgroup/debug.c
@@ -55,7 +55,7 @@ static int current_css_set_read(struct seq_file *seq, void *v)
seq_printf(seq, "css_set %pK %d", cset, refcnt);
if (refcnt > cset->nr_tasks)
seq_printf(seq, " +%d", refcnt - cset->nr_tasks);
- seq_puts(seq, "\n");
+ seq_putc(seq, '\n');

/*
* Print the css'es stored in the current css_set.
@@ -159,7 +159,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
extra_refs += extra;
}
}
- seq_puts(seq, "\n");
+ seq_putc(seq, '\n');

list_for_each_entry(task, &cset->tasks, cg_list) {
if (count++ <= MAX_TASKS_SHOWN_PER_CSS)
@@ -189,7 +189,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
if (!dead_cnt && !extra_refs && !threaded_csets)
return 0;

- seq_puts(seq, "\n");
+ seq_putc(seq, '\n');
if (threaded_csets)
seq_printf(seq, "threaded css_sets = %d\n", threaded_csets);
if (extra_refs)
--
2.39.2


2024-03-26 18:53:46

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 7/8] time: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Signed-off-by: Maxim Moskalets <[email protected]>
---
kernel/time/test_udelay.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/test_udelay.c b/kernel/time/test_udelay.c
index 20d5df631570..82fe239c3184 100644
--- a/kernel/time/test_udelay.c
+++ b/kernel/time/test_udelay.c
@@ -59,7 +59,7 @@ static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters)
(usecs * 1000) - allowed_error_ns, min, avg, max);
if (fail_count)
seq_printf(s, " FAIL=%d", fail_count);
- seq_puts(s, "\n");
+ seq_putc(s, '\n');

return 0;
}
--
2.39.2


2024-03-26 18:56:35

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 6/8] locking: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Signed-off-by: Maxim Moskalets <[email protected]>
---
kernel/locking/lockdep_proc.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index e2bfb1db589d..4612d1c4f45e 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -101,17 +101,17 @@ static int l_show(struct seq_file *m, void *v)

seq_printf(m, ": ");
print_name(m, class);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');

if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
list_for_each_entry(entry, &class->locks_after, entry) {
if (entry->distance == 1) {
seq_printf(m, " -> [%p] ", entry->class->key);
print_name(m, entry->class);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
}
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}

return 0;
@@ -175,9 +175,9 @@ static int lc_show(struct seq_file *m, void *v)

seq_printf(m, "[%p] ", class->key);
print_name(m, class);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
- seq_puts(m, "\n");
+ seq_putc(m, '\n');

return 0;
}
@@ -379,7 +379,7 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
/*
* Zapped classes and lockdep data buffers reuse statistics.
*/
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
seq_printf(m, " zapped classes: %11lu\n",
nr_zapped_classes);
#ifdef CONFIG_PROVE_LOCKING
@@ -422,10 +422,10 @@ static void seq_line(struct seq_file *m, char c, int offset, int length)
int i;

for (i = 0; i < offset; i++)
- seq_puts(m, " ");
+ seq_putc(m, ' ');
for (i = 0; i < length; i++)
seq_printf(m, "%c", c);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}

static void snprint_time(char *buf, size_t bufsiz, s64 nr)
@@ -512,7 +512,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
seq_lock_time(m, &stats->write_waittime);
seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
seq_lock_time(m, &stats->write_holdtime);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}

if (stats->read_holdtime.nr) {
@@ -521,7 +521,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
seq_lock_time(m, &stats->read_waittime);
seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
seq_lock_time(m, &stats->read_holdtime);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}

if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
@@ -561,9 +561,9 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
ip, (void *)class->contending_point[i]);
}
if (i) {
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
seq_line(m, '.', 0, 40 + 1 + 12 * (14 + 1));
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
}

--
2.39.2


2024-03-26 18:57:56

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 5/8] sched: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Signed-off-by: Maxim Moskalets <[email protected]>
---
kernel/sched/cpuacct.c | 4 ++--
kernel/sched/debug.c | 14 +++++++-------
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index 0de9dda09949..0c1ce2e1c89b 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -245,14 +245,14 @@ static int cpuacct_all_seq_show(struct seq_file *m, void *V)
seq_puts(m, "cpu");
for (index = 0; index < CPUACCT_STAT_NSTATS; index++)
seq_printf(m, " %s", cpuacct_stat_desc[index]);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');

for_each_possible_cpu(cpu) {
seq_printf(m, "%d", cpu);
for (index = 0; index < CPUACCT_STAT_NSTATS; index++)
seq_printf(m, " %llu",
cpuacct_cpuusage_read(ca, cpu, index));
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
return 0;
}
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 8d5d98a5834d..03d78cff66e3 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -62,7 +62,7 @@ static int sched_feat_show(struct seq_file *m, void *v)
seq_puts(m, "NO_");
seq_printf(m, "%s ", sched_feat_names[i]);
}
- seq_puts(m, "\n");
+ seq_putc(m, '\n');

return 0;
}
@@ -251,15 +251,15 @@ static int sched_dynamic_show(struct seq_file *m, void *v)

for (i = 0; i < ARRAY_SIZE(preempt_modes); i++) {
if (preempt_dynamic_mode == i)
- seq_puts(m, "(");
+ seq_putc(m, '(');
seq_puts(m, preempt_modes[i]);
if (preempt_dynamic_mode == i)
- seq_puts(m, ")");
+ seq_putc(m, ')');

- seq_puts(m, " ");
+ seq_putc(m, ' ');
}

- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}

@@ -389,9 +389,9 @@ static int sd_flags_show(struct seq_file *m, void *v)

for_each_set_bit(idx, &flags, __SD_FLAG_CNT) {
seq_puts(m, sd_flag_debug[idx].name);
- seq_puts(m, " ");
+ seq_putc(m, ' ');
}
- seq_puts(m, "\n");
+ seq_putc(m, '\n');

return 0;
}
--
2.39.2


2024-03-26 18:59:24

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 8/8] kernel: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Signed-off-by: Maxim Moskalets <[email protected]>
---
kernel/latencytop.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/latencytop.c b/kernel/latencytop.c
index 781249098cb6..08fe9ce35ec3 100644
--- a/kernel/latencytop.c
+++ b/kernel/latencytop.c
@@ -261,7 +261,7 @@ static int lstats_show(struct seq_file *m, void *v)

seq_printf(m, " %ps", (void *)bt);
}
- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}
}
return 0;
--
2.39.2


2024-03-26 19:13:13

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 3/8] trace: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Signed-off-by: Maxim Moskalets <[email protected]>
---
kernel/trace/trace_events_hist.c | 26 +++++++++++++-------------
kernel/trace/trace_events_user.c | 8 ++++----
kernel/trace/trace_hwlat.c | 4 ++--
3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 6ece1308d36a..5992278cbfb5 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -4898,14 +4898,14 @@ static void print_action_spec(struct seq_file *m,
for (i = 0; i < hist_data->n_save_vars; i++) {
seq_printf(m, "%s", hist_data->save_vars[i]->var->var.name);
if (i < hist_data->n_save_vars - 1)
- seq_puts(m, ",");
+ seq_putc(m, ',');
}
} else if (data->action == ACTION_TRACE) {
if (data->use_trace_keyword)
seq_printf(m, "%s", data->synth_event_name);
for (i = 0; i < data->n_params; i++) {
if (i || data->use_trace_keyword)
- seq_puts(m, ",");
+ seq_putc(m, ',');
seq_printf(m, "%s", data->params[i]);
}
}
@@ -4924,7 +4924,7 @@ static void print_track_data_spec(struct seq_file *m,

print_action_spec(m, hist_data, data);

- seq_puts(m, ")");
+ seq_putc(m, ')');
}

static void print_onmatch_spec(struct seq_file *m,
@@ -4938,7 +4938,7 @@ static void print_onmatch_spec(struct seq_file *m,

print_action_spec(m, hist_data, data);

- seq_puts(m, ")");
+ seq_putc(m, ')');
}

static bool actions_match(struct hist_trigger_data *hist_data,
@@ -5413,9 +5413,9 @@ static void hist_trigger_print_key(struct seq_file *m,
}

if (!multiline)
- seq_puts(m, " ");
+ seq_putc(m, ' ');

- seq_puts(m, "}");
+ seq_putc(m, '}');
}

/* Get the 100 times of the percentage of @val in @total */
@@ -5511,13 +5511,13 @@ static void hist_trigger_entry_print(struct seq_file *m,
if (flags & HIST_FIELD_FL_VAR || flags & HIST_FIELD_FL_EXPR)
continue;

- seq_puts(m, " ");
+ seq_putc(m, ' ');
hist_trigger_print_val(m, i, field_name, flags, stats, elt);
}

print_actions(m, hist_data, elt);

- seq_puts(m, "\n");
+ seq_putc(m, '\n');
}

static int print_entries(struct seq_file *m,
@@ -5971,7 +5971,7 @@ static int event_hist_trigger_print(struct seq_file *m,
field = hist_data->fields[i];

if (i > hist_data->n_vals)
- seq_puts(m, ",");
+ seq_putc(m, ',');

if (field->flags & HIST_FIELD_FL_STACKTRACE) {
if (field->field)
@@ -5997,7 +5997,7 @@ static int event_hist_trigger_print(struct seq_file *m,
seq_puts(m, "hitcount");
} else {
if (show_val)
- seq_puts(m, ",");
+ seq_putc(m, ',');
hist_field_print(m, field);
}
show_val = true;
@@ -6006,14 +6006,14 @@ static int event_hist_trigger_print(struct seq_file *m,
if (have_var) {
unsigned int n = 0;

- seq_puts(m, ":");
+ seq_putc(m, ':');

for_each_hist_val_field(i, hist_data) {
field = hist_data->fields[i];

if (field->flags & HIST_FIELD_FL_VAR) {
if (n++)
- seq_puts(m, ",");
+ seq_putc(m, ',');
hist_field_print(m, field);
}
}
@@ -6035,7 +6035,7 @@ static int event_hist_trigger_print(struct seq_file *m,
return -EINVAL;

if (i > 0)
- seq_puts(m, ",");
+ seq_putc(m, ',');

if (idx == HITCOUNT_IDX)
seq_puts(m, "hitcount");
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index 70d428c394b6..762f8b4667ca 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -1823,7 +1823,7 @@ static int user_event_show(struct seq_file *m, struct dyn_event *ev)

list_for_each_entry_reverse(field, head, link) {
if (depth == 0)
- seq_puts(m, " ");
+ seq_putc(m, ' ');
else
seq_puts(m, "; ");

@@ -1835,7 +1835,7 @@ static int user_event_show(struct seq_file *m, struct dyn_event *ev)
depth++;
}

- seq_puts(m, "\n");
+ seq_putc(m, '\n');

return 0;
}
@@ -2733,13 +2733,13 @@ static int user_seq_show(struct seq_file *m, void *p)
busy++;
}

- seq_puts(m, "\n");
+ seq_putc(m, '\n');
active++;
}

mutex_unlock(&group->reg_mutex);

- seq_puts(m, "\n");
+ seq_putc(m, '\n');
seq_printf(m, "Active: %d\n", active);
seq_printf(m, "Busy: %d\n", busy);

diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index b791524a6536..874a81cf9bb7 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -636,14 +636,14 @@ static int s_mode_show(struct seq_file *s, void *v)
seq_printf(s, "%s", thread_mode_str[mode]);

if (mode < MODE_MAX - 1) /* if mode is any but last */
- seq_puts(s, " ");
+ seq_putc(s, ' ');

return 0;
}

static void s_mode_stop(struct seq_file *s, void *v)
{
- seq_puts(s, "\n");
+ seq_putc(s, '\n');
mutex_unlock(&hwlat_data.lock);
}

--
2.39.2


2024-03-26 19:13:31

by Maxim Moskalets

[permalink] [raw]
Subject: [PATCH 4/8] module: replace seq_puts by seq_putc

Using seq_putc for single characters is faster and more appropriate
than seq_puts, since only one character is passed and there is no need
to use a more powerful and less fast function.

Signed-off-by: Maxim Moskalets <[email protected]>
---
kernel/module/procfs.c | 4 ++--
kernel/module/tracking.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/module/procfs.c b/kernel/module/procfs.c
index 0a4841e88adb..dc91d3dba8f3 100644
--- a/kernel/module/procfs.c
+++ b/kernel/module/procfs.c
@@ -35,7 +35,7 @@ static inline void print_unload_info(struct seq_file *m, struct module *mod)
}

if (!printed_something)
- seq_puts(m, "-");
+ seq_putc(m, '-');
}
#else /* !CONFIG_MODULE_UNLOAD */
static inline void print_unload_info(struct seq_file *m, struct module *mod)
@@ -99,7 +99,7 @@ static int m_show(struct seq_file *m, void *p)
if (mod->taints)
seq_printf(m, " %s", module_flags(mod, buf, true));

- seq_puts(m, "\n");
+ seq_putc(m, '\n');
return 0;
}

diff --git a/kernel/module/tracking.c b/kernel/module/tracking.c
index 16742d1c630c..dcc4dc4c7501 100644
--- a/kernel/module/tracking.c
+++ b/kernel/module/tracking.c
@@ -95,7 +95,7 @@ static int unloaded_tainted_modules_seq_show(struct seq_file *m, void *p)
buf[l++] = '\0';

seq_printf(m, "%s (%s) %llu", mod_taint->name, buf, mod_taint->count);
- seq_puts(m, "\n");
+ seq_putc(m, '\n');

return 0;
}
--
2.39.2


2024-04-02 00:58:02

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH 0/8] kernel: replace seq_puts by seq_putc

On Tue, Mar 26, 2024 at 09:45:14PM +0300, Maxim Moskalets wrote:
> Using seq_putc for single characters is faster and more appropriate
> than seq_puts, since only one character is passed and there is no need
> to use a more powerful and less fast function.

Could we simply do this:

static inline void seq_puts(struct seq_file *m, const char *s)
{
if (__builtin_constant_p(*s) && s[0] && !s[1])
seq_putc(m, s[0]);
else
__seq_puts(m, s);
}

IIRC, __builtin_constant_p(*s) is true when s is a string literal.
Works for recent gcc and clang...