[PATCH] soc: qcom: Add check devm_kasprintf() returned value

Charles Han posted 1 patch 2 months ago
drivers/soc/qcom/socinfo.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
[PATCH] soc: qcom: Add check devm_kasprintf() returned value
Posted by Charles Han 2 months ago
devm_kasprintf() can return a NULL pointer on failure but this
returned value in qcom_socinfo_probe() is not checked.

Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/soc/qcom/socinfo.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index 24c3971f2ef1..e42d86d5f6f9 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -786,10 +786,16 @@ static int qcom_socinfo_probe(struct platform_device *pdev)
 	qs->attr.revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u.%u",
 					   SOCINFO_MAJOR(le32_to_cpu(info->ver)),
 					   SOCINFO_MINOR(le32_to_cpu(info->ver)));
-	if (offsetof(struct socinfo, serial_num) <= item_size)
+	if (!qs->attr.soc_id || qs->attr.revision)
+		return -ENOMEM;
+
+	if (offsetof(struct socinfo, serial_num) <= item_size) {
 		qs->attr.serial_number = devm_kasprintf(&pdev->dev, GFP_KERNEL,
 							"%u",
 							le32_to_cpu(info->serial_num));
+		if (!qs->attr.serial_number)
+			return -ENOMEM;
+	}
 
 	qs->soc_dev = soc_device_register(&qs->attr);
 	if (IS_ERR(qs->soc_dev))
-- 
2.31.1
Re: [PATCH] soc: qcom: Add check devm_kasprintf() returned value
Posted by Bjorn Andersson 1 month, 3 weeks ago
On Sun, 29 Sep 2024 15:23:49 +0800, Charles Han wrote:
> devm_kasprintf() can return a NULL pointer on failure but this
> returned value in qcom_socinfo_probe() is not checked.
> 
> 

Applied, thanks!

[1/1] soc: qcom: Add check devm_kasprintf() returned value
      commit: e694d2b5c58ba2d1e995d068707c8d966e7f5f2a

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>