Re: [PATCH] fix topology init take 2

From: Andreas Schwab <schwab_at_suse.de>
Date: 2003-10-21 06:50:16
jbarnes@sgi.com (Jesse Barnes) writes:

> @@ -43,3 +50,49 @@
>  
>  	return (i < num_memblks) ? node_memblk[i].nid : (num_memblks ? -1 : 0);
>  }
> +
> +static int __init topology_init(void)
> +{
> +	int i, err = 0;
> +
> +	sysfs_nodes = kmalloc(sizeof(struct node) * numnodes, GFP_KERNEL);
> +	if (!sysfs_nodes) {
> +		err = -ENOMEM;
> +		goto out;
> +	}
> +
> +	sysfs_memblks = kmalloc(sizeof(struct memblk) * num_memblks,
> +				GFP_KERNEL);
> +	if (!sysfs_memblks) {
> +		kfree(sysfs_nodes);
> +		err = -ENOMEM;
> +		goto out;
> +	}
> +
> +	sysfs_cpus = kmalloc(sizeof(struct cpu) * NR_CPUS, GFP_KERNEL);
> +	if (!sysfs_cpus) {
> +		kfree(sysfs_memblks);
> +		kfree(sysfs_nodes);
> +		err = -ENOMEM;
> +		goto out;
> +	}
> +
> +	for (i = 0; i < numnodes; i++)
> +		if ((err = register_node(&sysfs_nodes[i], i, 0)))
> +			goto out;
> +	
> +	for (i = 0; i < num_memblks; i++)
> +		if ((err = register_memblk(&sysfs_memblks[i], i,
> +					   &sysfs_nodes[memblk_to_node(i)])))
> +			goto out;
> +	
> +	for (i = 0; i < NR_CPUS; i++)
> +		if (cpu_online(i))
> +			if((err = register_cpu(&sysfs_cpus[i], i,
> +					       &sysfs_nodes[cpu_to_node(i)])))
> +				goto out;

You need to clear all kmalloc'd memory before you can pass it to
register_{node,memblk,cpu}, otherwise sys_device_register may trip over
the uninitialized sysdev.

--- linux-2.6.0-test8/arch/ia64/mm/numa.c.~1~	2003-10-20 21:25:23.000000000 +0200
+++ linux-2.6.0-test8/arch/ia64/mm/numa.c	2003-10-20 22:00:21.000000000 +0200
@@ -76,6 +76,9 @@ static int __init topology_init(void)
 		err = -ENOMEM;
 		goto out;
 	}
+	memset(sysfs_nodes, 0, sizeof(struct node) * numnodes);
+	memset(sysfs_memblks, 0, sizeof(struct memblk) * num_memblks);
+	memset(sysfs_cpus, 0, sizeof(struct cpu) * NR_CPUS);
 
 	for (i = 0; i < numnodes; i++)
 		if ((err = register_node(&sysfs_nodes[i], i, 0)))

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Mon Oct 20 16:51:52 2003

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:19 EST