[PATCH 2/2] ASoC: topology: Fix a small leak in soc_tplg_dapm_graph_elems_load()

Dan Carpenter dan.carpenter at oracle.com
Thu May 20 10:08:40 CEST 2021


On Thu, May 20, 2021 at 09:54:42AM +0200, Amadeusz Sławiński wrote:
> On 5/20/2021 7:07 AM, Dan Carpenter wrote:
> > We have to kfree(routes) on this error path.
> > 
> > Fixes: ff9226224437 ("ASoC: topology: Change allocations to resource managed")
> > Signed-off-by: Dan Carpenter <dan.carpenter at oracle.com>
> > ---
> >   sound/soc/soc-topology.c | 7 +++++--
> >   1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
> > index 6b7a813bc264..5730fcaa7bc6 100644
> > --- a/sound/soc/soc-topology.c
> > +++ b/sound/soc/soc-topology.c
> > @@ -1135,8 +1135,10 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
> >   	 */
> >   	for (i = 0; i < count; i++) {
> >   		routes[i] = devm_kzalloc(tplg->dev, sizeof(*routes[i]), GFP_KERNEL);
> > -		if (!routes[i])
> > -			return -ENOMEM;
> > +		if (!routes[i]) {
> > +			ret = -ENOMEM;
> > +			goto free_routes;
> > +		}
> >   	}
> >   	for (i = 0; i < count; i++) {
> > @@ -1198,6 +1200,7 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
> >   	 * The memory allocated for each dapm route will be freed
> >   	 * when it is removed in remove_route().
> >   	 */
> > +free_routes:
> >   	kfree(routes);
> >   	return ret;
> > 
> 
> Yes, that's right, however looking at this function again, I wonder if
> instead we can just get rid of the routes array and kcalloc call?
> 
> Something along those lines (hope that copy paste won't mess it up):
> 

It did mess it up but I got the idea.  Yeah, that's way better.

regards,
dan carpenter



More information about the Alsa-devel mailing list