Drivers: hv: vmbus: Fix synic per-cpu context initialization
If hv_synic_alloc() errors out, the state of the per-cpu context for some CPUs is unknown since the zero'ing is done as each CPU is iterated over. In such case, hv_synic_cleanup() may try to free memory based on uninitialized values. Fix this by zero'ing the per-cpu context for all CPUs before doing any memory allocations that might fail. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
8e6925631a
commit
f25a7ece08
|
@ -189,6 +189,17 @@ static void hv_init_clockevent_device(struct clock_event_device *dev, int cpu)
|
||||||
int hv_synic_alloc(void)
|
int hv_synic_alloc(void)
|
||||||
{
|
{
|
||||||
int cpu;
|
int cpu;
|
||||||
|
struct hv_per_cpu_context *hv_cpu;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* First, zero all per-cpu memory areas so hv_synic_free() can
|
||||||
|
* detect what memory has been allocated and cleanup properly
|
||||||
|
* after any failures.
|
||||||
|
*/
|
||||||
|
for_each_present_cpu(cpu) {
|
||||||
|
hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu);
|
||||||
|
memset(hv_cpu, 0, sizeof(*hv_cpu));
|
||||||
|
}
|
||||||
|
|
||||||
hv_context.hv_numa_map = kcalloc(nr_node_ids, sizeof(struct cpumask),
|
hv_context.hv_numa_map = kcalloc(nr_node_ids, sizeof(struct cpumask),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
|
@ -198,10 +209,8 @@ int hv_synic_alloc(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
for_each_present_cpu(cpu) {
|
for_each_present_cpu(cpu) {
|
||||||
struct hv_per_cpu_context *hv_cpu
|
hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu);
|
||||||
= per_cpu_ptr(hv_context.cpu_context, cpu);
|
|
||||||
|
|
||||||
memset(hv_cpu, 0, sizeof(*hv_cpu));
|
|
||||||
tasklet_init(&hv_cpu->msg_dpc,
|
tasklet_init(&hv_cpu->msg_dpc,
|
||||||
vmbus_on_msg_dpc, (unsigned long) hv_cpu);
|
vmbus_on_msg_dpc, (unsigned long) hv_cpu);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue