Commit 168bfeef7bba3f9784f7540b053e4ac72b769ce9
Committed by
Borislav Petkov
1 parent
6f0c0580b7
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
amd64_edac:__amd64_set_scrub_rate(): avoid overindexing scrubrates[]
If none of the elements in scrubrates[] matches, this loop will cause __amd64_set_scrub_rate() to incorrectly use the n+1th element. As the function is designed to use the final scrubrates[] element in the case of no match, we can fix this bug by simply terminating the array search at the n-1th element. Boris: this code is fragile anyway, see here why: http://marc.info/?l=linux-kernel&m=135102834131236&w=2 It will be rewritten more robustly soonish. Reported-by: Denis Kirjanov <kirjanov@gmail.com> Cc: stable@vger.kernel.org Cc: Doug Thompson <dougthompson@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
Showing 1 changed file with 4 additions and 7 deletions Side-by-side Diff
drivers/edac/amd64_edac.c
... | ... | @@ -170,8 +170,11 @@ |
170 | 170 | * memory controller and apply to register. Search for the first |
171 | 171 | * bandwidth entry that is greater or equal than the setting requested |
172 | 172 | * and program that. If at last entry, turn off DRAM scrubbing. |
173 | + * | |
174 | + * If no suitable bandwidth is found, turn off DRAM scrubbing entirely | |
175 | + * by falling back to the last element in scrubrates[]. | |
173 | 176 | */ |
174 | - for (i = 0; i < ARRAY_SIZE(scrubrates); i++) { | |
177 | + for (i = 0; i < ARRAY_SIZE(scrubrates) - 1; i++) { | |
175 | 178 | /* |
176 | 179 | * skip scrub rates which aren't recommended |
177 | 180 | * (see F10 BKDG, F3x58) |
... | ... | @@ -181,12 +184,6 @@ |
181 | 184 | |
182 | 185 | if (scrubrates[i].bandwidth <= new_bw) |
183 | 186 | break; |
184 | - | |
185 | - /* | |
186 | - * if no suitable bandwidth found, turn off DRAM scrubbing | |
187 | - * entirely by falling back to the last element in the | |
188 | - * scrubrates array. | |
189 | - */ | |
190 | 187 | } |
191 | 188 | |
192 | 189 | scrubval = scrubrates[i].scrubval; |