* [PATCH] perf: arm_spe: handle devm_kasprintf() failure
@ 2018-11-28 11:24 Nicholas Mc Guire
2018-11-29 12:14 ` Mark Rutland
0 siblings, 1 reply; 3+ messages in thread
From: Nicholas Mc Guire @ 2018-11-28 11:24 UTC (permalink / raw)
To: Will Deacon
Cc: Mark Rutland, linux-arm-kernel, linux-kernel, Nicholas Mc Guire
devm_kasprintf() may return NULL on failure of internal allocation
thus the assignment to name is not safe if unchecked. if NULL
is passed in for name then perf_pmu_register() would not fail
but rather silently jump to skip_type which is not the intent
here. As perf_pmu_register() may also return -ENOMEM returning
-ENOMEM in the (unlikely) failure case of devm_kasprintf() should
be fine here as well.
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Fixes: d5d9696b0380 ("drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension")
---
Problem located with an experimental coccinelle script
The dev_err() might seem a bit much for this unlikely error but as
perf_pmu_register() may also return -ENOMEM it would be hard to figure
out what went wrong without this message.
Patch was compile tested with: defconfig (ARCH=arm64) +
ARM_SPE_PMU=y
Patch is against 4.20-rc3 (localversion-next is next-20181128)
drivers/perf/arm_spe_pmu.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index 54ec278..f1ea00c 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -927,6 +927,11 @@ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu)
idx = atomic_inc_return(&pmu_idx);
name = devm_kasprintf(dev, GFP_KERNEL, "%s_%d", PMUNAME, idx);
+ if (!name) {
+ dev_err(dev, "Allocation of name failed\n");
+ return -ENOMEM;
+ }
+
return perf_pmu_register(&spe_pmu->pmu, name, -1);
}
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf: arm_spe: handle devm_kasprintf() failure
2018-11-28 11:24 [PATCH] perf: arm_spe: handle devm_kasprintf() failure Nicholas Mc Guire
@ 2018-11-29 12:14 ` Mark Rutland
2018-11-29 16:01 ` Will Deacon
0 siblings, 1 reply; 3+ messages in thread
From: Mark Rutland @ 2018-11-29 12:14 UTC (permalink / raw)
To: Nicholas Mc Guire; +Cc: Will Deacon, linux-arm-kernel, linux-kernel
On Wed, Nov 28, 2018 at 12:24:47PM +0100, Nicholas Mc Guire wrote:
> devm_kasprintf() may return NULL on failure of internal allocation
> thus the assignment to name is not safe if unchecked. if NULL
> is passed in for name then perf_pmu_register() would not fail
> but rather silently jump to skip_type which is not the intent
> here. As perf_pmu_register() may also return -ENOMEM returning
> -ENOMEM in the (unlikely) failure case of devm_kasprintf() should
> be fine here as well.
>
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> Fixes: d5d9696b0380 ("drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension")
> ---
>
> Problem located with an experimental coccinelle script
>
> The dev_err() might seem a bit much for this unlikely error but as
> perf_pmu_register() may also return -ENOMEM it would be hard to figure
> out what went wrong without this message.
>
> Patch was compile tested with: defconfig (ARCH=arm64) +
> ARM_SPE_PMU=y
>
> Patch is against 4.20-rc3 (localversion-next is next-20181128)
>
> drivers/perf/arm_spe_pmu.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
> index 54ec278..f1ea00c 100644
> --- a/drivers/perf/arm_spe_pmu.c
> +++ b/drivers/perf/arm_spe_pmu.c
> @@ -927,6 +927,11 @@ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu)
>
> idx = atomic_inc_return(&pmu_idx);
> name = devm_kasprintf(dev, GFP_KERNEL, "%s_%d", PMUNAME, idx);
> + if (!name) {
> + dev_err(dev, "Allocation of name failed\n");
> + return -ENOMEM;
> + }
In the other dev_err() messages, we use the form "failed to ...", e.g.
"failed to get IRQ (%d)\n"
"failed to get PPI partition (%d)\n
"failed to allocate spe_pmu\n"
... so for consistency could you please change the string to:
"failed to allocate spe_pmu name\n"
With that, feel free to add:
Acked-by: Mark Rutland <mark.rutland@arm.com>
Mark.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf: arm_spe: handle devm_kasprintf() failure
2018-11-29 12:14 ` Mark Rutland
@ 2018-11-29 16:01 ` Will Deacon
0 siblings, 0 replies; 3+ messages in thread
From: Will Deacon @ 2018-11-29 16:01 UTC (permalink / raw)
To: Mark Rutland; +Cc: Nicholas Mc Guire, linux-arm-kernel, linux-kernel
On Thu, Nov 29, 2018 at 12:14:32PM +0000, Mark Rutland wrote:
> On Wed, Nov 28, 2018 at 12:24:47PM +0100, Nicholas Mc Guire wrote:
> > diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
> > index 54ec278..f1ea00c 100644
> > --- a/drivers/perf/arm_spe_pmu.c
> > +++ b/drivers/perf/arm_spe_pmu.c
> > @@ -927,6 +927,11 @@ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu)
> >
> > idx = atomic_inc_return(&pmu_idx);
> > name = devm_kasprintf(dev, GFP_KERNEL, "%s_%d", PMUNAME, idx);
> > + if (!name) {
> > + dev_err(dev, "Allocation of name failed\n");
> > + return -ENOMEM;
> > + }
>
> In the other dev_err() messages, we use the form "failed to ...", e.g.
>
> "failed to get IRQ (%d)\n"
> "failed to get PPI partition (%d)\n
> "failed to allocate spe_pmu\n"
>
> ... so for consistency could you please change the string to:
>
> "failed to allocate spe_pmu name\n"
>
> With that, feel free to add:
>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
Thanks, I've queued this for 4.21 with a tweaked error message.
Will
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-29 16:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28 11:24 [PATCH] perf: arm_spe: handle devm_kasprintf() failure Nicholas Mc Guire
2018-11-29 12:14 ` Mark Rutland
2018-11-29 16:01 ` Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).