Thread (37 messages) 37 messages, 7 authors, 2021-09-15
STALE1753d LANDED

[PATCH 06/13] sysfs: simplify sysfs_kf_seq_show

From: Christoph Hellwig <hch@lst.de>
Date: 2021-09-13 05:48:35
Also in: linux-fsdevel, linux-xfs, lkml
Subsystem: driver core, kobjects, debugfs and sysfs, filesystems (vfs and infrastructure), the rest · Maintainers: Greg Kroah-Hartman, "Rafael J. Wysocki", Danilo Krummrich, Alexander Viro, Christian Brauner, Linus Torvalds

Contrary to the comment ->show is never called from lseek for sysfs,
given that sysfs does not use seq_lseek.  So remove the NULL ->show
case and just WARN and return an error if some future code path ends
up here.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/sysfs/file.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 74a2a8021c8bb..42dcf96881b68 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -45,6 +45,9 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
 	ssize_t count;
 	char *buf;
 
+	if (WARN_ON_ONCE(!ops->show))
+		return -EINVAL;
+
 	/* acquire buffer and ensure that it's >= PAGE_SIZE and clear */
 	count = seq_get_buf(sf, &buf);
 	if (count < PAGE_SIZE) {
@@ -53,15 +56,9 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
 	}
 	memset(buf, 0, PAGE_SIZE);
 
-	/*
-	 * Invoke show().  Control may reach here via seq file lseek even
-	 * if @ops->show() isn't implemented.
-	 */
-	if (ops->show) {
-		count = ops->show(kobj, of->kn->priv, buf);
-		if (count < 0)
-			return count;
-	}
+	count = ops->show(kobj, of->kn->priv, buf);
+	if (count < 0)
+		return count;
 
 	/*
 	 * The code works fine with PAGE_SIZE return but it's likely to
-- 
2.30.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help