linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicholas Mc Guire <hofrat@osadl.org>
To: Will Deacon <will.deacon@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Nicholas Mc Guire <hofrat@osadl.org>
Subject: [PATCH V2] perf: arm_spe: handle devm_kasprintf() failure
Date: Thu, 29 Nov 2018 13:55:30 +0100	[thread overview]
Message-ID: <1543496130-7727-1-git-send-email-hofrat@osadl.org> (raw)

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")
Acked-by: Mark Rutland <mark.rutland@arm.com>
---

V2: Changed error message to keep error messages consistent
    as suggested by Mark Rutland <mark.rutland@arm.com> - thanks !

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-rc4 (localversion-next is next-20181129)

 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, "failed to allocate spe_pmu name\n");
+		return -ENOMEM;
+	}
+
 	return perf_pmu_register(&spe_pmu->pmu, name, -1);
 }
 
-- 
2.1.4


                 reply	other threads:[~2018-11-29 12:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1543496130-7727-1-git-send-email-hofrat@osadl.org \
    --to=hofrat@osadl.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).