drivers/ddr: Fix possible out of bounds error
PATCH v2 1/1 drivers/ddr: Fix possible out of bounds error
This is a theoretical possible out of bounds error in DDR driver. Adding check before using array index. Also change some runtime conditions to pre-compiling conditions.
Signed-off-by York Sun <[email protected]>
---
Change log:
v2: Revise subject and commit message
drivers/ddr/fsl/ctrl_regs.c | 8 ++-- drivers/ddr/fsl/main.c | 6 +++ drivers/ddr/fsl/options.c | 108 +++++++++++++++++++++---------------------- 3 files changed, 64 insertions(+), 58 deletions(-)
drivers/ddr/fsl/ctrl_regs.c +4 -4
@@ -507,8 +507,8 @@ static void set_timing_cfg_1(fsl_ddr_cfg_regs_t *ddr, wrrec_mclk =picos_to_mclk (common_dimm->twr_ps); acttoact_mclk =max (picos_to_mclk (common_dimm->trrds_ps),4 ); wrtord_mclk =max (2 ,picos_to_mclk (2500 )); -if (wrrec_mclk >24 ) -printf ("Error: WRREC doesn't support more than 24 clocks\n" ); +if ((wrrec_mclk <1 ) || (wrrec_mclk >24 )) +printf ("Error: WRREC doesn't support %d clocks\n" , wrrec_mclk);else wrrec_mclk = wrrec_table[wrrec_mclk -1 ];#else
@@ -516,8 +516,8 @@ static void set_timing_cfg_1(fsl_ddr_cfg_regs_t *ddr, wrrec_mclk =picos_to_mclk (common_dimm->twr_ps); acttoact_mclk =picos_to_mclk (common_dimm->trrd_ps); wrtord_mclk =picos_to_mclk (common_dimm->twtr_ps); -if (wrrec_mclk >16 ) -printf ("Error: WRREC doesn't support more than 16 clocks\n" ); +if ((wrrec_mclk <1 ) || (wrrec_mclk >16 )) +printf ("Error: WRREC doesn't support %d clocks\n" , wrrec_mclk);else wrrec_mclk = wrrec_table[wrrec_mclk -1 ];#endif
drivers/ddr/fsl/main.c +6 -0
@@ -220,6 +220,11 @@ const char * step_to_string(unsigned int step) {if ((1 << s) != step)return step_string_tbl[7 ]; +if (s >=ARRAY_SIZE (step_string_tbl)) { +printf ("Error for the step in %s\n" , __func__); + s =0 ; + } +return step_string_tbl[s]; }
@@ -520,6 +525,7 @@ fsl_ddr_compute(fsl_ddr_info_t *pinfo, unsigned int start_step,/* STEP 5: Assign addresses to chip selects */ check_interleaving_options (pinfo); total_mem =step_assign_addresses (pinfo, dbw_capacity_adjust); +debug ("Total mem %llu assigned\n" , total_mem);case STEP_COMPUTE_REGS :/* STEP 6: compute controller register values */
drivers/ddr/fsl/options.c +54 -54
147 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 1/1 drivers/ddr: Fix possible out of bounds error
Quoted 9 lines · York Sun
This is a theoretical possible out of bounds error in DDR driver. Adding check before using array index. Also change some runtime conditions to pre-compiling conditions.
Signed-off-by York Sun <[email protected]>---
Change log:
v2: Revise subject and commit message
Applied to u-boot-mpc85xx/master.
York