* [PATCH] ASoC: sma1307: Add NULL check in sma1307_setting_loaded()
@ 2025-03-11 1:57 Chenyuan Yang
2025-03-17 10:17 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Chenyuan Yang @ 2025-03-11 1:57 UTC (permalink / raw)
To: kiseok.jo, lgirdwood, broonie, perex, tiwai
Cc: linux-sound, linux-kernel, Chenyuan Yang
All varibale allocated by kzalloc and devm_kzalloc could be NULL.
Multiple pointer checks and their cleanup are added.
This issue is found by our static analysis tool
Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
---
sound/soc/codecs/sma1307.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/sound/soc/codecs/sma1307.c b/sound/soc/codecs/sma1307.c
index 480bcea48541..b9d8136fe3dc 100644
--- a/sound/soc/codecs/sma1307.c
+++ b/sound/soc/codecs/sma1307.c
@@ -1728,6 +1728,11 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
}
data = kzalloc(fw->size, GFP_KERNEL);
+ if (!data) {
+ release_firmware(fw);
+ sma1307->set.status = false;
+ return;
+ }
size = fw->size >> 2;
memcpy(data, fw->data, fw->size);
@@ -1741,6 +1746,12 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
sma1307->set.header = devm_kzalloc(sma1307->dev,
sma1307->set.header_size,
GFP_KERNEL);
+ if (!sma1307->set.header) {
+ kfree(data);
+ sma1307->set.status = false;
+ return;
+ }
+
memcpy(sma1307->set.header, data,
sma1307->set.header_size * sizeof(int));
@@ -1756,6 +1767,13 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
sma1307->set.def
= devm_kzalloc(sma1307->dev,
sma1307->set.def_size * sizeof(int), GFP_KERNEL);
+ if (!sma1307->set.def) {
+ kfree(data);
+ kfree(sma1307->set.header);
+ sma1307->set.status = false;
+ return;
+ }
+
memcpy(sma1307->set.def,
&data[sma1307->set.header_size],
sma1307->set.def_size * sizeof(int));
@@ -1768,6 +1786,16 @@ static void sma1307_setting_loaded(struct sma1307_priv *sma1307, const char *fil
= devm_kzalloc(sma1307->dev,
sma1307->set.mode_size * 2 * sizeof(int),
GFP_KERNEL);
+ if (!sma1307->set.mode_set[i]) {
+ kfree(data);
+ kfree(sma1307->set.header);
+ kfree(sma1307->set.def);
+ for (int j = 0; j < i; j++)
+ kfree(sma1307->set.mode_set[j]);
+ sma1307->set.status = false;
+ return;
+ }
+
for (int j = 0; j < sma1307->set.mode_size; j++) {
sma1307->set.mode_set[i][2 * j]
= data[offset + ((num_mode + 1) * j)];
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ASoC: sma1307: Add NULL check in sma1307_setting_loaded()
2025-03-11 1:57 [PATCH] ASoC: sma1307: Add NULL check in sma1307_setting_loaded() Chenyuan Yang
@ 2025-03-17 10:17 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2025-03-17 10:17 UTC (permalink / raw)
To: kiseok.jo, lgirdwood, perex, tiwai, Chenyuan Yang
Cc: linux-sound, linux-kernel
On Mon, 10 Mar 2025 20:57:14 -0500, Chenyuan Yang wrote:
> All varibale allocated by kzalloc and devm_kzalloc could be NULL.
> Multiple pointer checks and their cleanup are added.
>
> This issue is found by our static analysis tool
>
>
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: sma1307: Add NULL check in sma1307_setting_loaded()
commit: 0ec6bd16705fe21d6429d6b8f7981eae2142bba8
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-17 10:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-11 1:57 [PATCH] ASoC: sma1307: Add NULL check in sma1307_setting_loaded() Chenyuan Yang
2025-03-17 10:17 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®