diff mbox series

sound: fix uninit-value in sof_ipc4_pcm_dai_link_fixup_rate

Message ID 20241030155705.31327-1-surajsonawane0215@gmail.com (mailing list archive)
State Superseded
Headers show
Series sound: fix uninit-value in sof_ipc4_pcm_dai_link_fixup_rate | expand

Commit Message

Suraj Sonawane Oct. 30, 2024, 3:57 p.m. UTC
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(-)

Comments

Mark Brown Oct. 30, 2024, 5:10 p.m. UTC | #1
On Wed, Oct 30, 2024 at 09:27:05PM +0530, Suraj Sonawane wrote:
> Fix an issue detected by the Smatch tool:

Please submit patches using subject lines reflecting the style for the
subsystem, this makes it easier for people to identify relevant patches.
Look at what existing commits in the area you're changing are doing and
make sure your subject lines visually resemble what they're doing.
There's no need to resubmit to fix this alone.
Mark Brown Oct. 30, 2024, 5:17 p.m. UTC | #2
On Wed, Oct 30, 2024 at 09:27:05PM +0530, Suraj Sonawane wrote:

> 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.

Again, this shuts the warning up but is this actually a good fix?
Suraj Sonawane Oct. 31, 2024, 6:02 a.m. UTC | #3
On 30/10/24 22:40, Mark Brown wrote:
> Please submit patches using subject lines reflecting the style for the
> subsystem, this makes it easier for people to identify relevant patches.
> Look at what existing commits in the area you're changing are doing and
> make sure your subject lines visually resemble what they're doing.
> There's no need to resubmit to fix this alone.
Thank you for the guidance! I’ll make sure to follow the subsystem’s 
subject line style in future submissions.
diff mbox series

Patch

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;
 
 	/*