[alsa-devel] [PATCH] ASoC: max98357a: release GPIO when component removing

Tzung-Bi Shih tzungbi at google.com
Wed May 8 11:27:35 CEST 2019


> On Tue, May 07, 2019 at 01:11:40PM +0800, Tzung-Bi Shih wrote:
>
> > +static void max98357a_component_remove(struct snd_soc_component *component)
> > +{
> > +     struct max98357a_priv *max98357a =
> > +                     snd_soc_component_get_drvdata(component);
> > +
> > +     if (max98357a->sdmode)
> > +             devm_gpiod_put(component->dev, max98357a->sdmode);
> > +}
>
> This is an obvious mess, if you're explicitly freeing devm_ allocated
> resources in the common case something is going wrong.  Just move the
> initial allocation to the device level probe so devm can do what it's
> supposed to.

Move the GPIO allocation to max98357a_platform_probe() should work but
I am wondering the difference between device's probe() and component's
probe().  What do we expect to do in component's probe()?
As component's probe() is later than device's, I thought we tend to
put resource allocation in component's probe() for reasons:
- to speed up the booting *maybe* a little
- to allocate resources when really need them

I am using devm_gpiod_put() instead of gpiod_put() so that I suppose
devm_ should take care of the rest of cleanup.  Do you think this is
still a mess?


More information about the Alsa-devel mailing list