ARM: tegra: dvfs: Prevent CL-DVFS map allocation overflow
Alex Frid [Sat, 13 Jul 2013 23:26:51 +0000 (16:26 -0700)]
Instead of generating BUG() when number of CL-DVFS output map entries
exceeds look up table size, store maximum voltage mapping, and abort
allocation when last available slot is reached.

Change-Id: Ibff18a82e4efa3729f3e0641473acb826429a8e5
Signed-off-by: Alex Frid <afrid@nvidia.com>
Reviewed-on: http://git-master/r/248945
(cherry picked from commit 38c68198819c6fb1d2c9cff3d2e498b5f9a25e23)
Reviewed-on: http://git-master/r/254680
(cherry picked from commit e2af4d6762b2cfe2353ee9f1394442245e99b769)
Reviewed-on: http://git-master/r/274914
GVS: Gerrit_Virtual_Submit
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>

arch/arm/mach-tegra/tegra_cl_dvfs.c

index ee11c98..1d3958a 100644 (file)
@@ -961,7 +961,7 @@ static void cl_dvfs_init_maps(struct tegra_cl_dvfs *cld)
                                cld->out_map[j++] = m;
                }
 
-               v = millivolts[i];
+               v = (j == MAX_CL_DVFS_VOLTAGES - 1) ? v_max : millivolts[i];
                m = find_vdd_map_entry(cld, v, true);
                BUG_ON(!m);
                if (m != cld->out_map[j - 1])
@@ -972,8 +972,10 @@ static void cl_dvfs_init_maps(struct tegra_cl_dvfs *cld)
                        cld->clk_dvfs_map[i] = cld->out_map[j - 1]->reg_value;
                        BUG_ON(cld->clk_dvfs_map[i] > OUT_MASK + 1);
                }
+
+               if (v >= v_max)
+                       break;
        }
-       BUG_ON(j > MAX_CL_DVFS_VOLTAGES);
        cld->num_voltages = j;
 }