* [PATCH] ALSA: hda/ca0132: fix potential memory leak in dspxfr_image()
@ 2022-06-29 17:16 Jianglei Nie
0 siblings, 0 replies; 4+ messages in thread
From: Jianglei Nie @ 2022-06-29 17:16 UTC (permalink / raw)
To: perex, tiwai, colin.king; +Cc: alsa-devel, linux-kernel, Jianglei Nie
dspxfr_image() allocates DSP ports for the download stream with
dsp_allocate_ports_format(). When some error occurs, the allocated
DSP ports are not released, which will lead to a memory leak.
We can fix it by releasing DSP ports with dsp_free_ports() if some
error occurs.
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
sound/pci/hda/patch_ca0132.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 208933792787..6b8f45e14075 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -3455,6 +3455,7 @@ static int dspxfr_image(struct hda_codec *codec,
&port_map_mask);
if (status < 0) {
codec_dbg(codec, "alloc ports fail\n");
+ dsp_free_ports(codec);
goto exit;
}
@@ -3463,6 +3464,7 @@ static int dspxfr_image(struct hda_codec *codec,
WIDGET_CHIP_CTRL, stream_id, 0, &response);
if (status < 0) {
codec_dbg(codec, "set stream chan fail\n");
+ dsp_free_ports(codec);
goto exit;
}
@@ -3470,6 +3472,7 @@ static int dspxfr_image(struct hda_codec *codec,
if (!is_valid(fls_data)) {
codec_dbg(codec, "FLS check fail\n");
status = -EINVAL;
+ dsp_free_ports(codec);
goto exit;
}
status = dspxfr_one_seg(codec, fls_data, reloc,
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ALSA: hda/ca0132: fix potential memory leak in dspxfr_image()
2022-09-07 6:59 Jianglei Nie
@ 2022-09-07 7:35 ` Takashi Iwai
0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2022-09-07 7:35 UTC (permalink / raw)
To: Jianglei Nie; +Cc: perex, tiwai, alsa-devel, linux-kernel
On Wed, 07 Sep 2022 08:59:17 +0200,
Jianglei Nie wrote:
>
> dspxfr_image() allocates DSP ports for the download stream with
> dsp_allocate_ports_format(). When gets some error, the allocated
> DSP ports are not released, which will lead to a memory leak.
Hmm, those allocate_* functions don't really allocate memories but
rather allocate virtual ports on the hardware; i.e. it just flips some
DSP registers. There should be no "memory leaks".
> We can fix it by releasing DSP ports with dsp_free_ports() when
> getting some error.
>
> Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
> ---
> sound/pci/hda/patch_ca0132.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
> index 208933792787..6b8f45e14075 100644
> --- a/sound/pci/hda/patch_ca0132.c
> +++ b/sound/pci/hda/patch_ca0132.c
> @@ -3455,6 +3455,7 @@ static int dspxfr_image(struct hda_codec *codec,
> &port_map_mask);
> if (status < 0) {
> codec_dbg(codec, "alloc ports fail\n");
> + dsp_free_ports(codec);
This is likely superfluous. When an allocation fails, you don't free,
in general.
thanks,
Takashi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ALSA: hda/ca0132: fix potential memory leak in dspxfr_image()
@ 2022-09-07 7:35 ` Takashi Iwai
0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2022-09-07 7:35 UTC (permalink / raw)
To: Jianglei Nie; +Cc: linux-kernel, alsa-devel, tiwai
On Wed, 07 Sep 2022 08:59:17 +0200,
Jianglei Nie wrote:
>
> dspxfr_image() allocates DSP ports for the download stream with
> dsp_allocate_ports_format(). When gets some error, the allocated
> DSP ports are not released, which will lead to a memory leak.
Hmm, those allocate_* functions don't really allocate memories but
rather allocate virtual ports on the hardware; i.e. it just flips some
DSP registers. There should be no "memory leaks".
> We can fix it by releasing DSP ports with dsp_free_ports() when
> getting some error.
>
> Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
> ---
> sound/pci/hda/patch_ca0132.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
> index 208933792787..6b8f45e14075 100644
> --- a/sound/pci/hda/patch_ca0132.c
> +++ b/sound/pci/hda/patch_ca0132.c
> @@ -3455,6 +3455,7 @@ static int dspxfr_image(struct hda_codec *codec,
> &port_map_mask);
> if (status < 0) {
> codec_dbg(codec, "alloc ports fail\n");
> + dsp_free_ports(codec);
This is likely superfluous. When an allocation fails, you don't free,
in general.
thanks,
Takashi
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] ALSA: hda/ca0132: fix potential memory leak in dspxfr_image()
@ 2022-09-07 6:59 Jianglei Nie
2022-09-07 7:35 ` Takashi Iwai
0 siblings, 1 reply; 4+ messages in thread
From: Jianglei Nie @ 2022-09-07 6:59 UTC (permalink / raw)
To: perex, tiwai; +Cc: alsa-devel, linux-kernel, Jianglei Nie
dspxfr_image() allocates DSP ports for the download stream with
dsp_allocate_ports_format(). When gets some error, the allocated
DSP ports are not released, which will lead to a memory leak.
We can fix it by releasing DSP ports with dsp_free_ports() when
getting some error.
Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
sound/pci/hda/patch_ca0132.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 208933792787..6b8f45e14075 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -3455,6 +3455,7 @@ static int dspxfr_image(struct hda_codec *codec,
&port_map_mask);
if (status < 0) {
codec_dbg(codec, "alloc ports fail\n");
+ dsp_free_ports(codec);
goto exit;
}
@@ -3463,6 +3464,7 @@ static int dspxfr_image(struct hda_codec *codec,
WIDGET_CHIP_CTRL, stream_id, 0, &response);
if (status < 0) {
codec_dbg(codec, "set stream chan fail\n");
+ dsp_free_ports(codec);
goto exit;
}
@@ -3470,6 +3472,7 @@ static int dspxfr_image(struct hda_codec *codec,
if (!is_valid(fls_data)) {
codec_dbg(codec, "FLS check fail\n");
status = -EINVAL;
+ dsp_free_ports(codec);
goto exit;
}
status = dspxfr_one_seg(codec, fls_data, reloc,
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-07 7:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 17:16 [PATCH] ALSA: hda/ca0132: fix potential memory leak in dspxfr_image() Jianglei Nie
2022-09-07 6:59 Jianglei Nie
2022-09-07 7:35 ` Takashi Iwai
2022-09-07 7:35 ` Takashi Iwai
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.