Skip to content

Commit 9c9a042

Browse files
Yufeng MoPaolo Abeni
authored andcommitted
net: hns3: fix the concurrency between functions reading debugfs
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: 5e69ea7 ("net: hns3: refactor the debugfs process") Signed-off-by: Yufeng Mo <moyufeng@huawei.com> Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 1e71cfc commit 9c9a042

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ struct hnae3_handle {
845845
struct dentry *hnae3_dbgfs;
846846
/* protects concurrent contention between debugfs commands */
847847
struct mutex dbgfs_lock;
848+
char **dbgfs_buf;
848849

849850
/* Network interface message level enabled bits */
850851
u32 msg_enable;

drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ static ssize_t hns3_dbg_read(struct file *filp, char __user *buffer,
12271227
return ret;
12281228

12291229
mutex_lock(&handle->dbgfs_lock);
1230-
save_buf = &hns3_dbg_cmd[index].buf;
1230+
save_buf = &handle->dbgfs_buf[index];
12311231

12321232
if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
12331233
test_bit(HNS3_NIC_STATE_RESETTING, &priv->state)) {
@@ -1332,6 +1332,13 @@ int hns3_dbg_init(struct hnae3_handle *handle)
13321332
int ret;
13331333
u32 i;
13341334

1335+
handle->dbgfs_buf = devm_kcalloc(&handle->pdev->dev,
1336+
ARRAY_SIZE(hns3_dbg_cmd),
1337+
sizeof(*handle->dbgfs_buf),
1338+
GFP_KERNEL);
1339+
if (!handle->dbgfs_buf)
1340+
return -ENOMEM;
1341+
13351342
hns3_dbg_dentry[HNS3_DBG_DENTRY_COMMON].dentry =
13361343
debugfs_create_dir(name, hns3_dbgfs_root);
13371344
handle->hnae3_dbgfs = hns3_dbg_dentry[HNS3_DBG_DENTRY_COMMON].dentry;
@@ -1380,9 +1387,9 @@ void hns3_dbg_uninit(struct hnae3_handle *handle)
13801387
u32 i;
13811388

13821389
for (i = 0; i < ARRAY_SIZE(hns3_dbg_cmd); i++)
1383-
if (hns3_dbg_cmd[i].buf) {
1384-
kvfree(hns3_dbg_cmd[i].buf);
1385-
hns3_dbg_cmd[i].buf = NULL;
1390+
if (handle->dbgfs_buf[i]) {
1391+
kvfree(handle->dbgfs_buf[i]);
1392+
handle->dbgfs_buf[i] = NULL;
13861393
}
13871394

13881395
mutex_destroy(&handle->dbgfs_lock);

drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ struct hns3_dbg_cmd_info {
4949
enum hnae3_dbg_cmd cmd;
5050
enum hns3_dbg_dentry_type dentry;
5151
u32 buf_len;
52-
char *buf;
5352
int (*init)(struct hnae3_handle *handle, unsigned int cmd);
5453
};
5554

0 commit comments

Comments
 (0)