i2c: i2c-sh_mobile irq rollback fix
authorMagnus Damm <damm@opensource.se>
Mon, 2 Aug 2010 07:16:37 +0000 (07:16 +0000)
committerPaul Mundt <lethal@linux-sh.org>
Wed, 4 Aug 2010 07:10:34 +0000 (16:10 +0900)
Update the i2c-sh_mobile driver to properly free
interrupts. The function sh_mobile_i2c_hook_irqs()
is fixed so module both unload and load are working
as expected.

Signed-off-by: Magnus Damm <damm@opensource.se>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
drivers/i2c/busses/i2c-sh_mobile.c

index ffb405d7c6f24caaf61a9837e66de0b4f417d490..97b84b80d0ff325370a0ca3bfc9d9f569bc3d267 100644 (file)
@@ -497,15 +497,17 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
 {
        struct resource *res;
        int ret = -ENXIO;
-       int q, m;
-       int k = 0;
-       int n = 0;
+       int n, k = 0;
 
        while ((res = platform_get_resource(dev, IORESOURCE_IRQ, k))) {
                for (n = res->start; hook && n <= res->end; n++) {
                        if (request_irq(n, sh_mobile_i2c_isr, IRQF_DISABLED,
-                                       dev_name(&dev->dev), dev))
+                                       dev_name(&dev->dev), dev)) {
+                               for (n--; n >= res->start; n--)
+                                       free_irq(n, dev);
+
                                goto rollback;
+                       }
                }
                k++;
        }
@@ -513,16 +515,17 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
        if (hook)
                return k > 0 ? 0 : -ENOENT;
 
-       k--;
        ret = 0;
 
  rollback:
-       for (q = k; k >= 0; k--) {
-               for (m = n; m >= res->start; m--)
-                       free_irq(m, dev);
+       k--;
+
+       while (k >= 0) {
+               res = platform_get_resource(dev, IORESOURCE_IRQ, k);
+               for (n = res->start; n <= res->end; n++)
+                       free_irq(n, dev);
 
-               res = platform_get_resource(dev, IORESOURCE_IRQ, k - 1);
-               m = res->end;
+               k--;
        }
 
        return ret;