Thread (27 messages) 27 messages, 7 authors, 3d ago

Re: [PATCH 09/11] treewide: Convert custom kernel_param_ops .get callbacks to seq_buf via cocci

From: SeongJae Park <sj@kernel.org>
Date: 2026-05-23 00:45:54
Also in: damon, dmaengine, dri-devel, intel-gfx, kvm, linux-acpi, linux-arch, linux-fsdevel, linux-hardening, linux-media, linux-mm, linux-modules, linux-pci, linux-pm, linux-rdma, linux-scsi, linux-security-module, linux-serial, linux-usb, lkml, netdev, qemu-devel, virtualization

+ damon@lists.linux.dev

On Thu, 21 May 2026 06:33:22 -0700 Kees Cook [off-list ref] wrote:
Using the following Coccinelle script, convert struct kernel_param_ops
.get callbacks from "char *" to "struct seq_buf *" when the only write
to the buffer is via a final call of scnprintf(), snprintf(), sprintf(),
or sysfs_emit().

Since seq_buf_printf() will return -1 on overflow, and struct
kernel_param_ops .get callbacks are expected to truncate without error,
we must ignore the return value from seq_buf_print() and always return 0
(as the length is calculated in the common dispatcher code).

@@
identifier FN, BUF, KP;
expression FMT;
expression list ARGS;
@@
 int FN(
-               char *BUF
+               struct seq_buf *BUF
                , const struct kernel_param *KP)
 {
        ... when any
(
-       return scnprintf(BUF, PAGE_SIZE, FMT, ARGS);
|
-       return snprintf(BUF, PAGE_SIZE, FMT, ARGS);
|
-       return sprintf(BUF, FMT, ARGS);
|
-       return sysfs_emit(BUF, FMT, ARGS);
)
+       seq_buf_printf(BUF, FMT, ARGS);
+       return 0;
 }

No struct kernel_param_ops initializations need changing since
DEFINE_KERNEL_PARAM_OPS already routes the pointer to .get or .get_str
via _Generic based on the function signature, so converted callbacks
are automatically moved from the .get_str to the .get callback.

Signed-off-by: Kees Cook <kees@kernel.org>
[...]
 mm/damon/lru_sort.c                           | 14 +++---
 mm/damon/reclaim.c                            | 14 +++---
 mm/damon/stat.c                               | 10 ++--
For the above DAMON changes,

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help