public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: H Hartley Sweeten <hartleys@visionengravers.com>
To: Linux Kernel <linux-kernel@vger.kernel.org>
Cc: <grant.likely@secretlab.ca>
Subject: gpio: pca953x: prevent freeing IRQ 0 on probe error
Date: Fri, 25 Mar 2011 15:02:54 -0700	[thread overview]
Message-ID: <201103251502.54348.hartleys@visionengravers.com> (raw)

If CONFIG_GPIO_PCA953X_IRQ is enabled and an error occurs in the probe
before pca953x_irq_setup() is called chip->client->irq will be 0 due to
the kmalloc.  pca953x_irq_teardown() will then try to free_irq(0, chip)
which will produce a:

	WARN(1, "Trying to free already-free IRQ %d\n", irq);

Add an error path to prevent this.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Grant Likely <grant.likely@secretlab.ca>

---

diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index 2fc25de..e1ff4d5 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -523,7 +523,7 @@ static int __devinit pca953x_probe(struct i2c_client *client,
 	if (pdata == NULL) {
 		dev_dbg(&client->dev, "no platform data\n");
 		ret = -EINVAL;
-		goto out_failed;
+		goto out_free;
 	}
 
 	chip->client = client;
@@ -541,20 +541,20 @@ static int __devinit pca953x_probe(struct i2c_client *client,
 
 	ret = pca953x_read_reg(chip, PCA953X_OUTPUT, &chip->reg_output);
 	if (ret)
-		goto out_failed;
+		goto out_free;
 
 	ret = pca953x_read_reg(chip, PCA953X_DIRECTION, &chip->reg_direction);
 	if (ret)
-		goto out_failed;
+		goto out_free;
 
 	/* set platform specific polarity inversion */
 	ret = pca953x_write_reg(chip, PCA953X_INVERT, pdata->invert);
 	if (ret)
-		goto out_failed;
+		goto out_free;
 
 	ret = pca953x_irq_setup(chip, id);
 	if (ret)
-		goto out_failed;
+		goto out_free;
 
 	ret = gpiochip_add(&chip->gpio_chip);
 	if (ret)
@@ -572,6 +572,7 @@ static int __devinit pca953x_probe(struct i2c_client *client,
 
 out_failed:
 	pca953x_irq_teardown(chip);
+out_free:
 	kfree(chip->dyn_pdata);
 	kfree(chip);
 	return ret;

             reply	other threads:[~2011-03-25 22:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-25 22:02 H Hartley Sweeten [this message]
2011-03-31 20:48 ` gpio: pca953x: prevent freeing IRQ 0 on probe error Grant Likely
2011-03-31 21:20   ` H Hartley Sweeten

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=201103251502.54348.hartleys@visionengravers.com \
    --to=hartleys@visionengravers.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    /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