1

soc: qcom: Add check devm_kasprintf() returned value

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>
Link: https://lore.kernel.org/r/20240929072349.202520-1-hanchunchao@inspur.com
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
This commit is contained in:
Charles Han 2024-09-29 15:23:49 +08:00 committed by Bjorn Andersson
parent 274e58cc22
commit e694d2b5c5

View File

@ -786,10 +786,16 @@ static int qcom_socinfo_probe(struct platform_device *pdev)
qs->attr.revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u.%u", qs->attr.revision = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%u.%u",
SOCINFO_MAJOR(le32_to_cpu(info->ver)), SOCINFO_MAJOR(le32_to_cpu(info->ver)),
SOCINFO_MINOR(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, qs->attr.serial_number = devm_kasprintf(&pdev->dev, GFP_KERNEL,
"%u", "%u",
le32_to_cpu(info->serial_num)); le32_to_cpu(info->serial_num));
if (!qs->attr.serial_number)
return -ENOMEM;
}
qs->soc_dev = soc_device_register(&qs->attr); qs->soc_dev = soc_device_register(&qs->attr);
if (IS_ERR(qs->soc_dev)) if (IS_ERR(qs->soc_dev))