From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Markus Elfring <Markus.Elfring@web.de>,
kernel-janitors@vger.kernel.org, alsa-devel@alsa-project.org,
sound-open-firmware@alsa-project.org,
Bard Liao <yung-chuan.liao@linux.intel.com>,
Daniel Baluta <daniel.baluta@nxp.com>,
Jaroslav Kysela <perex@perex.cz>,
Kai Vehmanen <kai.vehmanen@linux.intel.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
Rander Wang <rander.wang@intel.com>,
Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
Takashi Iwai <tiwai@suse.com>
Cc: cocci@inria.fr, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ASoC: SOF: Intel: hda-stream: Move three variable assignments behind condition checks in hda_dsp_iccmax_stream_hw_params()
Date: Wed, 19 Apr 2023 14:03:18 -0500 [thread overview]
Message-ID: <fbdee94e-b731-0471-e18f-b334ab0db7f5@linux.intel.com> (raw)
In-Reply-To: <c18331ca-3de9-d433-f477-b04103958b9c@web.de>
On 4/19/23 13:54, Markus Elfring wrote:
> Date: Wed, 19 Apr 2023 20:42:19 +0200
>
> The address of a data structure member was determined before
> a corresponding null pointer check in the implementation of
> the function “hda_dsp_iccmax_stream_hw_params”.
>
> Thus avoid the risk for undefined behaviour by moving the assignment
> for three local variables behind some condition checks.
>
> This issue was detected by using the Coccinelle software.
>
> Fixes: 7d88b9608142f95ccdd3dfb190da4a5faddb1cc7 ("ASoC: SOF: Intel: hdac_ext_stream: consistent prefixes for variables/members")
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Yes indeed, for some reason this was fixed in
hda_dsp_stream_hw_params() but not in the
hda_dsp_iccmax_stream_hw_params() variant.
Could we however use the same code as in hda_dsp_stream_hw_params() for
consistency?
if (!hext_stream) {
dev_err(sdev->dev, "error: no stream available\n");
return -ENODEV;
}
if (!dmab) {
dev_err(sdev->dev, "error: no dma buffer allocated!\n");
return -ENODEV;
}
hstream = &hext_stream->hstream;
sd_offset = SOF_STREAM_SD_OFFSET(hstream);
mask = BIT(hstream->index);
Thanks!
> ---
> sound/soc/sof/intel/hda-stream.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/sound/soc/sof/intel/hda-stream.c b/sound/soc/sof/intel/hda-stream.c
> index 79d818e6a0fa..9c44127014fc 100644
> --- a/sound/soc/sof/intel/hda-stream.c
> +++ b/sound/soc/sof/intel/hda-stream.c
> @@ -407,10 +407,10 @@ int hda_dsp_iccmax_stream_hw_params(struct snd_sof_dev *sdev, struct hdac_ext_st
> struct snd_dma_buffer *dmab,
> struct snd_pcm_hw_params *params)
> {
> - struct hdac_stream *hstream = &hext_stream->hstream;
> - int sd_offset = SOF_STREAM_SD_OFFSET(hstream);
> + struct hdac_stream *hstream;
> + int sd_offset;
> int ret;
> - u32 mask = 0x1 << hstream->index;
> + u32 mask;
>
> if (!hext_stream) {
> dev_err(sdev->dev, "error: no stream available\n");
> @@ -422,9 +422,12 @@ int hda_dsp_iccmax_stream_hw_params(struct snd_sof_dev *sdev, struct hdac_ext_st
> return -ENODEV;
> }
>
> + hstream = &hext_stream->hstream;
> if (hstream->posbuf)
> *hstream->posbuf = 0;
>
> + sd_offset = SOF_STREAM_SD_OFFSET(hstream);
> +
> /* reset BDL address */
> snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR,
> sd_offset + SOF_HDA_ADSP_REG_SD_BDLPL,
> @@ -459,6 +462,8 @@ int hda_dsp_iccmax_stream_hw_params(struct snd_sof_dev *sdev, struct hdac_ext_st
> sd_offset + SOF_HDA_ADSP_REG_SD_LVI,
> 0xffff, (hstream->frags - 1));
>
> + mask = 0x1 << hstream->index;
> +
> /* decouple host and link DMA, enable DSP features */
> snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
> mask, mask);
> --
> 2.40.0
>
next prev parent reply other threads:[~2023-04-19 19:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <40c60719-4bfe-b1a4-ead7-724b84637f55@web.de>
[not found] ` <1a11455f-ab57-dce0-1677-6beb8492a257@web.de>
2023-04-13 12:10 ` [PATCH] ASoC: SOF: topology: Move a variable assignment behind condition checks in sof_dai_load() Markus Elfring
2023-04-19 18:54 ` [PATCH] ASoC: SOF: Intel: hda-stream: Move three variable assignments behind condition checks in hda_dsp_iccmax_stream_hw_params() Markus Elfring
2023-04-19 19:03 ` Pierre-Louis Bossart [this message]
2023-04-24 14:56 ` Markus Elfring
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=fbdee94e-b731-0471-e18f-b334ab0db7f5@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=Markus.Elfring@web.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=cocci@inria.fr \
--cc=daniel.baluta@nxp.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=rander.wang@intel.com \
--cc=ranjani.sridharan@linux.intel.com \
--cc=sound-open-firmware@alsa-project.org \
--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