diff options
author | Andrew Morton <akpm@linux-foundation.org> | 2012-10-23 17:09:39 -0400 |
---|---|---|
committer | Borislav Petkov <borislav.petkov@amd.com> | 2012-10-24 10:13:27 -0400 |
commit | 168bfeef7bba3f9784f7540b053e4ac72b769ce9 (patch) | |
tree | a02890616eb3d65377be628ff9cd1b577beb36df /drivers | |
parent | 6f0c0580b70c89094b3422ba81118c7b959c7556 (diff) |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/edac/amd64_edac.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c index 5a297a26211d..cc8e7c78a23c 100644 --- a/drivers/edac/amd64_edac.c +++ b/drivers/edac/amd64_edac.c | |||
@@ -170,8 +170,11 @@ static int __amd64_set_scrub_rate(struct pci_dev *ctl, u32 new_bw, u32 min_rate) | |||
170 | * memory controller and apply to register. Search for the first | 170 | * memory controller and apply to register. Search for the first |
171 | * bandwidth entry that is greater or equal than the setting requested | 171 | * bandwidth entry that is greater or equal than the setting requested |
172 | * and program that. If at last entry, turn off DRAM scrubbing. | 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 | * skip scrub rates which aren't recommended | 179 | * skip scrub rates which aren't recommended |
177 | * (see F10 BKDG, F3x58) | 180 | * (see F10 BKDG, F3x58) |
@@ -181,12 +184,6 @@ static int __amd64_set_scrub_rate(struct pci_dev *ctl, u32 new_bw, u32 min_rate) | |||
181 | 184 | ||
182 | if (scrubrates[i].bandwidth <= new_bw) | 185 | if (scrubrates[i].bandwidth <= new_bw) |
183 | break; | 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 | scrubval = scrubrates[i].scrubval; | 189 | scrubval = scrubrates[i].scrubval; |