[PATCH linux-next-2.6] gpio/ml_ioh_gpio: fix resource leak issue
From: Tomoya MORINAGA
Date: Wed Jan 05 2011 - 04:02:25 EST
(1) add gpiochip_remove processing in case gpiochip_add fails.
(2) for easy to read, move variable initialization to out of for-condition.
Reported-by: Andrew Morton. <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Tomoya MORINAGA <tomoya-linux@xxxxxxxxxxxxxxx>
---
drivers/gpio/ml_ioh_gpio.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/drivers/gpio/ml_ioh_gpio.c b/drivers/gpio/ml_ioh_gpio.c
index 4fa3224..cead8e6 100644
--- a/drivers/gpio/ml_ioh_gpio.c
+++ b/drivers/gpio/ml_ioh_gpio.c
@@ -208,7 +208,8 @@ static int __devinit ioh_gpio_probe(struct pci_dev *pdev,
goto err_kzalloc;
}
- for (i = 0, chip = chip_save; i < 8; i++, chip++) {
+ chip = chip_save;
+ for (i = 0; i < 8; i++, chip++) {
chip->dev = &pdev->dev;
chip->base = base;
chip->reg = chip->base;
@@ -228,6 +229,12 @@ static int __devinit ioh_gpio_probe(struct pci_dev *pdev,
return 0;
err_gpiochip_add:
+ for (; i != 0; i--) {
+ chip--;
+ ret = gpiochip_remove(&chip->gpio);
+ if (ret)
+ dev_err(&pdev->dev, "Failed gpiochip_remove(%d)\n", i);
+ }
kfree(chip_save);
err_kzalloc:
--
1.6.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/