[media] rc: Fix invalid free_region and/or free_irq on probe failure
authorBen Hutchings <ben@decadent.org.uk>
Tue, 15 May 2012 00:36:00 +0000 (21:36 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sun, 20 May 2012 14:43:05 +0000 (11:43 -0300)
fintek-cir, ite-cir and nuvoton-cir may try to free an I/O region
and/or IRQ handler that was never allocated after a failure in their
respective probe functions.  Add and use separate labels on the
failure path so they will do the right cleanup after each possible
point of failure.

Compile-tested only.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/rc/fintek-cir.c
drivers/media/rc/ite-cir.c
drivers/media/rc/nuvoton-cir.c

index 4a3a238bcfbc0d3eabbfbf66eec0d49fd66ecaa3..6aabf7ae3a31b79948f6afa5341284ce185f5ca9 100644 (file)
@@ -556,11 +556,11 @@ static int fintek_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id
 
        if (request_irq(fintek->cir_irq, fintek_cir_isr, IRQF_SHARED,
                        FINTEK_DRIVER_NAME, (void *)fintek))
-               goto failure;
+               goto failure2;
 
        ret = rc_register_device(rdev);
        if (ret)
-               goto failure;
+               goto failure3;
 
        device_init_wakeup(&pdev->dev, true);
        fintek->rdev = rdev;
@@ -570,12 +570,11 @@ static int fintek_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id
 
        return 0;
 
+failure3:
+       free_irq(fintek->cir_irq, fintek);
+failure2:
+       release_region(fintek->cir_addr, fintek->cir_port_len);
 failure:
-       if (fintek->cir_irq)
-               free_irq(fintek->cir_irq, fintek);
-       if (fintek->cir_addr)
-               release_region(fintek->cir_addr, fintek->cir_port_len);
-
        rc_free_device(rdev);
        kfree(fintek);
 
index 0e49c99abf68501c4558953058ae8d9b9df2ffa7..36fe5a349b95d34e0d9a2b427b891647bf7bf6fa 100644 (file)
@@ -1598,24 +1598,22 @@ static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id
 
        if (request_irq(itdev->cir_irq, ite_cir_isr, IRQF_SHARED,
                        ITE_DRIVER_NAME, (void *)itdev))
-               goto failure;
+               goto failure2;
 
        ret = rc_register_device(rdev);
        if (ret)
-               goto failure;
+               goto failure3;
 
        itdev->rdev = rdev;
        ite_pr(KERN_NOTICE, "driver has been successfully loaded\n");
 
        return 0;
 
+failure3:
+       free_irq(itdev->cir_irq, itdev);
+failure2:
+       release_region(itdev->cir_addr, itdev->params.io_region_size);
 failure:
-       if (itdev->cir_irq)
-               free_irq(itdev->cir_irq, itdev);
-
-       if (itdev->cir_addr)
-               release_region(itdev->cir_addr, itdev->params.io_region_size);
-
        rc_free_device(rdev);
        kfree(itdev);
 
index 8b2c071ac0ab67d86cfb1ea8120435e5df23406f..dc8a7dddccd458edb615e60b0c8eb0a242167779 100644 (file)
@@ -1075,19 +1075,19 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
 
        if (request_irq(nvt->cir_irq, nvt_cir_isr, IRQF_SHARED,
                        NVT_DRIVER_NAME, (void *)nvt))
-               goto failure;
+               goto failure2;
 
        if (!request_region(nvt->cir_wake_addr,
                            CIR_IOREG_LENGTH, NVT_DRIVER_NAME))
-               goto failure;
+               goto failure3;
 
        if (request_irq(nvt->cir_wake_irq, nvt_cir_wake_isr, IRQF_SHARED,
                        NVT_DRIVER_NAME, (void *)nvt))
-               goto failure;
+               goto failure4;
 
        ret = rc_register_device(rdev);
        if (ret)
-               goto failure;
+               goto failure5;
 
        device_init_wakeup(&pdev->dev, true);
        nvt->rdev = rdev;
@@ -1099,17 +1099,15 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
 
        return 0;
 
+failure5:
+       free_irq(nvt->cir_wake_irq, nvt);
+failure4:
+       release_region(nvt->cir_wake_addr, CIR_IOREG_LENGTH);
+failure3:
+       free_irq(nvt->cir_irq, nvt);
+failure2:
+       release_region(nvt->cir_addr, CIR_IOREG_LENGTH);
 failure:
-       if (nvt->cir_irq)
-               free_irq(nvt->cir_irq, nvt);
-       if (nvt->cir_addr)
-               release_region(nvt->cir_addr, CIR_IOREG_LENGTH);
-
-       if (nvt->cir_wake_irq)
-               free_irq(nvt->cir_wake_irq, nvt);
-       if (nvt->cir_wake_addr)
-               release_region(nvt->cir_wake_addr, CIR_IOREG_LENGTH);
-
        rc_free_device(rdev);
        kfree(nvt);