[PATCH v2 0/1] rust: seq_file: add puts, putc, write, and hex_dump methods

Christian Benton
2026-04-08T21:56:12Z

This is v2 of the seq_file methods patch, addressing feedback from
Alice Ryhl and build issues reported by the kernel test robot.

On use-case:

Looking at the existing Rust Binder code in drivers/android/binder/,
there are several places where seq_print! is used purely to output
static strings, for example in freeze.rs and node.rs:

seq_print!(m, "{}has frozen binder\n", prefix);
seq_print!(m, "{}has dead binder\n", prefix);
seq_print!(m, "{}has cleared dead binder\n", prefix);
seq_print!(m, "{}has cleared death notification\n", prefix);

The static string portions of these calls are candidates for puts(),
which avoids the format string parsing overhead of seq_printf entirely.

write() and hex_dump() do not have obvious in-tree users today. The
motivation for including them is API completeness — any Rust driver
needing these operations currently must call C bindings directly,
bypassing the safe abstraction. An out-of-tree user that motivated
the full set is the amdtelem driver, which exposes GPU telemetry
through a misc character device and uses hex_dump() for register
data output.

If the preference is to merge only puts() and putc() now and add
write() and hex_dump() when concrete in-tree users exist, I am happy
to split the patch accordingly.

Changes in v2:
- Reformat use statement to satisfy rustfmt line length requirement
- Rename as_c_int() to to_c_int() to satisfy clippy wrong_self_convention
- Replace rowsize/groupsize as-casts with ffi::c_int::from() to satisfy
clippy cast_lossless lint

Christian Benton (1):
rust: seq_file: add puts, putc, write, and hex_dump methods

rust/kernel/seq_file.rs | 87 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 86 insertions(+), 1 deletion(-)

--
2.53.0