raw/ntb: fix null pointer dereference
[dpdk.git] / drivers / raw / ntb / ntb.c
index c83b8d9..bfecce1 100644 (file)
@@ -240,11 +240,19 @@ ntb_enqueue_bufs(struct rte_rawdev *dev,
                 unsigned int count,
                 rte_rawdev_obj_t context)
 {
-       RTE_SET_USED(dev);
-       RTE_SET_USED(buffers);
-       RTE_SET_USED(count);
-       RTE_SET_USED(context);
+       /* Not FIFO right now. Just for testing memory write. */
+       struct ntb_hw *hw = dev->dev_private;
+       unsigned int i;
+       void *bar_addr;
+       size_t size;
+
+       if (hw->ntb_ops->get_peer_mw_addr == NULL)
+               return -ENOTSUP;
+       bar_addr = (*hw->ntb_ops->get_peer_mw_addr)(dev, 0);
+       size = (size_t)context;
 
+       for (i = 0; i < count; i++)
+               rte_memcpy(bar_addr, buffers[i]->buf_addr, size);
        return 0;
 }
 
@@ -254,11 +262,15 @@ ntb_dequeue_bufs(struct rte_rawdev *dev,
                 unsigned int count,
                 rte_rawdev_obj_t context)
 {
-       RTE_SET_USED(dev);
-       RTE_SET_USED(buffers);
-       RTE_SET_USED(count);
-       RTE_SET_USED(context);
+       /* Not FIFO. Just for testing memory read. */
+       struct ntb_hw *hw = dev->dev_private;
+       unsigned int i;
+       size_t size;
 
+       size = (size_t)context;
+
+       for (i = 0; i < count; i++)
+               rte_memcpy(buffers[i]->buf_addr, hw->mz[i]->addr, size);
        return 0;
 }
 
@@ -435,14 +447,16 @@ static int
 ntb_attr_set(struct rte_rawdev *dev, const char *attr_name,
                                 uint64_t attr_value)
 {
-       struct ntb_hw *hw = dev->dev_private;
-       int index = 0;
+       struct ntb_hw *hw;
+       int index;
 
        if (dev == NULL || attr_name == NULL) {
                NTB_LOG(ERR, "Invalid arguments for setting attributes");
                return -EINVAL;
        }
 
+       hw = dev->dev_private;
+
        if (!strncmp(attr_name, NTB_SPAD_USER, NTB_SPAD_USER_LEN)) {
                if (hw->ntb_ops->spad_write == NULL)
                        return -ENOTSUP;
@@ -463,14 +477,16 @@ static int
 ntb_attr_get(struct rte_rawdev *dev, const char *attr_name,
                                 uint64_t *attr_value)
 {
-       struct ntb_hw *hw = dev->dev_private;
-       int index = 0;
+       struct ntb_hw *hw;
+       int index;
 
        if (dev == NULL || attr_name == NULL || attr_value == NULL) {
                NTB_LOG(ERR, "Invalid arguments for getting attributes");
                return -EINVAL;
        }
 
+       hw = dev->dev_private;
+
        if (!strncmp(attr_name, NTB_TOPO_NAME, NTB_ATTR_NAME_LEN)) {
                *attr_value = hw->topo;
                NTB_LOG(INFO, "Attribute (%s) Value (%" PRIu64 ")",
@@ -723,7 +739,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
 
        if (pci_dev == NULL) {
                NTB_LOG(ERR, "Invalid pci_dev.");
-               ret = -EINVAL;
+               return -EINVAL;
        }
 
        memset(name, 0, sizeof(name));
@@ -738,7 +754,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
                                         socket_id);
        if (rawdev == NULL) {
                NTB_LOG(ERR, "Unable to allocate rawdev.");
-               ret = -EINVAL;
+               return -EINVAL;
        }
 
        rawdev->dev_ops = &ntb_ops;
@@ -754,7 +770,7 @@ ntb_create(struct rte_pci_device *pci_dev, int socket_id)
        return ret;
 
 fail:
-       if (rawdev)
+       if (rawdev != NULL)
                rte_rawdev_pmd_release(rawdev);
 
        return ret;