* powerpc/perf: Fix a sizeof() typo so we allocate less memory
@ 2017-11-04 7:51 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2017-11-04 7:51 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Anju T Sudhakar
Cc: Paul Mackerras, Michael Ellerman, Madhavan Srinivasan,
Hemant Kumar, linuxppc-dev, kernel-janitors
We're allocating the size of the struct which is 32 bytes when we should
be allocating sizeof(void *) which is 4 or 8 bytes depending on the
architecture.
Fixes: 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 88126245881b..91c90ddab807 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -210,7 +210,7 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
of_property_read_u32(node, "reg", &base_reg);
/* Allocate memory for the events */
- pmu->events = kcalloc(ct, sizeof(struct imc_events), GFP_KERNEL);
+ pmu->events = kcalloc(ct, sizeof(*pmu->events), GFP_KERNEL);
if (!pmu->events)
return -ENOMEM;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* powerpc/perf: Fix a sizeof() typo so we allocate less memory
@ 2017-11-04 7:51 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2017-11-04 7:51 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Anju T Sudhakar
Cc: Paul Mackerras, Michael Ellerman, Madhavan Srinivasan,
Hemant Kumar, linuxppc-dev, kernel-janitors
We're allocating the size of the struct which is 32 bytes when we should
be allocating sizeof(void *) which is 4 or 8 bytes depending on the
architecture.
Fixes: 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 88126245881b..91c90ddab807 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -210,7 +210,7 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
of_property_read_u32(node, "reg", &base_reg);
/* Allocate memory for the events */
- pmu->events = kcalloc(ct, sizeof(struct imc_events), GFP_KERNEL);
+ pmu->events = kcalloc(ct, sizeof(*pmu->events), GFP_KERNEL);
if (!pmu->events)
return -ENOMEM;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: powerpc/perf: Fix a sizeof() typo so we allocate less memory
2017-11-04 7:51 ` Dan Carpenter
@ 2017-11-06 10:39 ` Michael Ellerman
-1 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2017-11-06 10:39 UTC (permalink / raw)
To: Dan Carpenter, Benjamin Herrenschmidt, Anju T Sudhakar
Cc: Paul Mackerras, Madhavan Srinivasan, Hemant Kumar, linuxppc-dev,
kernel-janitors
Dan Carpenter <dan.carpenter@oracle.com> writes:
> We're allocating the size of the struct which is 32 bytes when we should
> be allocating sizeof(void *) which is 4 or 8 bytes depending on the
> architecture.
>
> Fixes: 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Thanks.
I think your patch is right, but the code would be much simpler if we
actually did just allocate an array of struct imc_events, rather than an
array of pointers to structs.
Some of the cleanup code is written as if that is already the case, ie.
it frees the pmu->events array, but not the things the array points to.
So there's a memory leak there too.
Anju, Maddy, can one of you rework the code to just use an array of
structs? Basically imc_parse_event() wouldn't allocate a struct, we
would pass it a pointer to a slot in the array.
cheers
> diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
> index 88126245881b..91c90ddab807 100644
> --- a/arch/powerpc/perf/imc-pmu.c
> +++ b/arch/powerpc/perf/imc-pmu.c
> @@ -210,7 +210,7 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
> of_property_read_u32(node, "reg", &base_reg);
>
> /* Allocate memory for the events */
> - pmu->events = kcalloc(ct, sizeof(struct imc_events), GFP_KERNEL);
> + pmu->events = kcalloc(ct, sizeof(*pmu->events), GFP_KERNEL);
> if (!pmu->events)
> return -ENOMEM;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: powerpc/perf: Fix a sizeof() typo so we allocate less memory
@ 2017-11-06 10:39 ` Michael Ellerman
0 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2017-11-06 10:39 UTC (permalink / raw)
To: Dan Carpenter, Benjamin Herrenschmidt, Anju T Sudhakar
Cc: Paul Mackerras, Madhavan Srinivasan, Hemant Kumar, linuxppc-dev,
kernel-janitors
Dan Carpenter <dan.carpenter@oracle.com> writes:
> We're allocating the size of the struct which is 32 bytes when we should
> be allocating sizeof(void *) which is 4 or 8 bytes depending on the
> architecture.
>
> Fixes: 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Thanks.
I think your patch is right, but the code would be much simpler if we
actually did just allocate an array of struct imc_events, rather than an
array of pointers to structs.
Some of the cleanup code is written as if that is already the case, ie.
it frees the pmu->events array, but not the things the array points to.
So there's a memory leak there too.
Anju, Maddy, can one of you rework the code to just use an array of
structs? Basically imc_parse_event() wouldn't allocate a struct, we
would pass it a pointer to a slot in the array.
cheers
> diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
> index 88126245881b..91c90ddab807 100644
> --- a/arch/powerpc/perf/imc-pmu.c
> +++ b/arch/powerpc/perf/imc-pmu.c
> @@ -210,7 +210,7 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
> of_property_read_u32(node, "reg", &base_reg);
>
> /* Allocate memory for the events */
> - pmu->events = kcalloc(ct, sizeof(struct imc_events), GFP_KERNEL);
> + pmu->events = kcalloc(ct, sizeof(*pmu->events), GFP_KERNEL);
> if (!pmu->events)
> return -ENOMEM;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-06 10:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-04 7:51 powerpc/perf: Fix a sizeof() typo so we allocate less memory Dan Carpenter
2017-11-04 7:51 ` Dan Carpenter
2017-11-06 10:39 ` Michael Ellerman
2017-11-06 10:39 ` Michael Ellerman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.