sysfs: simplify sysfs_kf_seq_show
authorChristoph Hellwig <hch@lst.de>
Mon, 13 Sep 2021 05:41:14 +0000 (07:41 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Sep 2021 15:03:01 +0000 (17:03 +0200)
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.

Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210913054121.616001-7-hch@lst.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/sysfs/file.c

index 74a2a8021c8bbd3d4f7551472c991ef147587896..42dcf96881b688f3474a76bb6b618eade3c2b959 100644 (file)
@@ -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