diff options
author | Ben Collins <ben.collins@ubuntu.com> | 2007-05-23 16:57:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-23 23:14:12 -0400 |
commit | 3c6df2a9177c010bf811c361149069e4bfd9bb11 (patch) | |
tree | 151ece2576e9e2481057bc0107aba8c0cc864384 /arch/x86_64 | |
parent | 6754bb4de94098a0aaa23a600f0edb9a9454c252 (diff) |
Avoid zero size allocation in cache_k8_northbridges()
kmalloc for flush_words resulted in zero size allocation when no
k8_northbridges existed. Short circuit the code path for this case.
Also remove uneeded zeroing of num_k8_northbridges just after checking if
it is zero.
Signed-off-by: Ben Collins <bcollins@ubuntu.com>
Cc: Andi Kleen <ak@suse.de>
Cc: Dave Jones <davej@codemonkey.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/x86_64')
-rw-r--r-- | arch/x86_64/kernel/k8.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/arch/x86_64/kernel/k8.c b/arch/x86_64/kernel/k8.c index bc11b32e8b4d..7377ccb21335 100644 --- a/arch/x86_64/kernel/k8.c +++ b/arch/x86_64/kernel/k8.c | |||
@@ -39,10 +39,10 @@ int cache_k8_northbridges(void) | |||
39 | { | 39 | { |
40 | int i; | 40 | int i; |
41 | struct pci_dev *dev; | 41 | struct pci_dev *dev; |
42 | |||
42 | if (num_k8_northbridges) | 43 | if (num_k8_northbridges) |
43 | return 0; | 44 | return 0; |
44 | 45 | ||
45 | num_k8_northbridges = 0; | ||
46 | dev = NULL; | 46 | dev = NULL; |
47 | while ((dev = next_k8_northbridge(dev)) != NULL) | 47 | while ((dev = next_k8_northbridge(dev)) != NULL) |
48 | num_k8_northbridges++; | 48 | num_k8_northbridges++; |
@@ -52,6 +52,11 @@ int cache_k8_northbridges(void) | |||
52 | if (!k8_northbridges) | 52 | if (!k8_northbridges) |
53 | return -ENOMEM; | 53 | return -ENOMEM; |
54 | 54 | ||
55 | if (!num_k8_northbridges) { | ||
56 | k8_northbridges[0] = NULL; | ||
57 | return 0; | ||
58 | } | ||
59 | |||
55 | flush_words = kmalloc(num_k8_northbridges * sizeof(u32), GFP_KERNEL); | 60 | flush_words = kmalloc(num_k8_northbridges * sizeof(u32), GFP_KERNEL); |
56 | if (!flush_words) { | 61 | if (!flush_words) { |
57 | kfree(k8_northbridges); | 62 | kfree(k8_northbridges); |