Skip to content

printk: add macros to simplify handling struct va_format

Andrzej Hajda linux-mm lkml 2 versions – In review

Get series with b4
b4 am [email protected] change-id 20251126-va_format_call-41053ef60fd7

Versions newest first

  1. v2 Latest5 patches 4 repliesIn review
  2. v13 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- added two patches simplifying handling of variadic args in drivers/core and mm in slightly less obvious cases, this way both mm and drivers/core do not use anymore hand rolled variadic -> va_format conversions.
- Link to v1: https://lore.kernel.org/r/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5printk: add macros to simplify handling struct va_formatinclude/linux/printk.h+30 -00 replies
2/5drivers/core: use va_format_call helperdrivers/base/core.c+6 -260 replies
3/5drivers/core: simplify variadic args handlingdrivers/base/core.c+7 -434 replies
4/5mm: use va_format_call helpermm/page_alloc.c mm/slub.c+5 -190 replies
5/5mm: simplify variadic args handlingmm/slub.c+4 -190 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/5] printk: add macros to simplify handling struct va_format

This patchset contains patch abstracting out most common bits of va_format uses into small macro. The macro works as a forwarder of variadic args to va_format call.
Rough estimates based on dirty cocci script suggests about 180-230 users could be converted, allowing to remove about 1100-1300 lines of code. Of course, I do not plan to do it in mass. I just provide few patches to show the usage and the potential.

Provided helper deals with variadic args to va_format conversion/forwarding. Similar solution could be proposed also for variadic args to va_list conversion. Common code:

    va_list args;
    va_start(args, fmt);
    ret = func(..., fmt, args);
    va_end(args);
    return ret;
Could be replaced with:
    ret = va_list_call(fmt, func, ..., fmt);
This is less rewarding (less lines to remove) but still looks promising. Also
separate helper should be created for functions without return value,
unless somebody knows trick how to do it in one macro:
    va_list_void_call(fmt, func, ..., fmt);

Any comments?

---
Changes in v2:
- added two patches simplifying handling of variadic args in drivers/core and mm in slightly less obvious cases, this way both mm and drivers/core do not use anymore hand rolled variadic -> va_format conversions.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrzej Hajda (5):
printk: add macros to simplify handling struct va_format drivers/core: use va_format_call helper drivers/core: simplify variadic args handling
mm: use va_format_call helper
mm: simplify variadic args handling

 drivers/base/core.c    | 82 ++++++++------------------------------------------
 include/linux/printk.h | 30 ++++++++++++++++++
 mm/page_alloc.c        | 14 +++------
 mm/slub.c              | 33 +++-----------------
 4 files changed, 52 insertions(+), 107 deletions(-)

---
base-commit: 37a098cc87aafdf4de147851cbf350bb66c51b45
change-id: 20251126-va_format_call-41053ef60fd7

Best regards,

Signature · 1 line
Andrzej Hajda <[email protected]>