Message ID | 1519326142-26421-1-git-send-email-festevam@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | f91b1e73ccde71d4bc69ae10d475196df38844ab |
Headers | show |
On 02/22/2018 08:02 PM, Fabio Estevam wrote: > From: Fabio Estevam <fabio.estevam@nxp.com> > > When dmaengine_pcm_request_chan_of() fails it should release > the previously acquired resources, which in this case is to > call kfree(pcm), so jump to the correct point in the error > path. > > Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com> This creates a resource leak. dmaengine_pcm_request_chan_of() requests both transmit and receive channels. It might return with an error if one of them fails, but the other one succeeded. In this case we need to call dmaengine_pcm_release_chan() to free the requested channel. > --- > sound/soc/soc-generic-dmaengine-pcm.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c > index 768247f..32ea16d 100644 > --- a/sound/soc/soc-generic-dmaengine-pcm.c > +++ b/sound/soc/soc-generic-dmaengine-pcm.c > @@ -450,7 +450,7 @@ int snd_dmaengine_pcm_register(struct device *dev, > > ret = dmaengine_pcm_request_chan_of(pcm, dev, config); > if (ret) > - goto err_free_dma; > + goto err_free_pcm; > > ret = snd_soc_add_component(dev, &pcm->component, > &dmaengine_pcm_component, NULL, 0); > @@ -461,6 +461,7 @@ int snd_dmaengine_pcm_register(struct device *dev, > > err_free_dma: > dmaengine_pcm_release_chan(pcm); > +err_free_pcm: > kfree(pcm); > return ret; > } >
On Mon, Feb 26, 2018 at 11:25 AM, Lars-Peter Clausen <lars@metafoo.de> wrote: > This creates a resource leak. dmaengine_pcm_request_chan_of() requests both > transmit and receive channels. It might return with an error if one of them > fails, but the other one succeeded. In this case we need to call > dmaengine_pcm_release_chan() to free the requested channel. Ok, I will send a revert.
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c index 768247f..32ea16d 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -450,7 +450,7 @@ int snd_dmaengine_pcm_register(struct device *dev, ret = dmaengine_pcm_request_chan_of(pcm, dev, config); if (ret) - goto err_free_dma; + goto err_free_pcm; ret = snd_soc_add_component(dev, &pcm->component, &dmaengine_pcm_component, NULL, 0); @@ -461,6 +461,7 @@ int snd_dmaengine_pcm_register(struct device *dev, err_free_dma: dmaengine_pcm_release_chan(pcm); +err_free_pcm: kfree(pcm); return ret; }