[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240119074635.265218-1-chentao@kylinos.cn>
Date: Fri, 19 Jan 2024 15:46:35 +0800
From: Kunwu Chan <chentao@...inos.cn>
To: neil.armstrong@...aro.org,
khilman@...libre.com,
jbrunet@...libre.com,
martin.blumenstingl@...glemail.com
Cc: linux-arm-kernel@...ts.infradead.org,
linux-amlogic@...ts.infradead.org,
linux-kernel@...r.kernel.org,
Kunwu Chan <chentao@...inos.cn>
Subject: [PATCH] meson-mx-socinfo: Fix possible null-pointer dereference issues in meson_mx_socinfo_init
In meson_mx_socinfo_revision, kasprintf() returns a pointer
to dynamically allocated memory which can be NULL upon failure.
Similarly, the kstrdup_const in the meson_mx_socinfo_soc_id
returns a null pointer when it fails. Ensure the allocation was successful
by checking the pointer validity. Avoid null pointer dereference issues.
Signed-off-by: Kunwu Chan <chentao@...inos.cn>
---
drivers/soc/amlogic/meson-mx-socinfo.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/soc/amlogic/meson-mx-socinfo.c b/drivers/soc/amlogic/meson-mx-socinfo.c
index 92125dd65f33..9c0296599561 100644
--- a/drivers/soc/amlogic/meson-mx-socinfo.c
+++ b/drivers/soc/amlogic/meson-mx-socinfo.c
@@ -160,6 +160,12 @@ static int __init meson_mx_socinfo_init(void)
metal_rev);
soc_dev_attr->soc_id = meson_mx_socinfo_soc_id(major_ver, metal_rev);
+ if (!soc_dev_attr->revision || !soc_dev_attr->soc_id) {
+ kfree_const(soc_dev_attr->revision);
+ kfree_const(soc_dev_attr->soc_id);
+ kfree(soc_dev_attr);
+ return -ENOMEM;
+ }
soc_dev = soc_device_register(soc_dev_attr);
if (IS_ERR(soc_dev)) {
kfree_const(soc_dev_attr->revision);
--
2.39.2
Powered by blists - more mailing lists