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 B6B523FFE; Tue, 23 Jan 2024 00:49:18 +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=1705970958; cv=none; b=WE4t9BQRjo2g/dHqXUyfnOz6hYZlj3outYDzmLjyfGAiLv1okQsOMX4uoEyMPUKlfSIYsg6+80XVxFiWwizUIyV3O/ttCxeA6Mh8Mpd1gc0LVFOWglQP5bt/6Uzzt1f4R7hd8So+z38SF9axayj6Wd2WL9/BrF6ehC3QweGBzWE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705970958; c=relaxed/simple; bh=IfB3qHli62QSHZAbeSRf1BBORuR+UMg2Hc5J5N7jbMQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gEsmpJeidgMdB+X+BV4eg4zxPPu0IxnD/wXxVjhLkE5Jar1/fcvyF9kU2f+uQks8208JZiNVvSdPeZGOW7oxH9RG+0JIrTdZZrpzgXJbfS3Wjs7jGTRVzFlQL1zrx4jPXh1zGz2rrWSW6DBECTbWhLeVG0WusRsWXZI+qPGip9A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tVwq+ccc; 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="tVwq+ccc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55018C433C7; Tue, 23 Jan 2024 00:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705970958; bh=IfB3qHli62QSHZAbeSRf1BBORuR+UMg2Hc5J5N7jbMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tVwq+ccckiqjoi32R5rKxZ/dy8IBIqJ8yM15uUywnLZC8juHFQvlU9YktyAasISnZ /NLLOnGqRuhnunNoGF9xxaFDFQrm9R5eA2lMrAUzkvYEyXayVzOsDa6TXU4X4wOP8J r34mI5oUYHkBsmqsy5jyiSPzIfBWZlhajlBCVa1k= 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 5.10 057/286] powerpc/powernv: Add a null pointer check to scom_debug_init_one() Date: Mon, 22 Jan 2024 15:56:03 -0800 Message-ID: <20240122235734.223377087@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235732.009174833@linuxfoundation.org> References: <20240122235732.009174833@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kunwu Chan [ Upstream commit 9a260f2dd827bbc82cc60eb4f4d8c22707d80742 ] kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Add a null pointer check, and release 'ent' to avoid memory leaks. Fixes: bfd2f0d49aef ("powerpc/powernv: Get rid of old scom_controller abstraction") Signed-off-by: Kunwu Chan Signed-off-by: Michael Ellerman Link: https://msgid.link/20231208085937.107210-1-chentao@kylinos.cn Signed-off-by: Sasha Levin --- arch/powerpc/platforms/powernv/opal-xscom.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c b/arch/powerpc/platforms/powernv/opal-xscom.c index fd510d961b8c..d5814c5046ba 100644 --- a/arch/powerpc/platforms/powernv/opal-xscom.c +++ b/arch/powerpc/platforms/powernv/opal-xscom.c @@ -165,6 +165,11 @@ static int scom_debug_init_one(struct dentry *root, struct device_node *dn, ent->chip = chip; snprintf(ent->name, 16, "%08x", chip); ent->path.data = (void *)kasprintf(GFP_KERNEL, "%pOF", dn); + if (!ent->path.data) { + kfree(ent); + return -ENOMEM; + } + ent->path.size = strlen((char *)ent->path.data); dir = debugfs_create_dir(ent->name, root); -- 2.43.0