Skip to content

file: simplify and harden cleanup handling

Christian Brauner bpf dri-devel io-uring linux-arm-msm linux-fsdevel linux-gpio linux-media linux-mm linux-xfs linuxppc-dev lkml netdev 1 version In review

Get series with b4
b4 am [email protected] change-id 20260917-work-file-fd_prepare-ea5966d68a95

Versions newest first

  1. v1 Latest4 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4file: simplify FD_PREPARE()include/linux/file.h+41 -580 replies
2/4file: declare the FD_PREPARE() variable with __cleanup() directlyinclude/linux/file.h+3 -61 reply
3/4cleanup: remove CLASS_INIT()include/linux/cleanup.h+0 -70 replies
4/4file: make struct fd_prepare const and kill its err fieldarch/powerpc/platforms/cell/spufs/inode.c drivers/gpio/gpiolib-cdev.c drivers/gpu/drm/msm/msm_perfcntr.c +16 more+95 -1071 reply

Reviews trailers per patch

None of the 4 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchJan Kara
SeriesR-b
1/4
2/4
3/4
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/4] file: simplify and harden cleanup handling

The cleanup guards rely on unnecessary infrastructure and make the code more complicated to follow than it needs to be. Clean it up. Also shrink the struct a bit and get rid of the unnecessary error variable. We can just make this more ergonomic by using fdf->fd directly. Also expose the struct itself as const and hide the actual underlying local variable behind a UNIQUE_ID() named variable so we avoid risking shadow variables and polluting callsites. Code generation wise the outcome is exactly the same but simpler.

---
Christian Brauner (4):
file: simplify FD_PREPARE()
file: declare the FD_PREPARE() variable with __cleanup() directly
cleanup: remove CLASS_INIT()
file: make struct fd_prepare const and kill its err field

 arch/powerpc/platforms/cell/spufs/inode.c |  12 +--
 drivers/gpio/gpiolib-cdev.c               |  18 ++---
 drivers/gpu/drm/msm/msm_perfcntr.c        |   4 +-
 drivers/media/mc/mc-request.c             |   8 +-
 drivers/misc/ntsync.c                     |   6 +-
 fs/eventfd.c                              |   4 +-
 fs/eventpoll.c                            |   6 +-
 fs/file.c                                 |   8 +-
 fs/namespace.c                            |  12 +--
 fs/nsfs.c                                 |   4 +-
 fs/xfs/xfs_handle.c                       |   6 +-
 include/linux/cleanup.h                   |   7 --
 include/linux/file.h                      | 130 +++++++++++-------------------
 io_uring/mock_file.c                      |   8 +-
 kernel/bpf/bpf_iter.c                     |   6 +-
 kernel/bpf/token.c                        |   6 +-
 mm/userfaultfd.c                          |   6 +-
 net/core/scm.c                            |   8 +-
 net/handshake/netlink.c                   |   8 +-
 net/kcm/kcmsock.c                         |   6 +-
 20 files changed, 117 insertions(+), 156 deletions(-)

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260917-work-file-fd_prepare-ea5966d68a95