Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] sound: fix uninit-value in sof_ipc4_pcm_dai_link_fixup_rate
@ 2024-10-30 15:57 Suraj Sonawane
  2024-10-30 17:10 ` Mark Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Suraj Sonawane @ 2024-10-30 15:57 UTC (permalink / raw)
  To: lgirdwood, peter.ujfalusi, yung-chuan.liao, ranjani.sridharan,
	daniel.baluta, kai.vehmanen, pierre-louis.bossart, broonie, perex,
	tiwai
  Cc: sound-open-firmware, linux-sound, linux-kernel, Suraj Sonawane

Fix an issue detected by the Smatch tool:

sound/soc/sof/ipc4-pcm.c:615 sof_ipc4_pcm_dai_link_fixup_rate()
error: uninitialized symbol 'be_rate'.
sound/soc/sof/ipc4-pcm.c:636 sof_ipc4_pcm_dai_link_fixup_rate()
error: uninitialized symbol 'be_rate'.

These errors occurred because the variable 'be_rate' is declared but
may not be assigned a value before it is used. Specifically, if the
loop that assigns values to 'be_rate' does not execute (for example,
when 'num_input_formats' is zero), 'be_rate' remains uninitialized,
leading to potential undefined behavior.

To resolve this issue, initialize 'be_rate' to 0 at the point of
declaration. This ensures that 'be_rate' has a defined value before
it is used in subsequent calculations, preventing any warnings or
undefined behavior in cases where the loop does not run.

Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
---
 sound/soc/sof/ipc4-pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/sof/ipc4-pcm.c b/sound/soc/sof/ipc4-pcm.c
index 4df2be3d3..d08419859 100644
--- a/sound/soc/sof/ipc4-pcm.c
+++ b/sound/soc/sof/ipc4-pcm.c
@@ -600,7 +600,7 @@ static int sof_ipc4_pcm_dai_link_fixup_rate(struct snd_sof_dev *sdev,
 	unsigned int fe_rate = params_rate(params);
 	bool fe_be_rate_match = false;
 	bool single_be_rate = true;
-	unsigned int be_rate;
+	unsigned int be_rate = 0;
 	int i;
 
 	/*
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-11-06  8:34 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-30 15:57 [PATCH] sound: fix uninit-value in sof_ipc4_pcm_dai_link_fixup_rate Suraj Sonawane
2024-10-30 17:10 ` Mark Brown
2024-10-31  6:02   ` Suraj Sonawane
2024-10-30 17:17 ` Mark Brown
2024-11-03 11:37 ` [PATCH v2] " Suraj Sonawane
2024-11-04 10:52   ` Péter Ujfalusi
2024-11-04 18:27     ` Mark Brown
2024-11-05 10:50       ` Suraj Sonawane
2024-11-05 19:07         ` Mark Brown
2024-11-06  8:34           ` Suraj Sonawane
2024-11-05 10:48     ` Suraj Sonawane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox