[PATCH] sound: fix uninit-value in sof_ipc4_pcm_dai_link_fixup_rate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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@xxxxxxxxx>
---
 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





[Index of Archives]     [Pulseaudio]     [Linux Audio Users]     [ALSA Devel]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux