Re: [PATCH RESEND v2 08/23] proc: let procfs own the seq_file of proc_create_seq() and friends

From
sashiko-bot@kernel.org
Date
2026-11-05 19:35:44
Also in
dri-devel, kexec, linux-ext4, linux-hwmon, linux-input, linux-m68k, linux-mm, linux-pci, linux-raid, linux-s390, linux-scsi, linux-serial, linux-sound, linux-usb, sparclinux
Reply to
Christian Brauner, 2026-11-04
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] proc: unused-but-set variable p in seq_open_net() when CONFIG_NET_NS=n
--

commit 4dea51dab83a49a4131e34ad5f96bc9822052389
Author: Christian Brauner [off-list ref]

proc: let procfs own the seq_file of proc_create_seq() and friends

This commit updates proc_create_seq_private(), proc_create_single_data(), and
their network namespace variants so that procfs owns the seq_file directly via
PROC_ENTRY_proc_seq_ops and PROC_ENTRY_proc_show. For the network namespace
variants, ->proc_open() and ->proc_release() are simplified to only manage the
network namespace reference.
quoted hunk ↗ jump to hunk
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
index df5484813d5dd..9973f846c4674 100644
--- a/fs/proc/proc_net.c
+++ b/fs/proc/proc_net.c
@@ -37,13 +37,13 @@ static struct net *get_proc_net(const struct inode *inode)
 	return maybe_get_net(PDE_NET(PDE(inode)));
 }
 
+/* procfs opened the seq_file and allocated its state, see pde_seq_start() */
 static int seq_open_net(struct inode *inode, struct file *file)
 {
-	unsigned int state_size = PDE(inode)->state_size;
-	struct seq_net_private *p;
+	struct seq_net_private *p = ((struct seq_file *)file->private_data)->private;
 	struct net *net;
 
-	WARN_ON_ONCE(state_size < sizeof(*p));
+	WARN_ON_ONCE(PDE(inode)->state_size < sizeof(*p));
 
 	if (file->f_mode & FMODE_WRITE && !PDE(inode)->write)
 		return -EACCES;
@@ -51,12 +51,6 @@ static int seq_open_net(struct inode *inode, struct file *file)
 	net = get_proc_net(inode);
 	if (!net)
 		return -ENXIO;
-
-	p = __seq_open_private(file, PDE(inode)->seq_ops, state_size);
-	if (!p) {
-		put_net(net);
-		return -ENOMEM;
-	}
 #ifdef CONFIG_NET_NS
 	p->net = net;
 	netns_tracker_alloc(net, &p->ns_tracker, GFP_KERNEL);
[Severity: Low]
When CONFIG_NET_NS is disabled, does initializing p unconditionally in
seq_open_net() trigger a -Wunused-but-set-variable warning?

Previously, p was assigned via __seq_open_private() and checked with if (!p)
outside the #ifdef CONFIG_NET_NS block. With that check removed, the only
remaining reference outside #ifdef CONFIG_NET_NS is sizeof(*p) in
WARN_ON_ONCE(), which is an unevaluated context and does not read the value of
p.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-work-procfs-core-v2-0-76ace653a773@kernel.org?part=8
Thread (209 messages) 209 messages, 9 authors, last reply 23d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help