Thread (7 messages) 7 messages, 2 authors, 13d ago

Re: [PATCH 4/4] file: make struct fd_prepare const and kill its err field

From: David Laight <hidden>
Date: 2026-09-17 12:29:47
Also in: bpf, dri-devel, io-uring, linux-arm-msm, linux-fsdevel, linux-gpio, linux-media, linux-mm, linux-xfs, linuxppc-dev, lkml

On Thu, 17 Sep 2026 11:09:45 +0200
Christian Brauner [off-list ref] wrote:
FD_PREPARE() releases the fd as soon as the file expression fails. The
fd either holds the descriptor or the error. The separate field is
redundant. Make fd and file plain members and struct fd_prepare simpler.

Callers of FD_PREPARE() get a const pointer to the guard. Simplify all
users as they can now easily access the trivial struct.
...
quoted hunk ↗ jump to hunk
@@ -191,35 +175,39 @@ static __always_inline struct fd_prepare __fd_prepare(int fd, struct file *file)
  * was allocated. If fd_publish() was called the fd and file are
  * published and cleanup becomes a nop.
  *
- * @_fdf: name of struct fd_prepare variable to define
+ * @_fdf: name of the const struct fd_prepare pointer to define
  * @_fd_flags: flags for get_unused_fd_flags()
  * @_file_owned: struct file to take ownership of (can be expression)
  */
-#define FD_PREPARE(_fdf, _fd_flags, _file_owned)			\
-	struct fd_prepare _fdf __cleanup(__fd_prepare_cleanup) = ({	\
+#define __FD_PREPARE(_guard, _fdf, _fd_flags, _file_owned)		\
+	struct fd_prepare _guard __cleanup(__fd_prepare_cleanup) = ({	\
 		int __fd = get_unused_fd_flags(_fd_flags);		\
 		__fd_prepare(__fd, __fd < 0 ? NULL : (_file_owned));	\
-	})
+	});								\
+	const struct fd_prepare *const _fdf = &_guard
Since the struct is only written by its initialiser, can't it just
be 'const' ?

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