]> Git Repo - linux.git/commitdiff
net: hns3: fix the concurrency between functions reading debugfs
authorYufeng Mo <[email protected]>
Wed, 30 Mar 2022 13:45:05 +0000 (21:45 +0800)
committerPaolo Abeni <[email protected]>
Thu, 31 Mar 2022 09:39:59 +0000 (11:39 +0200)
Currently, the debugfs mechanism is that all functions share a
global variable to save the pointer for obtaining data. When
different functions concurrently access the same file node,
repeated release exceptions occur. Therefore, the granularity
of the pointer for storing the obtained data is adjusted to be
private for each function.

Fixes: 5e69ea7ee2a6 ("net: hns3: refactor the debugfs process")
Signed-off-by: Yufeng Mo <[email protected]>
Signed-off-by: Guangbin Huang <[email protected]>
Signed-off-by: Paolo Abeni <[email protected]>
drivers/net/ethernet/hisilicon/hns3/hnae3.h
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.h

index d44dd7091fa136923e301b924e56cd3ddcb16152..79c64f4e67d2b4457442c24a6018dc31f62b37b5 100644 (file)
@@ -845,6 +845,7 @@ struct hnae3_handle {
        struct dentry *hnae3_dbgfs;
        /* protects concurrent contention between debugfs commands */
        struct mutex dbgfs_lock;
+       char **dbgfs_buf;
 
        /* Network interface message level enabled bits */
        u32 msg_enable;
index f726a5b70f9e2dc271bc9f2dabe068d06b0cfda2..44d9b560b3374f8f2ad8d7b0b1596e1b4f7bce50 100644 (file)
@@ -1227,7 +1227,7 @@ static ssize_t hns3_dbg_read(struct file *filp, char __user *buffer,
                return ret;
 
        mutex_lock(&handle->dbgfs_lock);
-       save_buf = &hns3_dbg_cmd[index].buf;
+       save_buf = &handle->dbgfs_buf[index];
 
        if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
            test_bit(HNS3_NIC_STATE_RESETTING, &priv->state)) {
@@ -1332,6 +1332,13 @@ int hns3_dbg_init(struct hnae3_handle *handle)
        int ret;
        u32 i;
 
+       handle->dbgfs_buf = devm_kcalloc(&handle->pdev->dev,
+                                        ARRAY_SIZE(hns3_dbg_cmd),
+                                        sizeof(*handle->dbgfs_buf),
+                                        GFP_KERNEL);
+       if (!handle->dbgfs_buf)
+               return -ENOMEM;
+
        hns3_dbg_dentry[HNS3_DBG_DENTRY_COMMON].dentry =
                                debugfs_create_dir(name, hns3_dbgfs_root);
        handle->hnae3_dbgfs = hns3_dbg_dentry[HNS3_DBG_DENTRY_COMMON].dentry;
@@ -1380,9 +1387,9 @@ void hns3_dbg_uninit(struct hnae3_handle *handle)
        u32 i;
 
        for (i = 0; i < ARRAY_SIZE(hns3_dbg_cmd); i++)
-               if (hns3_dbg_cmd[i].buf) {
-                       kvfree(hns3_dbg_cmd[i].buf);
-                       hns3_dbg_cmd[i].buf = NULL;
+               if (handle->dbgfs_buf[i]) {
+                       kvfree(handle->dbgfs_buf[i]);
+                       handle->dbgfs_buf[i] = NULL;
                }
 
        mutex_destroy(&handle->dbgfs_lock);
index 83aa1450ab9fe383bd31e979a885131329e4bf6a..97578eabb7d8b7a2defc1ac1422bb77f29b1f6bf 100644 (file)
@@ -49,7 +49,6 @@ struct hns3_dbg_cmd_info {
        enum hnae3_dbg_cmd cmd;
        enum hns3_dbg_dentry_type dentry;
        u32 buf_len;
-       char *buf;
        int (*init)(struct hnae3_handle *handle, unsigned int cmd);
 };
 
This page took 0.057181 seconds and 4 git commands to generate.