Re: [PATCH 09/11] treewide: Convert custom kernel_param_ops .get callbacks to seq_buf via cocci
SeongJae Park <[email protected]> Fri, 22 May 2026 17:45:43 -0700
| Newsgroups | gmane.linux.kernel.modules,gmane.comp.emulators.kvm.devel,gmane.linux.kernel.mm,gmane.comp.security.apparmor,gmane.linux.kernel.lsm,gmane.linux.uml.devel,gmane.linux.acpi.devel,gmane.linux.kernel.openipmi,gmane.comp.emulators.qemu,gmane.comp.freedesktop.xorg.drivers.intel,gmane.comp.video.dri.devel,gmane.linux.drivers.rdma,gmane.linux.drivers.video-input-infrastructure,gmane.linux.kernel.pci,gmane.linux.scsi,gmane.linux.power-management.general,gmane.linux.ports.ppc64.devel,gmane.linux.serial,gmane.linux.usb.general,gmane.linux.kernel,gmane.linux.kernel.cross-arch,gmane.linux.network,gmane.linux.file-systems |
|---|---|
| Message-ID | <[email protected]> |
+ damon-cunTk1MwBs/[email protected] On Thu, 21 May 2026 06:33:22 -0700 Kees Cook <[email protected]> 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 <[email protected]> [...] > 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 <[email protected]> Thanks, SJ [...]