net/ipn3ke: fix null pointer dereference
authorAndy Pei <andy.pei@intel.com>
Thu, 23 May 2019 04:31:22 +0000 (12:31 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Thu, 20 Jun 2019 21:42:04 +0000 (23:42 +0200)
In 'ipn3ke_hw_tm_node_wr()', elements of 'n->parent_node' are accessed
but 'n->parent_node' can be NULL.

After applying this patch, this null pointer dereference is avoided.

Coverity issue: 337921
Fixes: c820468ac99c ("net/ipn3ke: support TM")
Cc: stable@dpdk.org
Signed-off-by: Andy Pei <andy.pei@intel.com>
Acked-by: Rosen Xu <rosen.xu@intel.com>
drivers/net/ipn3ke/ipn3ke_tm.c

index 39c49bc..10828fc 100644 (file)
@@ -1568,7 +1568,8 @@ ipn3ke_tm_hierarchy_commit_check(struct rte_eth_dev *dev,
 
 static int
 ipn3ke_hw_tm_node_wr(struct ipn3ke_hw *hw,
-                               struct ipn3ke_tm_node *n)
+       struct ipn3ke_tm_node *n,
+       struct ipn3ke_tm_node *parent_node)
 {
        uint32_t level;
 
@@ -1639,11 +1640,12 @@ ipn3ke_hw_tm_node_wr(struct ipn3ke_hw *hw,
                /**
                 * Configure Map
                 */
-               IPN3KE_MASK_WRITE_REG(hw,
-                               IPN3KE_QOS_MAP_L2_X,
-                               n->node_index,
-                               n->parent_node->node_index,
-                               IPN3KE_QOS_MAP_L2_MASK);
+               if (parent_node)
+                       IPN3KE_MASK_WRITE_REG(hw,
+                                       IPN3KE_QOS_MAP_L2_X,
+                                       n->node_index,
+                                       parent_node->node_index,
+                                       IPN3KE_QOS_MAP_L2_MASK);
 
                break;
        case IPN3KE_TM_NODE_LEVEL_COS:
@@ -1696,11 +1698,12 @@ ipn3ke_hw_tm_node_wr(struct ipn3ke_hw *hw,
                                        0x80000000))
                        ;
 
-               IPN3KE_MASK_WRITE_REG(hw,
-                       IPN3KE_QM_UID_CONFIG_DATA,
-                       0,
-                       (1 << 8 | n->parent_node->parent_node->node_index),
-                       0x1FF);
+               if (parent_node && parent_node->parent_node)
+                       IPN3KE_MASK_WRITE_REG(hw,
+                               IPN3KE_QM_UID_CONFIG_DATA,
+                               0,
+                               (1 << 8 | parent_node->parent_node->node_index),
+                               0x1FF);
 
                IPN3KE_MASK_WRITE_REG(hw,
                                IPN3KE_QM_UID_CONFIG_CTRL,
@@ -1717,11 +1720,12 @@ ipn3ke_hw_tm_node_wr(struct ipn3ke_hw *hw,
                /**
                 * Configure Map
                 */
-               IPN3KE_MASK_WRITE_REG(hw,
-                               IPN3KE_QOS_MAP_L1_X,
-                               n->node_index,
-                               n->parent_node->node_index,
-                               IPN3KE_QOS_MAP_L1_MASK);
+               if (parent_node)
+                       IPN3KE_MASK_WRITE_REG(hw,
+                                       IPN3KE_QOS_MAP_L1_X,
+                                       n->node_index,
+                                       parent_node->node_index,
+                                       IPN3KE_QOS_MAP_L1_MASK);
 
                break;
        default:
@@ -1761,7 +1765,8 @@ ipn3ke_tm_hierarchy_hw_commit(struct rte_eth_dev *dev,
                                                NULL,
                                                rte_strerror(EINVAL));
                }
-               ipn3ke_hw_tm_node_wr(hw, n);
+               parent_node = n->parent_node;
+               ipn3ke_hw_tm_node_wr(hw, n, parent_node);
        }
 
        nl = &tm->h.vt_commit_node_list;
@@ -1791,7 +1796,7 @@ ipn3ke_tm_hierarchy_hw_commit(struct rte_eth_dev *dev,
                                                NULL,
                                                rte_strerror(EINVAL));
                }
-               ipn3ke_hw_tm_node_wr(hw, n);
+               ipn3ke_hw_tm_node_wr(hw, n, parent_node);
        }
 
        nl = &tm->h.cos_commit_node_list;
@@ -1825,7 +1830,7 @@ ipn3ke_tm_hierarchy_hw_commit(struct rte_eth_dev *dev,
                                                NULL,
                                                rte_strerror(EINVAL));
                }
-               ipn3ke_hw_tm_node_wr(hw, n);
+               ipn3ke_hw_tm_node_wr(hw, n, parent_node);
        }
 
        return 0;