From patchwork Thu Nov 29 12:55:30 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: 10704513 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 67C4213BB for ; Thu, 29 Nov 2018 13:00:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 573DA2EDAC for ; Thu, 29 Nov 2018 13:00:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BA8F2EDB3; Thu, 29 Nov 2018 13:00:00 +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 300272EDAC for ; Thu, 29 Nov 2018 12:59:59 +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=X8EfaEq6ouVxJ6KK9iVbS8+8XI+G/6Sf20IoAm8ypw8=; b=OfW bMCg+4dxoUDytzfx9NXfMIb0SDY2KRPJbvdJeqcr4zNj9KRf7YipzRJP2AKLQaTvrq3rFn7nEcwWD IbwmBF52X42C9EPnx+/ncsOFR7C3evDbIcD35MV0Ru4g/e+ksOfE+pc4Wq/uOTtZCpHJ1CdaMywH4 n0ywL15B4w86p1zli4KTtOpoCSvnaDPpCP7y36zSWa96kgdmJKk/n4BVRh6LUgQ1jdPrQXdj7tmUW ZkggVhzP/CKKKYf+aoMURsBr3tW/OlU8Cd3fzcMhsjOMyDDEu7Q9XtnQu9d7K8kmjrFmIZdcBaqkj +F/WqkEOGSXQMcA/Lkyg8vrzohN/DAw==; 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 1gSLv9-0002FH-OF; Thu, 29 Nov 2018 12:59:55 +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 1gSLv6-0002Ev-RG for linux-arm-kernel@lists.infradead.org; Thu, 29 Nov 2018 12:59:54 +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 wATCwSXr028330; Thu, 29 Nov 2018 13:58:28 +0100 From: Nicholas Mc Guire To: Will Deacon Subject: [PATCH V2] perf: arm_spe: handle devm_kasprintf() failure Date: Thu, 29 Nov 2018 13:55:30 +0100 Message-Id: <1543496130-7727-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-20181129_045953_186190_A1401D9B X-CRM114-Status: GOOD ( 11.42 ) 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 --- V2: Changed error message to keep error messages consistent as suggested by Mark Rutland - 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); }