]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/hns: Initialize seqfile before creating file
authorJunxian Huang <huangjunxian6@hisilicon.com>
Thu, 7 May 2026 01:21:46 +0000 (09:21 +0800)
committerLeon Romanovsky <leon@kernel.org>
Mon, 18 May 2026 08:58:41 +0000 (04:58 -0400)
The debugfs file was created before seq->read and seq->data were set,
leaving a small window where userspace could access an uninitialized
seqfile.

Move debugfs_create_file() after the assignments to avoid this issue.
Also, inline the original init_debugfs_seqfile() since it is not a
really necessary helper.

Fixes: ca7ad04cd5d2 ("RDMA/hns: Add debugfs to hns RoCE")
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
Link: https://patch.msgid.link/20260507012148.1079712-2-huangjunxian6@hisilicon.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/hns/hns_roce_debugfs.c

index b869cdc5411893dcb6c3ef072f9d17a0d1a69d5a..db32c5897640fbb32973b27a0495baf1dc8acd37 100644 (file)
@@ -26,17 +26,6 @@ static const struct file_operations hns_debugfs_seqfile_fops = {
        .llseek = seq_lseek
 };
 
-static void init_debugfs_seqfile(struct hns_debugfs_seqfile *seq,
-                                const char *name, struct dentry *parent,
-                                int (*read_fn)(struct seq_file *, void *),
-                                void *data)
-{
-       debugfs_create_file(name, 0400, parent, seq, &hns_debugfs_seqfile_fops);
-
-       seq->read = read_fn;
-       seq->data = data;
-}
-
 static const char * const sw_stat_info[] = {
        [HNS_ROCE_DFX_AEQE_CNT] = "aeqe",
        [HNS_ROCE_DFX_CEQE_CNT] = "ceqe",
@@ -76,10 +65,12 @@ static void create_sw_stat_debugfs(struct hns_roce_dev *hr_dev,
 {
        struct hns_sw_stat_debugfs *dbgfs = &hr_dev->dbgfs.sw_stat_root;
 
-       dbgfs->root = debugfs_create_dir("sw_stat", parent);
+       dbgfs->sw_stat.read = sw_stat_debugfs_show;
+       dbgfs->sw_stat.data = hr_dev;
 
-       init_debugfs_seqfile(&dbgfs->sw_stat, "sw_stat", dbgfs->root,
-                            sw_stat_debugfs_show, hr_dev);
+       dbgfs->root = debugfs_create_dir("sw_stat", parent);
+       debugfs_create_file("sw_stat", 0400, dbgfs->root, &dbgfs->sw_stat,
+                           &hns_debugfs_seqfile_fops);
 }
 
 /* debugfs for device */