diff options
author | Christoph Hellwig <hch@lst.de> | 2021-09-13 07:41:14 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-09-14 17:03:01 +0200 |
commit | 820879ee1865f7010ec3a949322f643f008c9feb (patch) | |
tree | 59e97ff1ee770f7b4367eea6a30dac69941bdf0f /fs | |
parent | d1a1a9606e080c9767e229742f5b331b3b551c0c (diff) | |
download | linux-stable-820879ee1865f7010ec3a949322f643f008c9feb.tar.gz linux-stable-820879ee1865f7010ec3a949322f643f008c9feb.tar.bz2 linux-stable-820879ee1865f7010ec3a949322f643f008c9feb.zip |
sysfs: simplify sysfs_kf_seq_show
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/sysfs/file.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 74a2a8021c8b..42dcf96881b6 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 |