net/qede/base: add a sanity check
authorRasesh Mody <rasesh.mody@cavium.com>
Tue, 19 Sep 2017 01:29:51 +0000 (18:29 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 6 Oct 2017 00:49:48 +0000 (02:49 +0200)
Add a sanity check that the offset being used to access the runtime array
is not greater/equal than/to RUNTIME_ARRAY_SIZE

Signed-off-by: Rasesh Mody <rasesh.mody@cavium.com>
drivers/net/qede/base/ecore_init_ops.c

index b907a95..80a52ca 100644 (file)
@@ -40,6 +40,13 @@ void ecore_init_clear_rt_data(struct ecore_hwfn *p_hwfn)
 
 void ecore_init_store_rt_reg(struct ecore_hwfn *p_hwfn, u32 rt_offset, u32 val)
 {
+       if (rt_offset >= RUNTIME_ARRAY_SIZE) {
+               DP_ERR(p_hwfn,
+                      "Avoid storing %u in rt_data at index %u since RUNTIME_ARRAY_SIZE is %u!\n",
+                      val, rt_offset, RUNTIME_ARRAY_SIZE);
+               return;
+       }
+
        p_hwfn->rt_data.init_val[rt_offset] = val;
        p_hwfn->rt_data.b_valid[rt_offset] = true;
 }
@@ -49,6 +56,14 @@ void ecore_init_store_rt_agg(struct ecore_hwfn *p_hwfn,
 {
        osal_size_t i;
 
+       if ((rt_offset + size - 1) >= RUNTIME_ARRAY_SIZE) {
+               DP_ERR(p_hwfn,
+                      "Avoid storing values in rt_data at indices %u-%u since RUNTIME_ARRAY_SIZE is %u!\n",
+                      rt_offset, (u32)(rt_offset + size - 1),
+                      RUNTIME_ARRAY_SIZE);
+               return;
+       }
+
        for (i = 0; i < size / sizeof(u32); i++) {
                p_hwfn->rt_data.init_val[rt_offset + i] = p_val[i];
                p_hwfn->rt_data.b_valid[rt_offset + i] = true;