* numa_reset_distance() uses numa_distance * sizeof(numa_distance[0]) as the table size when it should be using the square of numa_distance.

* The same size miscalculation when allocation space for phys_dist in numa_emulation().

* In numa_emulation(), phys_dist must be reserved; otherwise, the new emulated distance table may overlap it.

Fix them and, while at it, take numa_distance_cnt resetting innuma_reset_distance() out of the if block to simplify the code a bit.

David Rientjes reported incorrect handling of distance table duringemulation and Yinghai identified the above problems and wrote theoriginal patch to fix the problems. This patch is based on Yinghai'spatch.