Commit 860b7d22 authored by Anju T Sudhakar's avatar Anju T Sudhakar Committed by Michael Ellerman

powerpc/perf: Fix loop exit condition in nest_imc_event_init

The data structure (i.e struct imc_mem_info) to hold the memory address
information for nest imc units is allocated based on the number of nodes
in the system.

nest_imc_event_init() traverse this struct array to calculate the memory
base address for the event-cpu. If we fail to find a match for the event
cpu's chip-id in imc_mem_info struct array, then the do-while loop will
iterate until we crash.

Fix this by changing the loop exit condition based on the number of
non zero vbase elements in the array, since the allocation is done for
nr_chips + 1.
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Fixes: 885dcd70 ("powerpc/perf: Add nest IMC PMU support")
Signed-off-by: default avatarAnju T Sudhakar <anju@linux.vnet.ibm.com>
Reviewed-by: default avatarMadhavan Srinivasan <maddy@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent a913e5e8
...@@ -499,7 +499,7 @@ static int nest_imc_event_init(struct perf_event *event) ...@@ -499,7 +499,7 @@ static int nest_imc_event_init(struct perf_event *event)
break; break;
} }
pcni++; pcni++;
} while (pcni); } while (pcni->vbase != 0);
if (!flag) if (!flag)
return -ENODEV; return -ENODEV;
......
...@@ -127,7 +127,7 @@ static int imc_get_mem_addr_nest(struct device_node *node, ...@@ -127,7 +127,7 @@ static int imc_get_mem_addr_nest(struct device_node *node,
nr_chips)) nr_chips))
goto error; goto error;
pmu_ptr->mem_info = kcalloc(nr_chips, sizeof(*pmu_ptr->mem_info), pmu_ptr->mem_info = kcalloc(nr_chips + 1, sizeof(*pmu_ptr->mem_info),
GFP_KERNEL); GFP_KERNEL);
if (!pmu_ptr->mem_info) if (!pmu_ptr->mem_info)
goto error; goto error;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment