From: Chengwen Feng <fengchengwen@huawei.com>
Make sure to verify the 'dev_id' parameter before using them.
Note: there is no actual problem with the current code, but it is
recommended to clean it up.
Cc: stable@dpdk.org
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/dmadev/rte_dmadev.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
@@ -436,11 +436,12 @@ rte_dma_count_avail(void)
int
rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info)
{
- const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+ const struct rte_dma_dev *dev;
int ret;
if (!rte_dma_is_valid(dev_id) || dev_info == NULL)
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
if (*dev->dev_ops->dev_info_get == NULL)
return -ENOTSUP;
@@ -462,12 +463,13 @@ rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info)
int
rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf)
{
- struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
struct rte_dma_info dev_info;
+ struct rte_dma_dev *dev;
int ret;
if (!rte_dma_is_valid(dev_id) || dev_conf == NULL)
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
if (dev->data->dev_started != 0) {
RTE_DMA_LOG(ERR,
@@ -513,11 +515,12 @@ rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf)
int
rte_dma_start(int16_t dev_id)
{
- struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+ struct rte_dma_dev *dev;
int ret;
if (!rte_dma_is_valid(dev_id))
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
if (dev->data->dev_conf.nb_vchans == 0) {
RTE_DMA_LOG(ERR, "Device %d must be configured first", dev_id);
@@ -545,11 +548,12 @@ rte_dma_start(int16_t dev_id)
int
rte_dma_stop(int16_t dev_id)
{
- struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+ struct rte_dma_dev *dev;
int ret;
if (!rte_dma_is_valid(dev_id))
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
if (dev->data->dev_started == 0) {
RTE_DMA_LOG(WARNING, "Device %d already stopped", dev_id);
@@ -572,11 +576,12 @@ rte_dma_stop(int16_t dev_id)
int
rte_dma_close(int16_t dev_id)
{
- struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+ struct rte_dma_dev *dev;
int ret;
if (!rte_dma_is_valid(dev_id))
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
/* Device must be stopped before it can be closed */
if (dev->data->dev_started == 1) {
@@ -600,13 +605,14 @@ int
rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
const struct rte_dma_vchan_conf *conf)
{
- struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
struct rte_dma_info dev_info;
bool src_is_dev, dst_is_dev;
+ struct rte_dma_dev *dev;
int ret;
if (!rte_dma_is_valid(dev_id) || conf == NULL)
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
if (dev->data->dev_started != 0) {
RTE_DMA_LOG(ERR,
@@ -693,10 +699,11 @@ rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
int
rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats)
{
- const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+ const struct rte_dma_dev *dev;
if (!rte_dma_is_valid(dev_id) || stats == NULL)
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
if (vchan >= dev->data->dev_conf.nb_vchans &&
vchan != RTE_DMA_ALL_VCHAN) {
@@ -715,11 +722,12 @@ rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats)
int
rte_dma_stats_reset(int16_t dev_id, uint16_t vchan)
{
- struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+ struct rte_dma_dev *dev;
int ret;
if (!rte_dma_is_valid(dev_id))
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
if (vchan >= dev->data->dev_conf.nb_vchans &&
vchan != RTE_DMA_ALL_VCHAN) {
@@ -739,10 +747,11 @@ rte_dma_stats_reset(int16_t dev_id, uint16_t vchan)
int
rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *status)
{
- struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+ struct rte_dma_dev *dev;
if (!rte_dma_is_valid(dev_id) || status == NULL)
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
if (vchan >= dev->data->dev_conf.nb_vchans) {
RTE_DMA_LOG(ERR, "Device %u vchan %u out of range", dev_id, vchan);
@@ -804,12 +813,13 @@ dma_dump_capability(FILE *f, uint64_t dev_capa)
int
rte_dma_dump(int16_t dev_id, FILE *f)
{
- const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+ const struct rte_dma_dev *dev;
struct rte_dma_info dev_info;
int ret;
if (!rte_dma_is_valid(dev_id) || f == NULL)
return -EINVAL;
+ dev = &rte_dma_devices[dev_id];
ret = rte_dma_info_get(dev_id, &dev_info);
if (ret != 0) {