From: Chengchang Tang Date: Fri, 2 Apr 2021 02:58:49 +0000 (+0800) Subject: ethdev: validate input in register info X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=94af45f4005ee0c3152db45a3669bec5238a3c10;p=dpdk.git ethdev: validate input in register info This patch adds validity check of input pointer in regs dump API. Fixes: 7a3f27cbf59b ("ethdev: add access to specific device info") Fixes: 936eda25e8da ("net/hns3: support dump register") Cc: stable@dpdk.org Signed-off-by: Chengchang Tang Signed-off-by: Min Hu (Connor) Reviewed-by: Ferruh Yigit --- diff --git a/drivers/net/hns3/hns3_regs.c b/drivers/net/hns3/hns3_regs.c index d53c132b1e..5d15613c67 100644 --- a/drivers/net/hns3/hns3_regs.c +++ b/drivers/net/hns3/hns3_regs.c @@ -484,11 +484,6 @@ hns3_get_regs(struct rte_eth_dev *eth_dev, struct rte_dev_reg_info *regs) uint32_t *data; int ret; - if (regs == NULL) { - hns3_err(hw, "the input parameter regs is NULL!"); - return -EINVAL; - } - ret = hns3_get_regs_length(hw, &length); if (ret) return ret; diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index bb195abe70..3fe200d508 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -5286,6 +5286,8 @@ rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info) struct rte_eth_dev *dev; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + if (info == NULL) + return -EINVAL; dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP); diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index f5bbc10b68..1ad7cda27d 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -4403,6 +4403,7 @@ int rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id, * @return * - (0) if successful. * - (-ENOTSUP) if hardware doesn't support. + * - (-EINVAL) if bad parameter. * - (-ENODEV) if *port_id* invalid. * - (-EIO) if device is removed. * - others depends on the specific operations implementation.