提交 73848eb3 编写于 作者: K Kai Ye 提交者: Zheng Zengkai

crypto: hisilicon/qm - add pci bdf number check

mainline inclusion
from v6.1-rc4
commit 22d7a6c3
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5ZHPY
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=22d7a6c39cabab811f42cb2daed2343c87b0aca5

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

The pci bdf number check is added for qos written by using the pci api.
Directly get the devfn by pci_dev, so delete some redundant code.
And use the kstrtoul instead of sscanf to simplify code.
Signed-off-by: NKai Ye <yekai13@huawei.com>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NJiangshui Yang <yangjiangshui@h-partners.com>
Reviewed-by: NXiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 39cda6b9
...@@ -4593,49 +4593,36 @@ static ssize_t qm_algqos_read(struct file *filp, char __user *buf, ...@@ -4593,49 +4593,36 @@ static ssize_t qm_algqos_read(struct file *filp, char __user *buf,
return ret; return ret;
} }
static ssize_t qm_qos_value_init(const char *buf, unsigned long *val)
{
int buflen = strlen(buf);
int ret, i;
for (i = 0; i < buflen; i++) {
if (!isdigit(buf[i]))
return -EINVAL;
}
ret = sscanf(buf, "%lu", val);
if (ret != QM_QOS_VAL_NUM)
return -EINVAL;
return 0;
}
static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf, static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
unsigned long *val, unsigned long *val,
unsigned int *fun_index) unsigned int *fun_index)
{ {
struct bus_type *bus_type = qm->pdev->dev.bus;
char tbuf_bdf[QM_DBG_READ_LEN] = {0}; char tbuf_bdf[QM_DBG_READ_LEN] = {0};
char val_buf[QM_DBG_READ_LEN] = {0}; char val_buf[QM_DBG_READ_LEN] = {0};
u32 tmp1, device, function; struct pci_dev *pdev;
int ret, bus; struct device *dev;
int ret;
ret = sscanf(buf, "%s %s", tbuf_bdf, val_buf); ret = sscanf(buf, "%s %s", tbuf_bdf, val_buf);
if (ret != QM_QOS_PARAM_NUM) if (ret != QM_QOS_PARAM_NUM)
return -EINVAL; return -EINVAL;
ret = qm_qos_value_init(val_buf, val); ret = kstrtoul(val_buf, 10, val);
if (ret || *val == 0 || *val > QM_QOS_MAX_VAL) { if (ret || *val == 0 || *val > QM_QOS_MAX_VAL) {
pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n"); pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n");
return -EINVAL; return -EINVAL;
} }
ret = sscanf(tbuf_bdf, "%u:%x:%u.%u", &tmp1, &bus, &device, &function); dev = bus_find_device_by_name(bus_type, NULL, tbuf_bdf);
if (ret != QM_QOS_BDF_PARAM_NUM) { if (!dev) {
pci_err(qm->pdev, "input pci bdf value is error!\n"); pci_err(qm->pdev, "input pci bdf number is error!\n");
return -EINVAL; return -ENODEV;
} }
*fun_index = PCI_DEVFN(device, function); pdev = container_of(dev, struct pci_dev, dev);
*fun_index = pdev->devfn;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册