Skip to content

Commit

Permalink
Avoid zero size allocation in cache_k8_northbridges()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ben Collins authored and Linus Torvalds committed May 24, 2007
1 parent 6754bb4 commit 3c6df2a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion arch/x86_64/kernel/k8.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ int cache_k8_northbridges(void)
{
int i;
struct pci_dev *dev;

if (num_k8_northbridges)
return 0;

num_k8_northbridges = 0;
dev = NULL;
while ((dev = next_k8_northbridge(dev)) != NULL)
num_k8_northbridges++;
Expand All @@ -52,6 +52,11 @@ int cache_k8_northbridges(void)
if (!k8_northbridges)
return -ENOMEM;

if (!num_k8_northbridges) {
k8_northbridges[0] = NULL;
return 0;
}

flush_words = kmalloc(num_k8_northbridges * sizeof(u32), GFP_KERNEL);
if (!flush_words) {
kfree(k8_northbridges);
Expand Down

0 comments on commit 3c6df2a

Please sign in to comment.