From patchwork Wed Nov 28 11:24:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 10702359 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A8BE14D6 for ; Wed, 28 Nov 2018 11:29:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A6872C777 for ; Wed, 28 Nov 2018 11:29:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E9FD2CE31; Wed, 28 Nov 2018 11:29:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 927962C777 for ; Wed, 28 Nov 2018 11:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=9DHPCGite70utUJB4SU7tNKx77nonF8hEWRKBnjTJmk=; b=nUx 6RPUHHPcuS292OXpjUXDKIhAonkKEn+9x/0pr6tdpN1v04Eamc0/dmAcbXv89XlynmQ3qhJfxL7vf KtxynAHMz1DTjIwnb80iuXqSNqEPvTArCXsjR7WmA1G0HNWGH04mUWUTqARp3TYNpZWpDNil6iz1O i97fn6284dA+GZICTZRyFhG1ArTTU4tLPT4alaDoxmLejLGsB99iuMIliH75PtHuTi3rVaTHskGuz w5zvU9DhoSsMar4N5GVz4egZmXwkAKIFsYpjE0ReULXSwqXRXThvB+/9+4Zqr+2WhAKnqMz9VH23a wrMKLFlVeA2GpqWd90Z/LUdUeDMvcJg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRy1l-0000TY-AA; Wed, 28 Nov 2018 11:29:09 +0000 Received: from www.osadl.org ([62.245.132.105]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRy1h-0000TE-Kr for linux-arm-kernel@lists.infradead.org; Wed, 28 Nov 2018 11:29:07 +0000 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wASBRjpc031178; Wed, 28 Nov 2018 12:27:45 +0100 From: Nicholas Mc Guire To: Will Deacon Subject: [PATCH] perf: arm_spe: handle devm_kasprintf() failure Date: Wed, 28 Nov 2018 12:24:47 +0100 Message-Id: <1543404287-3946-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181128_032905_981937_BBFF6C80 X-CRM114-Status: GOOD ( 10.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Nicholas Mc Guire MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Fixes: d5d9696b0380 ("drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension") Acked-by: Mark Rutland --- 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); }