Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: "Lopez Cruz, Misael" <x0052729@ti.com>
Cc: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	Mark Brown <broonie@sirena.org.uk>
Subject: Re: [PATCH] ASoC: Add GPIO support for jack reporting	interface
Date: Tue, 03 Mar 2009 07:41:16 +0100	[thread overview]
Message-ID: <s5h63irp0qb.wl%tiwai@suse.de> (raw)
In-Reply-To: <2C7D3DF36ADFFC479B44490D912B616705ECD6D7C1@dlee07.ent.ti.com>

At Mon, 2 Mar 2009 19:05:28 -0600,
Lopez Cruz, Misael wrote:
> 
> Add GPIO support to jack reporting framework in ASoC using gpiolib calls.
> The gpio support exports two new functions: snd_soc_jack_add_gpios and
> snd_soc_jack_free_gpios.
> 
> Client drivers using gpio feature must pass an array of jack_gpio pins
> belonging to a specific jack to the snd_soc_jack_add_gpios function. The
> framework will request the gpio, set the data direction and request irq.
> The framework will update power status of related jack_pins when an event on
> the gpio pins comes according to the reporting bits defined for each gpio.
> 
> All gpio resources allocated when adding jack_gpio pins for a particular
> jack can be released using snd_soc_jack_free_gpios function.
> 
> Signed-off-by: Misael Lopez Cruz <x0052729@ti.com>

I prefer GPIO stuff built in conditionally.
The jack layer is used also for non-ASoC codes, and GPIO isn't always
present.

> +/* irq handler for gpio pin */
> +static irqreturn_t gpio_handler(int irq, void *data)
> +{
> +	struct snd_soc_jack_gpio *gpio = data;
> +
> +	return IRQ_RETVAL(schedule_work(&gpio->work));

Is this really correct?

> +int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
> +			struct snd_soc_jack_gpio *gpios)
> +{
> +	int i, ret = 0;
> +
> +	/* Link gpio array with the soc_jack */
> +	if (count > 0)
> +		jack->gpios = gpios;
> +
> +	for (i = 0; i < count; i++) {
> +		if (!gpio_is_valid(gpios[i].gpio)) {
> +			printk(KERN_ERR "Invalid gpio %d\n",
> +				gpios[i].gpio);
> +			return -EINVAL;
> +		}
> +		if (!gpios[i].name) {
> +			printk(KERN_ERR "No name for gpio %d\n",
> +				gpios[i].gpio);
> +			return -EINVAL;
> +		}
> +
> +		ret = gpio_request(gpios[i].gpio, gpios[i].name);
> +		if (ret)
> +			return ret;
> +
> +		ret = gpio_direction_input(gpios[i].gpio);
> +		if (ret)
> +			break;
> +
> +		ret = request_irq(gpio_to_irq(gpios[i].gpio),
> +				gpio_handler,
> +				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
> +				jack->card->dev->driver->name,
> +				&gpios[i]);
> +		if (ret)
> +			break;
> +
> +		INIT_WORK(&gpios[i].work, gpio_work);
> +		gpios[i].jack = jack;
> +	}
> +
> +	if (ret)
> +		gpio_free(gpios[i].gpio);

This error path doesn't look good.  It seems leaking / keeping some
resources.


thanks,

Takashi

  reply	other threads:[~2009-03-03  6:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-03  1:05 [PATCH] ASoC: Add GPIO support for jack reporting interface Lopez Cruz, Misael
2009-03-03  6:41 ` Takashi Iwai [this message]
2009-03-03 11:16   ` Mark Brown
2009-03-03 11:23     ` Takashi Iwai
2009-03-03 18:39   ` Lopez Cruz, Misael
2009-03-03 18:42     ` Mark Brown
2009-03-03 18:54       ` Lopez Cruz, Misael
2009-03-03 11:14 ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2009-03-03 21:25 Lopez Cruz, Misael
2009-03-04 14:43 ` Mark Brown
2009-03-04 14:52   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5h63irp0qb.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@sirena.org.uk \
    --cc=x0052729@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox