From: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
To: Suraj Sonawane <surajsonawane0215@gmail.com>
Cc: broonie@kernel.org, daniel.baluta@nxp.com,
kai.vehmanen@linux.intel.com, lgirdwood@gmail.com,
linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org,
perex@perex.cz, pierre-louis.bossart@linux.dev,
ranjani.sridharan@linux.intel.com,
sound-open-firmware@alsa-project.org, tiwai@suse.com,
yung-chuan.liao@linux.intel.com
Subject: Re: [PATCH v2] sound: fix uninit-value in sof_ipc4_pcm_dai_link_fixup_rate
Date: Mon, 4 Nov 2024 12:52:09 +0200 [thread overview]
Message-ID: <09d8462d-d305-4b83-ade9-747a88aedc38@linux.intel.com> (raw)
In-Reply-To: <20241103113702.27673-1-surajsonawane0215@gmail.com>
On 03/11/2024 13:37, Suraj Sonawane wrote:
> Fix an issue detected by the Smatch tool:
>
> sound/soc/sof/ipc4-pcm.c: sof_ipc4_pcm_dai_link_fixup_rate()
> error: uninitialized symbol 'be_rate'.
>
> This issue occurred because the variable 'be_rate' could remain
> uninitialized if num_input_formats is zero. In such cases, the
> loop that assigns a value to 'be_rate' would not execute,
> potentially leading to undefined behavior when rate->min and
> rate->max are set with an uninitialized 'be_rate'.
>
> To resolve this, an additional check for num_input_formats > 0
> was added before setting rate->min and rate->max with 'be_rate'.
> This ensures that 'be_rate' is assigned only when there are valid
> input formats, preventing any use of uninitialized data.
>
> This solution maintains defined behavior for rate->min and rate->max,
> ensuring they are only assigned when valid be_rate data is available.
>
> Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
> ---
> V1: Initialize 'be_rate' to 0.
> V2: Add conditional assignment based on num_input_formats to ensure
> be_rate is used only when assigned.
>
> sound/soc/sof/ipc4-pcm.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/sound/soc/sof/ipc4-pcm.c b/sound/soc/sof/ipc4-pcm.c
> index 4df2be3d3..d5d7ffc69 100644
> --- a/sound/soc/sof/ipc4-pcm.c
> +++ b/sound/soc/sof/ipc4-pcm.c
> @@ -633,8 +633,11 @@ static int sof_ipc4_pcm_dai_link_fixup_rate(struct snd_sof_dev *sdev,
> return -EINVAL;
> }
>
> - rate->min = be_rate;
> - rate->max = rate->min;
> + /* Set rate only if be_rate was assigned */
> + if (num_input_formats > 0) {
By definition the copier must have at least one input and one output
format, this check is going to be always true.
> + rate->min = be_rate;
> + rate->max = rate->min;
> + }
> }
>
> return 0;
--
Péter
next prev parent reply other threads:[~2024-11-04 10:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=09d8462d-d305-4b83-ade9-747a88aedc38@linux.intel.com \
--to=peter.ujfalusi@linux.intel.com \
--cc=broonie@kernel.org \
--cc=daniel.baluta@nxp.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=pierre-louis.bossart@linux.dev \
--cc=ranjani.sridharan@linux.intel.com \
--cc=sound-open-firmware@alsa-project.org \
--cc=surajsonawane0215@gmail.com \
--cc=tiwai@suse.com \
--cc=yung-chuan.liao@linux.intel.com \
/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