firmware: imx-dsp: Fix an error handling path in imx_dsp_setup_channels()

Message ID 2b4bc0b22fac32ab3a7262240019486804c1691f.1673806409.git.christophe.jaillet@wanadoo.fr
State New
Headers
Series firmware: imx-dsp: Fix an error handling path in imx_dsp_setup_channels() |

Commit Message

Christophe JAILLET Jan. 15, 2023, 6:13 p.m. UTC
  If mbox_request_channel_byname() fails, the memory allocated a few lines
above still need to be freed before going to the error handling path.

Fixes: 046326989a18 ("firmware: imx: Save channel name for further use")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
The Fixes tag is not really accurate, the issue was already there before,
with other emory leaks.
However, I think that the Fixes tag above is much more logical.

Feel free to update!
---
 drivers/firmware/imx/imx-dsp.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Daniel Baluta Jan. 17, 2023, 7:55 a.m. UTC | #1
On Sun, Jan 15, 2023 at 8:35 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> If mbox_request_channel_byname() fails, the memory allocated a few lines
> above still need to be freed before going to the error handling path.
>
> Fixes: 046326989a18 ("firmware: imx: Save channel name for further use")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Good catch.

Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
  
Shawn Guo Sept. 19, 2023, 12:13 p.m. UTC | #2
On Sun, Aug 20, 2023 at 08:26:01AM +0200, Christophe JAILLET wrote:
> Le 17/01/2023 à 08:55, Daniel Baluta a écrit :
> > On Sun, Jan 15, 2023 at 8:35 PM Christophe JAILLET
> > <christophe.jaillet@wanadoo.fr> wrote:
> > > 
> > > If mbox_request_channel_byname() fails, the memory allocated a few lines
> > > above still need to be freed before going to the error handling path.
> > > 
> > > Fixes: 046326989a18 ("firmware: imx: Save channel name for further use")
> > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > 
> > Good catch.
> > 
> > Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
> > 
> 
> Hi,
> 
> polite reminder.
> 
> This patch is still not in -next.

Sorry, not sure how this fell from the crack.

Applied, thanks!
  

Patch

diff --git a/drivers/firmware/imx/imx-dsp.c b/drivers/firmware/imx/imx-dsp.c
index a6c06d7476c3..1f410809d3ee 100644
--- a/drivers/firmware/imx/imx-dsp.c
+++ b/drivers/firmware/imx/imx-dsp.c
@@ -115,6 +115,7 @@  static int imx_dsp_setup_channels(struct imx_dsp_ipc *dsp_ipc)
 		dsp_chan->idx = i % 2;
 		dsp_chan->ch = mbox_request_channel_byname(cl, chan_name);
 		if (IS_ERR(dsp_chan->ch)) {
+			kfree(dsp_chan->name);
 			ret = PTR_ERR(dsp_chan->ch);
 			if (ret != -EPROBE_DEFER)
 				dev_err(dev, "Failed to request mbox chan %s ret %d\n",