From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF805131E3A; Tue, 23 Jan 2024 00:18:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969097; cv=none; b=odtj07YOWdILAzriJ7XPgHBI0WOCp6Glhtz9nV3Xn1FcN5fEJG4BPM3EKuMBxaKZgaLjorjp/kcKuSdw0YNPo1zfRLxBI5ZxCrLO2lnPMQGgyUXdo5Pl4AyoyuJ19KFs+nh/t2xH5XeIiCVwZv6t63WbfeV8KwT8XOrtEUcNUG0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969097; c=relaxed/simple; bh=fyXDzKqV/1L4tsjnlyagnNlJnvu8wadLbT73gvQfC9c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I+0omSjC3+kWgatKGxrn2LL1ERA3C1kwvRsrR8Nt4sharY/dxCiWju+VxcqcWIK+PCpGJ2q+3LTWBXwlKr65Bf9qf2/uHvXamtwddPBAkReg6T9ZTP5+Q6y2tgFTnappqq61osyxjI8nSpmKfGDJK3mOR3ePe4rMmx2e3Hblg6Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=rs30aegn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="rs30aegn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0AEFC433C7; Tue, 23 Jan 2024 00:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705969096; bh=fyXDzKqV/1L4tsjnlyagnNlJnvu8wadLbT73gvQfC9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rs30aegnE2uSK6QfdBVw/SmPU3+gqvaoB8CsrOiVc0u/VEMI9Zs0p9g3+AJMKi4bd 2orAPIB3EP91czw+SP5KAvMsF0iUKvdBSCKwRLX0fVdwhPJgm7b61H8IYw8XOjJys8 xw7XBbEYpU+V6uSCTtmBCXPfvrO1Cc6U11DQVHQU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kunwu Chan , Michael Ellerman , Sasha Levin Subject: [PATCH 6.7 019/641] powerpc/imc-pmu: Add a null pointer check in update_events_in_group() Date: Mon, 22 Jan 2024 15:48:43 -0800 Message-ID: <20240122235818.707667681@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235818.091081209@linuxfoundation.org> References: <20240122235818.091081209@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kunwu Chan [ Upstream commit 0a233867a39078ebb0f575e2948593bbff5826b3 ] kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Fixes: 885dcd709ba9 ("powerpc/perf: Add nest IMC PMU support") Signed-off-by: Kunwu Chan Signed-off-by: Michael Ellerman Link: https://msgid.link/20231126093719.1440305-1-chentao@kylinos.cn Signed-off-by: Sasha Levin --- arch/powerpc/perf/imc-pmu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c index 5d12ca386c1f..8664a7d297ad 100644 --- a/arch/powerpc/perf/imc-pmu.c +++ b/arch/powerpc/perf/imc-pmu.c @@ -299,6 +299,8 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu) attr_group->attrs = attrs; do { ev_val_str = kasprintf(GFP_KERNEL, "event=0x%x", pmu->events[i].value); + if (!ev_val_str) + continue; dev_str = device_str_attr_create(pmu->events[i].name, ev_val_str); if (!dev_str) continue; @@ -306,6 +308,8 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu) attrs[j++] = dev_str; if (pmu->events[i].scale) { ev_scale_str = kasprintf(GFP_KERNEL, "%s.scale", pmu->events[i].name); + if (!ev_scale_str) + continue; dev_str = device_str_attr_create(ev_scale_str, pmu->events[i].scale); if (!dev_str) continue; @@ -315,6 +319,8 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu) if (pmu->events[i].unit) { ev_unit_str = kasprintf(GFP_KERNEL, "%s.unit", pmu->events[i].name); + if (!ev_unit_str) + continue; dev_str = device_str_attr_create(ev_unit_str, pmu->events[i].unit); if (!dev_str) continue; -- 2.43.0