Commit cea3dc48 authored by Yufeng Mo's avatar Yufeng Mo Committed by Yang Yingliang
Browse files

net: hns3: change the method of getting cmd index in debugfs



mainline inclusion
from mainline-v5.14-rc7
commit 55649d56
category: bugfix
bugzilla: NA
CVE: NA

----------------------------

Currently, the cmd index is obtained in debugfs by comparing file names.
However, this method may cause errors when processing more complex file
names. So, change this method by saving cmd in private data and comparing
it when getting cmd index in debugfs for optimization.

Fixes: 5e69ea7e ("net: hns3: refactor the debugfs process")
Signed-off-by: default avatarYufeng Mo <moyufeng@huawei.com>
Signed-off-by: default avatarGuangbin Huang <huangguangbin2@huawei.com>
Signed-off-by: default avatarYonglong Liu <liuyonglong@huawei.com>
Reviewed-by: default avatarJunxin Chen <chenjunxin1@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
parent 6908cfb5
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -813,20 +813,19 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const char __user *buffer,
	return count;
}

static int hns3_dbg_get_cmd_index(struct hnae3_handle *handle,
				  const unsigned char *name, u32 *index)
static int hns3_dbg_get_cmd_index(struct hns3_dbg_data *dbg_data, u32 *index)
{
	u32 i;

	for (i = 0; i < ARRAY_SIZE(hns3_dbg_cmd); i++) {
		if (!strncmp(name, hns3_dbg_cmd[i].name,
			     strlen(hns3_dbg_cmd[i].name))) {
		if (hns3_dbg_cmd[i].cmd == dbg_data->cmd) {
			*index = i;
			return 0;
		}
	}

	dev_err(&handle->pdev->dev, "unknown command(%s)\n", name);
	dev_err(&dbg_data->handle->pdev->dev, "unknown command(%d)\n",
		dbg_data->cmd);
	return -EINVAL;
}

@@ -890,8 +889,7 @@ static ssize_t hns3_dbg_read(struct file *filp, char __user *buffer,
	u32 index;
	int ret;

	ret = hns3_dbg_get_cmd_index(handle, filp->f_path.dentry->d_iname,
				     &index);
	ret = hns3_dbg_get_cmd_index(dbg_data, &index);
	if (ret)
		return ret;

@@ -968,6 +966,7 @@ static int hns3_dbg_bd_file_init(struct hnae3_handle *handle, u32 cmd)
		char name[HNS3_DBG_FILE_NAME_LEN];

		data[i].handle = handle;
		data[i].cmd = hns3_dbg_cmd[cmd].cmd;
		data[i].qid = i;
		sprintf(name, "%s%u", hns3_dbg_cmd[cmd].name, i);
		debugfs_create_file(name, 0400, entry_dir, &data[i],
@@ -987,6 +986,7 @@ static int hns3_dbg_common_file_init(struct hnae3_handle *handle, u32 cmd)
		return -ENOMEM;

	data->handle = handle;
	data->cmd = hns3_dbg_cmd[cmd].cmd;
	entry_dir = hns3_dbg_dentry[hns3_dbg_cmd[cmd].dentry].dentry;
	debugfs_create_file(hns3_dbg_cmd[cmd].name, 0400, entry_dir,
			    data, &hns3_dbg_fops);
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ struct hns3_dbg_item {

struct hns3_dbg_data {
	struct hnae3_handle *handle;
	enum hnae3_dbg_cmd cmd;
	u16 qid;
};