af_unix: Clean up headers.
Subsystems (4)
cover af_unix: Clean up headers.
AF_UNIX files include many unnecessary headers (netdevice.h and rtnetlink.h, etc), and this series cleans them up.
Note that there are still some headers included indirectly and modifying them triggers rebuild, which seems mostly inevitable. [0]
$ python3 include_graph.py net/unix/garbage.c linux/rtnetlink.h linux/netdevice.h ... include/net/af_unix.h | include/linux/net.h | | include/linux/once.h | | include/linux/sockptr.h | | include/uapi/linux/net.h | include/net/sock.h | | include/linux/netdevice.h <--- ... | | include/net/dst.h | | | include/linux/rtnetlink.h <---
[0]: https://gist.github.com/q2ven/9c5897f11a493145829029c0bfb364d0
Kuniyuki Iwashima (4):
af_unix: Sort headers.
af_unix: Move internal definitions to net/unix/.
af_unix: Explicitly include headers for non-pointer struct fields.
af_unix: Clean up #include under net/unix/.
include/net/af_unix.h | 84 ++++---------------------------------- net/unix/af_unix.c | 55 +++++++++++-------------- net/unix/af_unix.h | 75 ++++++++++++++++++++++++++++++++++ net/unix/diag.c | 18 ++++---- net/unix/garbage.c | 33 +++++++++------ net/unix/sysctl_net_unix.c | 6 ++- net/unix/unix_bpf.c | 5 ++- 7 files changed, 143 insertions(+), 133 deletions(-) create mode 100644 net/unix/af_unix.h
Signature · 1 line
2.48.1
PATCH 1/4 af_unix: Sort headers.
This is a prep patch to make the following changes cleaner.
No functional change intended.
--- include/net/af_unix.h | 4 +-- net/unix/af_unix.c | 62 +++++++++++++++++++------------------- net/unix/diag.c | 15 ++++----- net/unix/garbage.c | 17 +++++------ net/unix/sysctl_net_unix.c | 1 - net/unix/unix_bpf.c | 4 +-- 6 files changed, 51 insertions(+), 52 deletions(-)
include/net/af_unix.h +2 -2
@@ -2,10 +2,10 @@#ifndef __LINUX_NET_AFUNIX_H#define __LINUX_NET_AFUNIX_H -#include <linux/socket.h> -#include <linux/un.h> #include <linux/mutex.h> #include <linux/refcount.h> +#include <linux/socket.h> +#include <linux/un.h> #include <net/sock.h> #if IS_ENABLED (CONFIG_UNIX )
net/unix/af_unix.c +31 -31
77 lines not on this page · raw message
net/unix/diag.c +8 -7
@@ -1,15 +1,16 @@// SPDX-License-Identifier: GPL-2.0-only -#include <linux/types.h> -#include <linux/spinlock.h> -#include <linux/sock_diag.h> -#include <linux/unix_diag.h> -#include <linux/skbuff.h> +#include <linux/module.h> +#include <linux/skbuff.h> +#include <linux/sock_diag.h> +#include <linux/spinlock.h> +#include <linux/types.h> #include <linux/uidgid.h> -#include <net/netlink.h> +#include <linux/unix_diag.h> #include <net/af_unix.h> -#include <net/tcp_states.h> +#include <net/netlink.h> #include <net/sock.h> +#include <net/tcp_states.h> static int sk_diag_dump_name (struct sock *sk,struct sk_buff *nlskb) {
net/unix/garbage.c +8 -9
@@ -63,22 +63,21 @@* wrt receive and holding up unrelated socket operations. */ +#include <linux/file.h> +#include <linux/fs.h> #include <linux/kernel.h> -#include <linux/string.h> -#include <linux/socket.h> -#include <linux/un.h> +#include <linux/mutex.h> #include <linux/net.h> -#include <linux/fs.h> -#include <linux/skbuff.h> #include <linux/netdevice.h> -#include <linux/file.h> #include <linux/proc_fs.h> -#include <linux/mutex.h> +#include <linux/skbuff.h> +#include <linux/socket.h> +#include <linux/string.h> +#include <linux/un.h> #include <linux/wait.h> - -#include <net/sock.h> #include <net/af_unix.h> #include <net/scm.h> +#include <net/sock.h> #include <net/tcp_states.h> struct unix_sock *unix_get_socket (struct file *filp)
net/unix/sysctl_net_unix.c +0 -1
@@ -8,7 +8,6 @@#include <linux/mm.h> #include <linux/slab.h> #include <linux/sysctl.h> -#include <net/af_unix.h> static struct ctl_table unix_table[] = {
net/unix/unix_bpf.c +2 -2
@@ -1,10 +1,10 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2021 Cong Wang <[email protected]> */ -#include <linux/skmsg.h> #include <linux/bpf.h> -#include <net/sock.h> +#include <linux/skmsg.h> #include <net/af_unix.h> +#include <net/sock.h> #define unix_sk_has_data (__sk, __psock) \ ({ !skb_queue_empty(&__sk->sk_receive_queue) || \
Signature · 1 line
2.48.1
Re: [PATCH v1 net-next 1/4] af_unix: Sort headers.
Quoted 13 lines · Kuniyuki Iwashima
This is a prep patch to make the following changes cleaner.
No functional change intended.
Signed-off-by Kuniyuki Iwashima <[email protected]>--- include/net/af_unix.h | 4 +-- net/unix/af_unix.c | 62 +++++++++++++++++++------------------- net/unix/diag.c | 15 ++++----- net/unix/garbage.c | 17 +++++------ net/unix/sysctl_net_unix.c | 1 - net/unix/unix_bpf.c | 4 +-- 6 files changed, 51 insertions(+), 52 deletions(-)
[...]
Quoted 4 lines
net/unix/af_unix.c +0
-0
[...]
Quoted 4 lines
net/unix/af_unix.c +3
-0+#include <linux/in.h> #include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h>
net/unix/af_unix.c line 100
Quoted 10 lines
net/unix/af_unix.c +6
-2+#include <linux/mount.h> +#include <linux/namei.h> +#include <linux/net.h> +#include <linux/netdevice.h> #include <linux/poll.h> +#include <linux/proc_fs.h> #include <linux/rtnetlink.h> -#include <linux/mount.h> -#include <net/checksum.h> +#include <linux/sched/signal.h>
Not sure what the sorting rules are, but I was wondering if maybe "linux/sched/*.h" should come after linux/*.h and not sorted within linux/s*.h ?
Quoted 7 lines
#include <
linux/security.h>net/unix/af_unix.c +6
-0+#include <linux/seq_file.h> +#include <linux/signal.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/socket.h> +#include <linux/sockios.h>
Re: [PATCH v1 net-next 1/4] af_unix: Sort headers.
From: Joe Damato <[email protected]>
Date: Tue, 18 Mar 2025 16:07:47 -0700
Quoted 10 lines
Quoted 10 lines
net/unix/af_unix.c +8
-0+#include <linux/in.h> #include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mount.h> +#include <linux/namei.h> +#include <linux/net.h> +#include <linux/netdevice.h> #include <linux/poll.h> +#include <linux/proc_fs.h>
Quoted 8 lines
net/unix/af_unix.c line 100
Quoted 4 lines
#include <
linux/rtnetlink.h>net/unix/af_unix.c +1
-2-#include <linux/mount.h> -#include <net/checksum.h> +#include <linux/sched/signal.h> Not sure what the sorting rules are, but I was wondering if maybe "linux/sched/*.h" should come after linux/*.h and not sorted within
linux/s*.h?
It's simply sorted in the alphabetial order.
Actually I haven't cared about the / level, so I grepped the linux/sched/signal.h users and it looks like most didn't care.
grep -rnI --include=*.c --include=*.h "linux/sched/signal.h" -C 3
Thanks!
Joe Damato
Reviewed-byRe: [PATCH v1 net-next 1/4] af_unix: Sort headers.
Quoted 21 lines · Kuniyuki Iwashima
From: Joe Damato <[email protected]>
Date: Tue, 18 Mar 2025 16:07:47 -0700Quoted 10 lines
Quoted 10 lines
net/unix/af_unix.c +8
-0+#include <linux/in.h> #include <linux/init.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mount.h> +#include <linux/namei.h> +#include <linux/net.h> +#include <linux/netdevice.h> #include <linux/poll.h> +#include <linux/proc_fs.h> Quoted 8 lines
net/unix/af_unix.c line 100
Quoted 4 lines
#include <
linux/rtnetlink.h>net/unix/af_unix.c +1
-2-#include <linux/mount.h> -#include <net/checksum.h> +#include <linux/sched/signal.h> Not sure what the sorting rules are, but I was wondering if maybe "linux/sched/*.h" should come after linux/*.h and not sorted within
linux/s*.h?
Quoted 1 line
It's simply sorted in the alphabetial order.
Yea, I understand that - just wasn't sure if subdirectories should be sorted separately.
Quoted 4 lines
Actually I haven't cared about the / level, so I grepped the
linux/sched/signal.husers and it looks like most didn't care.grep -rnI --include=*.c --include=*.h "linux/sched/signal.h" -C 3
OK, fair enough.
PATCH 2/4 af_unix: Move internal definitions to net/unix/.
In reply to Kuniyuki Iwashimanet/af_unix.h is included by core and some LSMs, but most definitions need not be.
Let's move struct unix_{vertex,edge} to net/unix/garbage.c and other definitions to net/unix/af_unix.h.
--- include/net/af_unix.h | 76 +------------------------------------- net/unix/af_unix.c | 2 + net/unix/af_unix.h | 75 +++++++++++++++++++++++++++++++++++++ net/unix/diag.c | 2 + net/unix/garbage.c | 18 +++++++++ net/unix/sysctl_net_unix.c | 2 + net/unix/unix_bpf.c | 2 + 7 files changed, 102 insertions(+), 75 deletions(-) create mode 100644 net/unix/af_unix.h
include/net/af_unix.h +1 -75
@@ -17,61 +17,17 @@ static inline struct unix_sock *unix_get_socket(struct file *filp) }#endif -extern unsigned int unix_tot_inflight; -void unix_add_edges (struct scm_fp_list *fpl,struct unix_sock *receiver); -void unix_del_edges (struct scm_fp_list *fpl); -void unix_update_edges (struct unix_sock *receiver); -int unix_prepare_fpl (struct scm_fp_list *fpl); -void unix_destroy_fpl (struct scm_fp_list *fpl); -void unix_gc (void ); -void wait_for_unix_gc (struct scm_fp_list *fpl); - -struct unix_vertex { -struct list_head edges; -struct list_head entry; -struct list_head scc_entry; -unsigned long out_degree; -unsigned long index; -unsigned long scc_index; -}; - -struct unix_edge { -struct unix_sock *predecessor; -struct unix_sock *successor; -struct list_head vertex_entry; -struct list_head stack_entry; -}; - -struct sock *unix_peer_get (struct sock *sk); - -#define UNIX_HASH_MOD (256 - 1) -#define UNIX_HASH_SIZE (256 * 2) -#define UNIX_HASH_BITS 8 -struct unix_address {refcount_t refcnt;int len;struct sockaddr_un name[]; }; -struct unix_skb_parms { -struct pid *pid;/* Skb credentials */ -kuid_t uid; -kgid_t gid; -struct scm_fp_list *fp;/* Passed files */ -#ifdef CONFIG_SECURITY_NETWORK -u32 secid;/* Security ID */ -#endif -u32 consumed; -} __randomize_layout; -struct scm_stat {atomic_t nr_fds;unsigned long nr_unix_fds; }; -#define UNIXCB (skb) (*(struct unix_skb_parms *)&((skb)->cb)) -/* The AF_UNIX socket */ struct unix_sock {/* WARNING: sk has to be the first member */
@@ -84,6 +40,7 @@ struct unix_sock {struct unix_vertex *vertex;spinlock_t lock;struct socket_wq peer_wq; +#define peer_wait peer_wq.waitwait_queue_entry_t peer_wake;struct scm_stat scm_stat;#if IS_ENABLED (CONFIG_AF_UNIX_OOB )
@@ -94,35 +51,4 @@ struct unix_sock {#define unix_sk (ptr) container_of_const(ptr, struct unix_sock, sk)#define unix_peer (sk) (unix_sk(sk)->peer) -#define unix_state_lock (s) spin_lock(&unix_sk(s)->lock) -#define unix_state_unlock (s) spin_unlock(&unix_sk(s)->lock) - -#define peer_wait peer_wq.wait - -long unix_inq_len (struct sock *sk); -long unix_outq_len (struct sock *sk); - -int __unix_dgram_recvmsg (struct sock *sk,struct msghdr *msg,size_t size, -int flags); -int __unix_stream_recvmsg (struct sock *sk,struct msghdr *msg,size_t size, -int flags); -#ifdef CONFIG_SYSCTL -int unix_sysctl_register (struct net *net); -void unix_sysctl_unregister (struct net *net); -#else -static inline int unix_sysctl_register (struct net *net) {return 0 ; } -static inline void unix_sysctl_unregister (struct net *net) {} -#endif - -#ifdef CONFIG_BPF_SYSCALL -extern struct proto unix_dgram_proto; -extern struct proto unix_stream_proto; - -int unix_dgram_bpf_update_proto (struct sock *sk,struct sk_psock *psock,bool restore); -int unix_stream_bpf_update_proto (struct sock *sk,struct sk_psock *psock,bool restore); -void __init unix_bpf_build_proto (void ); -#else -static inline void __init unix_bpf_build_proto (void ) -{} -#endif #endif
net/unix/af_unix.c +2 -0
@@ -118,6 +118,8 @@#include <net/sock.h> #include <net/tcp_states.h> +#include "af_unix.h" +static atomic_long_t unix_nr_socks;static struct hlist_head bsd_socket_buckets[UNIX_HASH_SIZE /2 ];static spinlock_t bsd_socket_locks[UNIX_HASH_SIZE /2 ];
net/unix/af_unix.h new file +75 -0
75 lines not on this page · raw message
net/unix/diag.c +2 -0
@@ -12,6 +12,8 @@#include <net/sock.h> #include <net/tcp_states.h> +#include "af_unix.h" +static int sk_diag_dump_name (struct sock *sk,struct sk_buff *nlskb) {/* might or might not have a hash table lock */
net/unix/garbage.c +18 -0
@@ -80,6 +80,24 @@#include <net/sock.h> #include <net/tcp_states.h> +#include "af_unix.h" + +struct unix_vertex { +struct list_head edges; +struct list_head entry; +struct list_head scc_entry; +unsigned long out_degree; +unsigned long index; +unsigned long scc_index; +}; + +struct unix_edge { +struct unix_sock *predecessor; +struct unix_sock *successor; +struct list_head vertex_entry; +struct list_head stack_entry; +}; +struct unix_sock *unix_get_socket (struct file *filp) {struct inode *inode =file_inode (filp);
net/unix/sysctl_net_unix.c +2 -0
@@ -10,6 +10,8 @@#include <linux/sysctl.h> #include <net/af_unix.h> +#include "af_unix.h" +static struct ctl_table unix_table[] = { { .procname ="max_dgram_qlen" ,
net/unix/unix_bpf.c +2 -0
@@ -6,6 +6,8 @@#include <net/af_unix.h> #include <net/sock.h> +#include "af_unix.h" +#define unix_sk_has_data (__sk, __psock) \ ({ !skb_queue_empty(&__sk->sk_receive_queue) || \ !skb_queue_empty(&__psock->ingress_skb) || \
Signature · 1 line
2.48.1
Re: [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
Quoted 7 lines · Kuniyuki Iwashima
net/af_unix.his included by core and some LSMs, but most definitions need not be.Let's move struct unix_{vertex,edge} to
net/unix/garbage.cand other definitions tonet/unix/af_unix.h.Signed-off-by Kuniyuki Iwashima <[email protected]>
Quoted 10 lines
--- include/net/af_unix.h | 76 +------------------------------------- net/unix/af_unix.c | 2 + net/unix/af_unix.h | 75 +++++++++++++++++++++++++++++++++++++ net/unix/diag.c | 2 + net/unix/garbage.c | 18 +++++++++ net/unix/sysctl_net_unix.c | 2 + net/unix/unix_bpf.c | 2 + 7 files changed, 102 insertions(+), 75 deletions(-) create mode 100644 net/unix/af_unix.h
Nice clean up.
Re: [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
In reply to Kuniyuki IwashimaQuoted 7 lines · Kuniyuki Iwashima
net/af_unix.his included by core and some LSMs, but most definitions need not be.Let's move struct unix_{vertex,edge} to
net/unix/garbage.cand other definitions tonet/unix/af_unix.h.Signed-off-by Kuniyuki Iwashima <[email protected]>
One trade-off with these kinds of refactors is that it adds an indirection in git history: a git blame on a line no longer points to the relevant commit.
Whether the trade-off is worth it is subjective, your call. Just making it explicit.
I still manually check out pre UDP/UDPLite split often to go back in udp history, for instance.
Re: [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
From: Willem de Bruijn <[email protected]>
Date: Wed, 19 Mar 2025 13:49:31 -0400
Quoted 4 lines
Quoted 3 lines · Kuniyuki Iwashima
net/af_unix.his included by core and some LSMs, but most definitions need not be.
Quoted 8 lines
Quoted 4 lines
Let's move struct unix_{vertex,edge} to
net/unix/garbage.cand other definitions tonet/unix/af_unix.h.Signed-off-by Kuniyuki Iwashima <[email protected]>One trade-off with these kinds of refactors is that it adds an indirection in git history: a git blame on a line no longer points to the relevant commit.
Right, and git has a useful option for that.
Quoted 6 lines
Whether the trade-off is worth it is subjective, your call. Just making it explicit.
I still manually check out pre UDP/UDPLite split often to go back in udp history, for instance.
I often use -C5 (track 5 times for line/file moves) and hope this helps you :)
$ git blame -C1 net/unix/af_unix.h Blaming lines: 100% (75/75), done. b24413180f5600 include/net/af_unix.h (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) /* SPDX-License-Identifier: GPL-2.0 */ d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 2) #ifndef __AF_UNIX_H d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 3) #define __AF_UNIX_H d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 4) cae9910e73446c net/unix/diag.c (Felipe Gasper 2019-05-20 19:43:51 -0500 5) #include <linux/uidgid.h> ^1da177e4c3f41 include/net/af_unix.h (Linus Torvalds 2005-04-16 15:20:36 -0700 6)
Thanks!
Re: [PATCH v1 net-next 2/4] af_unix: Move internal definitions to net/unix/.
Quoted 28 lines · Kuniyuki Iwashima
From: Willem de Bruijn <[email protected]>
Date: Wed, 19 Mar 2025 13:49:31 -0400Quoted 4 lines
Quoted 3 lines · Kuniyuki Iwashima
net/af_unix.his included by core and some LSMs, but most definitions need not be.Quoted 8 lines
Quoted 4 lines
Let's move struct unix_{vertex,edge} to
net/unix/garbage.cand other definitions tonet/unix/af_unix.h.Signed-off-by Kuniyuki Iwashima <[email protected]>One trade-off with these kinds of refactors is that it adds an indirection in git history: a git blame on a line no longer points to the relevant commit.
Right, and git has a useful option for that.
Quoted 6 lines
Whether the trade-off is worth it is subjective, your call. Just making it explicit.
I still manually check out pre UDP/UDPLite split often to go back in udp history, for instance.
I often use -C5 (track 5 times for line/file moves) and hope this helps you :)
Quoted 8 lines
$ git blame -C1 net/unix/af_unix.h Blaming lines: 100% (75/75), done. b24413180f5600 include/net/af_unix.h (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) /* SPDX-License-Identifier: GPL-2.0 */ d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 2) #ifndef __AF_UNIX_H d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 3) #define __AF_UNIX_H d48846033064e3 net/unix/af_unix.h (Kuniyuki Iwashima 2025-03-15 00:54:46 +0000 4) cae9910e73446c net/unix/diag.c (Felipe Gasper 2019-05-20 19:43:51 -0500 5) #include <linux/uidgid.h> ^1da177e4c3f41 include/net/af_unix.h (Linus Torvalds 2005-04-16 15:20:36 -0700 6)
Thanks! I can't believe I did not know about this. That certainly mitigates the busywork around refactoring a bit.
PATCH 3/4 af_unix: Explicitly include headers for non-pointer struct fields.
In reply to Kuniyuki Iwashimainclude/net/af_unix.h indirectly includes some definitions for structs.
Let's include such headers explicitly.
linux/atomic.h : scm_stat.nr_fds linux/net.h : unix_sock.peer_wq linux/path.h : unix_sock.path
linux/spinlock.h : unix_sock.lock
linux/wait.h : unix_sock.peer_wake
uapi/linux/un.h : unix_address.name[]
linux/socket.h is removed as the structs there are not used directly, and linux/un.h is clarified with uapi as un.h only exists under include/uapi.
While at it, duplicate headers are removed from .c files.
--- include/net/af_unix.h | 8 ++++++-- net/unix/af_unix.c | 3 --- net/unix/diag.c | 3 --- net/unix/garbage.c | 5 ----- net/unix/unix_bpf.c | 1 - 5 files changed, 6 insertions(+), 14 deletions(-)
include/net/af_unix.h +6 -2
@@ -2,11 +2,15 @@#ifndef __LINUX_NET_AFUNIX_H#define __LINUX_NET_AFUNIX_H +#include <linux/atomic.h> #include <linux/mutex.h> +#include <linux/net.h> +#include <linux/path.h> #include <linux/refcount.h> -#include <linux/socket.h> -#include <linux/un.h> +#include <linux/spinlock.h> +#include <linux/wait.h> #include <net/sock.h> +#include <uapi/linux/un.h> #if IS_ENABLED (CONFIG_UNIX )struct unix_sock *unix_get_socket (struct file *filp);
net/unix/af_unix.c +0 -3
@@ -92,7 +92,6 @@#include <linux/module.h> #include <linux/mount.h> #include <linux/namei.h> -#include <linux/net.h> #include <linux/netdevice.h> #include <linux/poll.h> #include <linux/proc_fs.h>
@@ -110,12 +109,10 @@#include <linux/string.h> #include <linux/termios.h> #include <linux/uaccess.h> -#include <linux/un.h> #include <net/af_unix.h> #include <net/checksum.h> #include <net/net_namespace.h> #include <net/scm.h> -#include <net/sock.h> #include <net/tcp_states.h> #include "af_unix.h"
net/unix/diag.c +0 -3
@@ -3,13 +3,10 @@#include <linux/module.h> #include <linux/skbuff.h> #include <linux/sock_diag.h> -#include <linux/spinlock.h> #include <linux/types.h> -#include <linux/uidgid.h> #include <linux/unix_diag.h> #include <net/af_unix.h> #include <net/netlink.h> -#include <net/sock.h> #include <net/tcp_states.h> #include "af_unix.h"
net/unix/garbage.c +0 -5
@@ -66,18 +66,13 @@#include <linux/file.h> #include <linux/fs.h> #include <linux/kernel.h> -#include <linux/mutex.h> -#include <linux/net.h> #include <linux/netdevice.h> #include <linux/proc_fs.h> #include <linux/skbuff.h> #include <linux/socket.h> #include <linux/string.h> -#include <linux/un.h> -#include <linux/wait.h> #include <net/af_unix.h> #include <net/scm.h> -#include <net/sock.h> #include <net/tcp_states.h> #include "af_unix.h"
net/unix/unix_bpf.c +0 -1
@@ -4,7 +4,6 @@#include <linux/bpf.h> #include <linux/skmsg.h> #include <net/af_unix.h> -#include <net/sock.h> #include "af_unix.h"
Signature · 1 line
2.48.1
PATCH 4/4 af_unix: Clean up #include under net/unix/.
In reply to Kuniyuki Iwashimanet/unix/*.c include many unnecessary header files (rtnetlink.h, netdevice.h, etc).
Let's clean them up.
af_unix.c:
+uapi/linux/sockios.h : Only exist under include/uapi
+uapi/linux/termios.h : Only exist under include/uapi
-linux/freezer.h : No longer use freezable_schedule_timeout() -linux/in.h : No ipv4_is_XXX() etc -linux/module.h : No longer support CONFIG_UNIX=m -linux/netdevice.h : No dev used -linux/rtnetlink.h : Not part of rtnetlink API -linux/signal.h : signal_pending() is defined in sched/signal.h -linux/stat.h : No struct stat used -net/checksum.h : CHECKSUM_UNNECESSARY is defined in skbuff.h
diag.c:
+linux/dcache.h : struct dentry in sk_diag_dump_vfs()
+linux/user_namespace.h : struct user_namespace in sk_diag_dump_uid() +uapi/linux/unix_diag.h : Only exist under include/uapi/
garbage.c:
+linux/list.h : struct unix_{vertex,edge}, etc
+linux/workqueue.h : DECLARE_WORK(unix_gc_work, ...)
-linux/file.h : No fget() etc -linux/kernel.h : No cond_resched() etc -linux/netdevice.h : No dev used -linux/proc_fs.h : No procfs provided -linux/string.h : No memcpy(), kmemdup(), etc
sysctl_net_unix.c:
+linux/string.h : kmemdup()
+net/net_namespace.h : struct net, net_eq()
-linux/mm.h : slab.h is enough
--- net/unix/af_unix.c | 12 ++---------- net/unix/diag.c | 4 +++- net/unix/garbage.c | 7 ++----- net/unix/sysctl_net_unix.c | 3 ++- 4 files changed, 9 insertions(+), 17 deletions(-)
net/unix/af_unix.c +2 -10
@@ -84,36 +84,28 @@#include <linux/fcntl.h> #include <linux/file.h> #include <linux/filter.h> -#include <linux/freezer.h> #include <linux/fs.h> -#include <linux/in.h> #include <linux/init.h> #include <linux/kernel.h> -#include <linux/module.h> #include <linux/mount.h> #include <linux/namei.h> -#include <linux/netdevice.h> #include <linux/poll.h> #include <linux/proc_fs.h> -#include <linux/rtnetlink.h> #include <linux/sched/signal.h> #include <linux/security.h> #include <linux/seq_file.h> -#include <linux/signal.h> #include <linux/skbuff.h> #include <linux/slab.h> #include <linux/socket.h> -#include <linux/sockios.h> #include <linux/splice.h> -#include <linux/stat.h> #include <linux/string.h> -#include <linux/termios.h> #include <linux/uaccess.h> #include <net/af_unix.h> -#include <net/checksum.h> #include <net/net_namespace.h> #include <net/scm.h> #include <net/tcp_states.h> +#include <uapi/linux/sockios.h> +#include <uapi/linux/termios.h> #include "af_unix.h"
net/unix/diag.c +3 -1
@@ -1,13 +1,15 @@// SPDX-License-Identifier: GPL-2.0-only +#include <linux/dcache.h> #include <linux/module.h> #include <linux/skbuff.h> #include <linux/sock_diag.h> #include <linux/types.h> -#include <linux/unix_diag.h> +#include <linux/user_namespace.h> #include <net/af_unix.h> #include <net/netlink.h> #include <net/tcp_states.h> +#include <uapi/linux/unix_diag.h> #include "af_unix.h"
net/unix/garbage.c +2 -5
@@ -63,14 +63,11 @@* wrt receive and holding up unrelated socket operations. */ -#include <linux/file.h> #include <linux/fs.h> -#include <linux/kernel.h> -#include <linux/netdevice.h> -#include <linux/proc_fs.h> +#include <linux/list.h> #include <linux/skbuff.h> #include <linux/socket.h> -#include <linux/string.h> +#include <linux/workqueue.h> #include <net/af_unix.h> #include <net/scm.h> #include <net/tcp_states.h>
net/unix/sysctl_net_unix.c +2 -1
@@ -5,10 +5,11 @@* Authors: Mike Shaver. */ -#include <linux/mm.h> #include <linux/slab.h> +#include <linux/string.h> #include <linux/sysctl.h> #include <net/af_unix.h> +#include <net/net_namespace.h> #include "af_unix.h"
Signature · 1 line
2.48.1
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 19 lines · On Mon, 17 Mar 2025 20:48:47 -0700 you wrote:
AF_UNIXfiles include many unnecessary headers (netdevice.handrtnetlink.h, etc), and this series cleans them up.Note that there are still some headers included indirectly and modifying them triggers rebuild, which seems mostly inevitable. [0]
$ python3 include_graph.py net/unix/garbage.c linux/rtnetlink.h linux/netdevice.h ... include/net/af_unix.h | include/linux/net.h | | include/linux/once.h | | include/linux/sockptr.h | | include/uapi/linux/net.h | include/net/sock.h | | include/linux/netdevice.h <--- ... | | include/net/dst.h | | | include/linux/rtnetlink.h <---
Quoted 1 line
[...]
Here is the summary with links:
- [v1,net-next,1/4] af_unix: Sort headers.
https://git.kernel.org/netdev/net-next/c/f9af583a2c76 - [v1,net-next,2/4] af_unix: Move internal definitions to net/unix/. https://git.kernel.org/netdev/net-next/c/84960bf24031 - [v1,net-next,3/4] af_unix: Explicitly include headers for non-pointer struct fields. https://git.kernel.org/netdev/net-next/c/3056172a261c - [v1,net-next,4/4] af_unix: Clean up #include under net/unix/. https://git.kernel.org/netdev/net-next/c/0083e3e37e07
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html