From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Charles Han <hanchunchao@inspur.com>,
Bjorn Andersson <andersson@kernel.org>,
Sasha Levin <sashal@kernel.org>,
konradybcio@kernel.org, linux-arm-msm@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 1/6] soc: qcom: Add check devm_kasprintf() returned value
Date: Tue, 12 Nov 2024 05:37:56 -0500 [thread overview]
Message-ID: <20241112103803.1654174-1-sashal@kernel.org> (raw)
From: Charles Han <hanchunchao@inspur.com>
[ Upstream commit e694d2b5c58ba2d1e995d068707c8d966e7f5f2a ]
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 60c82dcaa8d1d..7bb3543e42e59 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -507,10 +507,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.43.0
next reply other threads:[~2024-11-12 10:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 10:37 Sasha Levin [this message]
2024-11-12 10:37 ` [PATCH AUTOSEL 5.10 2/6] regulator: rk808: Add apply_bit for BUCK3 on RK809 Sasha Levin
2024-11-12 10:37 ` [PATCH AUTOSEL 5.10 3/6] can: j1939: fix error in J1939 documentation Sasha Levin
2024-12-02 11:59 ` Pavel Machek
2024-11-12 10:37 ` [PATCH AUTOSEL 5.10 4/6] ASoC: stm: Prevent potential division by zero in stm32_sai_mclk_round_rate() Sasha Levin
2024-12-02 12:01 ` Pavel Machek
2024-11-12 10:38 ` [PATCH AUTOSEL 5.10 5/6] ASoC: stm: Prevent potential division by zero in stm32_sai_get_clk_div() Sasha Levin
2024-11-12 10:38 ` [PATCH AUTOSEL 5.10 6/6] proc/softirqs: replace seq_printf with seq_put_decimal_ull_width Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241112103803.1654174-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andersson@kernel.org \
--cc=hanchunchao@inspur.com \
--cc=konradybcio@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox