V4L/DVB (4391): Refactor dvb_detach calls into a single dvb_frontend_detach function.
authorAndrew de Quincey <adq_dvb@lidskialf.net>
Tue, 8 Aug 2006 12:10:09 +0000 (09:10 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Tue, 26 Sep 2006 14:53:29 +0000 (11:53 -0300)
Remove buggy dvb_detach() macro and replace with unified
dvb_frontend_detach() call.

Signed-off-by: Andrew de Quincey <adq_dvb@lidskialf.net>
Acked-by: Trent Piepho <xyzzy@speakeasy.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
13 files changed:
drivers/media/dvb/b2c2/flexcop-fe-tuner.c
drivers/media/dvb/bt8xx/dvb-bt8xx.c
drivers/media/dvb/dvb-core/dvb_frontend.c
drivers/media/dvb/dvb-core/dvb_frontend.h
drivers/media/dvb/dvb-core/dvbdev.h
drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
drivers/media/dvb/ttpci/av7110.c
drivers/media/dvb/ttpci/budget-av.c
drivers/media/dvb/ttpci/budget-ci.c
drivers/media/dvb/ttpci/budget-patch.c
drivers/media/dvb/ttpci/budget.c
drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
drivers/media/video/video-buf-dvb.c

index e2d2e65dea52ad30b58c7a73a1943f56b6dc1ecc..0c3bab37d8dff287cba9b953caebd7670332a19a 100644 (file)
@@ -571,9 +571,7 @@ int flexcop_frontend_init(struct flexcop_device *fc)
        } else {
                if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) {
                        err("frontend registration failed!");
-                       dvb_detach(fc->fe->ops.release_sec, fc->fe);
-                       dvb_detach(fc->fe->ops.tuner_ops.release, fc->fe);
-                       dvb_detach(fc->fe->ops.release, fc->fe);
+                       dvb_frontend_detach(fc->fe);
                        fc->fe = NULL;
                        return -EINVAL;
                }
@@ -586,9 +584,7 @@ void flexcop_frontend_exit(struct flexcop_device *fc)
 {
        if (fc->init_state & FC_STATE_FE_INIT) {
                dvb_unregister_frontend(fc->fe);
-               dvb_detach(fc->fe->ops.release_sec, fc->fe);
-               dvb_detach(fc->fe->ops.tuner_ops.release, fc->fe);
-               dvb_detach(fc->fe->ops.release, fc->fe);
+               dvb_frontend_detach(fc->fe);
        }
 
        fc->init_state &= ~FC_STATE_FE_INIT;
index 6f0bb736099118d558b5d09d94c3804db3df2ee7..db1eba9a5c36bf7bb81caa0e18654ee505764f59 100644 (file)
@@ -706,9 +706,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
        else
                if (dvb_register_frontend(&card->dvb_adapter, card->fe)) {
                        printk("dvb-bt8xx: Frontend registration failed!\n");
-                       dvb_detach(card->fe->ops.release_sec, card->fe);
-                       dvb_detach(card->fe->ops.tuner_ops.release, card->fe);
-                       dvb_detach(card->fe->ops.release, card->fe);
+                       dvb_frontend_detach(card->fe);
                        card->fe = NULL;
                }
 }
@@ -927,9 +925,7 @@ static void dvb_bt8xx_remove(struct bttv_sub_device *sub)
        dvb_dmx_release(&card->demux);
        if (card->fe) {
                dvb_unregister_frontend(card->fe);
-               dvb_detach(card->fe->ops.release_sec, card->fe);
-               dvb_detach(card->fe->ops.tuner_ops.release, card->fe);
-               dvb_detach(card->fe->ops.release, card->fe);
+               dvb_frontend_detach(card->fe);
        }
        dvb_unregister_adapter(&card->dvb_adapter);
 
index d544731bed7d7191335433855b0d92518a074b76..86dadc71cd61d9487114fca0ac24823f3b476277 100644 (file)
@@ -1112,3 +1112,35 @@ int dvb_unregister_frontend(struct dvb_frontend* fe)
        return 0;
 }
 EXPORT_SYMBOL(dvb_unregister_frontend);
+
+#ifdef CONFIG_DVB_DETACH
+void dvb_frontend_detach(struct dvb_frontend* fe)
+{
+       void *ptr;
+
+       if (fe->ops.release_sec) {
+               fe->ops.release_sec(fe);
+               symbol_put_addr(fe->ops.release_sec);
+       }
+       if (fe->ops.tuner_ops.release) {
+               fe->ops.tuner_ops.release(fe);
+               symbol_put_addr(fe->ops.tuner_ops.release);
+       }
+       ptr = (void*)fe->ops.release;
+       if (ptr) {
+               fe->ops.release(fe);
+               symbol_put_addr(ptr);
+       }
+}
+#else
+void dvb_frontend_detach(struct dvb_frontend* fe)
+{
+       if (fe->ops.release_sec)
+               fe->ops.release_sec(fe);
+       if (fe->ops.tuner_ops.release)
+               fe->ops.tuner_ops.release(fe);
+       if (fe->ops.release)
+               fe->ops.release(fe);
+}
+#endif
+EXPORT_SYMBOL(dvb_frontend_detach);
index 6bea01af440022caa5e842c971b06531fa8c6744..e5d5028b3694fc68663da122664e6172095c596f 100644 (file)
@@ -158,6 +158,8 @@ extern int dvb_register_frontend(struct dvb_adapter* dvb,
 
 extern int dvb_unregister_frontend(struct dvb_frontend* fe);
 
+extern void dvb_frontend_detach(struct dvb_frontend* fe);
+
 extern void dvb_frontend_reinitialise(struct dvb_frontend *fe);
 
 extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec);
index 66d91e530f85f49f13b358f945e8eb565e140d13..620e7887b3d3b11c155d65cbbddc12dfdd284555 100644 (file)
@@ -102,7 +102,6 @@ extern int dvb_usercopy(struct inode *inode, struct file *file,
                            int (*func)(struct inode *inode, struct file *file,
                            unsigned int cmd, void *arg));
 
-
 /** generic DVB attach function. */
 #ifdef CONFIG_DVB_CORE_ATTACH
 #define dvb_attach(FUNCTION, ARGS...) ({ \
@@ -118,28 +117,11 @@ extern int dvb_usercopy(struct inode *inode, struct file *file,
        __r; \
 })
 
-#define dvb_detach(FUNCPTR, ARGS...) ({ \
-       typeof((FUNCPTR)) __funcptrtmp = FUNCPTR; \
-       if (__funcptrtmp) { \
-               __funcptrtmp(ARGS); \
-               symbol_put_addr(__funcptrtmp); \
-       } \
-       FUNCPTR = NULL; \
-})
-
 #else
 #define dvb_attach(FUNCTION, ARGS...) ({ \
        FUNCTION(ARGS); \
 })
 
-#define dvb_detach(FUNCPTR, ARGS...) \
-do { \
-       if (FUNCPTR) \
-               FUNCPTR(ARGS); \
-       FUNCPTR = NULL; \
-} while(0)
-
 #endif
 
-
 #endif /* #ifndef _DVBDEV_H_ */
index f0da15ebe33b4f38033272009d1438b1ba5963e5..9f8d3f0ca5a1c509e8ec78efc88d92ecbf23cdca 100644 (file)
@@ -188,9 +188,7 @@ int dvb_usb_fe_init(struct dvb_usb_device* d)
 
                if (dvb_register_frontend(&d->dvb_adap, d->fe)) {
                        err("Frontend registration failed.");
-                       dvb_detach(d->fe->ops.release_sec, d->fe);
-                       dvb_detach(d->fe->ops.tuner_ops.release, d->fe);
-                       dvb_detach(d->fe->ops.release, d->fe);
+                       dvb_frontend_detach(d->fe);
                        d->fe = NULL;
                        return -ENODEV;
                }
@@ -207,9 +205,7 @@ int dvb_usb_fe_exit(struct dvb_usb_device *d)
 {
        if (d->fe != NULL) {
                dvb_unregister_frontend(d->fe);
-               dvb_detach(d->fe->ops.release_sec, d->fe);
-               dvb_detach(d->fe->ops.tuner_ops.release, d->fe);
-               dvb_detach(d->fe->ops.release, d->fe);
+               dvb_frontend_detach(d->fe);
        }
        return 0;
 }
index d195cf59108174b7c2601a834f4a210b0ca4dafb..5742154d88412649044a1e16503bb4fde4ef84e5 100644 (file)
@@ -1385,9 +1385,7 @@ static void dvb_unregister(struct av7110 *av7110)
 
        if (av7110->fe != NULL) {
                dvb_unregister_frontend(av7110->fe);
-               dvb_detach(av7110->fe->ops.release_sec, av7110->fe);
-               dvb_detach(av7110->fe->ops.tuner_ops.release, av7110->fe);
-               dvb_detach(av7110->fe->ops.release, av7110->fe);
+               dvb_frontend_detach(av7110->fe);
        }
        dvb_unregister_device(av7110->osd_dev);
        av7110_av_unregister(av7110);
@@ -2259,9 +2257,7 @@ static int frontend_init(struct av7110 *av7110)
                ret = dvb_register_frontend(&av7110->dvb_adapter, av7110->fe);
                if (ret < 0) {
                        printk("av7110: Frontend registration failed!\n");
-                       dvb_detach(av7110->fe->ops.release_sec, av7110->fe);
-                       dvb_detach(av7110->fe->ops.tuner_ops.release, av7110->fe);
-                       dvb_detach(av7110->fe->ops.release, av7110->fe);
+                       dvb_frontend_detach(av7110->fe);
                        av7110->fe = NULL;
                }
        }
index c648c01c8ec52c59c42c3c3d7dfb30ada53c5a4f..6f1c41fb2cb45765a8fb6d843ea236810fe648c9 100644 (file)
@@ -1192,9 +1192,7 @@ static void frontend_init(struct budget_av *budget_av)
        if (dvb_register_frontend(&budget_av->budget.dvb_adapter,
                                  budget_av->budget.dvb_frontend)) {
                printk(KERN_ERR "budget-av: Frontend registration failed!\n");
-               dvb_detach(budget_av->budget.dvb_frontend->ops.release_sec, budget_av->budget.dvb_frontend);
-               dvb_detach(budget_av->budget.dvb_frontend->ops.tuner_ops.release, budget_av->budget.dvb_frontend);
-               dvb_detach(budget_av->budget.dvb_frontend->ops.release, budget_av->budget.dvb_frontend);
+               dvb_frontend_detach(budget_av->budget.dvb_frontend);
                budget_av->budget.dvb_frontend = NULL;
        }
 }
@@ -1230,9 +1228,7 @@ static int budget_av_detach(struct saa7146_dev *dev)
 
        if (budget_av->budget.dvb_frontend != NULL) {
                dvb_unregister_frontend(budget_av->budget.dvb_frontend);
-               dvb_detach(budget_av->budget.dvb_frontend->ops.release_sec, budget_av->budget.dvb_frontend);
-               dvb_detach(budget_av->budget.dvb_frontend->ops.tuner_ops.release, budget_av->budget.dvb_frontend);
-               dvb_detach(budget_av->budget.dvb_frontend->ops.release, budget_av->budget.dvb_frontend);
+               dvb_frontend_detach(budget_av->budget.dvb_frontend);
        }
        err = ttpci_budget_deinit(&budget_av->budget);
 
index 20b5e8dc8739bc9cd7816c2b40b6c235bbe1b06b..e440fa100b9494adfdc567d62f95f0d43bbbc807 100644 (file)
@@ -1065,9 +1065,7 @@ static void frontend_init(struct budget_ci *budget_ci)
                if (dvb_register_frontend
                    (&budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) {
                        printk("budget-ci: Frontend registration failed!\n");
-                       dvb_detach(budget_ci->budget.dvb_frontend->ops.release_sec, budget_ci->budget.dvb_frontend);
-                       dvb_detach(budget_ci->budget.dvb_frontend->ops.tuner_ops.release, budget_ci->budget.dvb_frontend);
-                       dvb_detach(budget_ci->budget.dvb_frontend->ops.release, budget_ci->budget.dvb_frontend);
+                       dvb_frontend_detach(budget_ci->budget.dvb_frontend);
                        budget_ci->budget.dvb_frontend = NULL;
                }
        }
@@ -1117,9 +1115,7 @@ static int budget_ci_detach(struct saa7146_dev *dev)
                ciintf_deinit(budget_ci);
        if (budget_ci->budget.dvb_frontend) {
                dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
-               dvb_detach(budget_ci->budget.dvb_frontend->ops.release_sec, budget_ci->budget.dvb_frontend);
-               dvb_detach(budget_ci->budget.dvb_frontend->ops.tuner_ops.release, budget_ci->budget.dvb_frontend);
-               dvb_detach(budget_ci->budget.dvb_frontend->ops.release, budget_ci->budget.dvb_frontend);
+               dvb_frontend_detach(budget_ci->budget.dvb_frontend);
        }
        err = ttpci_budget_deinit(&budget_ci->budget);
 
index 82dbef863e517d0bda2ae51b512d988d1438a11f..d043e1f50d92ccb6fc61922fc84c1ec7fe8880e4 100644 (file)
@@ -367,9 +367,7 @@ static void frontend_init(struct budget_patch* budget)
        } else {
                if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) {
                        printk("budget-av: Frontend registration failed!\n");
-                       dvb_detach(budget->dvb_frontend->ops.release_sec, budget->dvb_frontend);
-                       dvb_detach(budget->dvb_frontend->ops.tuner_ops.release, budget->dvb_frontend);
-                       dvb_detach(budget->dvb_frontend->ops.release, budget->dvb_frontend);
+                       dvb_frontend_detach(budget->dvb_frontend);
                        budget->dvb_frontend = NULL;
                }
        }
@@ -630,9 +628,7 @@ static int budget_patch_detach (struct saa7146_dev* dev)
 
        if (budget->dvb_frontend) {
                dvb_unregister_frontend(budget->dvb_frontend);
-               dvb_detach(budget->dvb_frontend->ops.release_sec, budget->dvb_frontend);
-               dvb_detach(budget->dvb_frontend->ops.tuner_ops.release, budget->dvb_frontend);
-               dvb_detach(budget->dvb_frontend->ops.release, budget->dvb_frontend);
+               dvb_frontend_detach(budget->dvb_frontend);
        }
        err = ttpci_budget_deinit (budget);
 
index 19beb11f96641c5185fb703a8197480e0cc6af9d..e846b96201709b0f24e36af1d04b9a1c9f0098f0 100644 (file)
@@ -442,9 +442,7 @@ static void frontend_init(struct budget *budget)
 
 error_out:
        printk("budget: Frontend registration failed!\n");
-       dvb_detach(budget->dvb_frontend->ops.release_sec, budget->dvb_frontend);
-       dvb_detach(budget->dvb_frontend->ops.tuner_ops.release, budget->dvb_frontend);
-       dvb_detach(budget->dvb_frontend->ops.release, budget->dvb_frontend);
+       dvb_frontend_detach(budget->dvb_frontend);
        budget->dvb_frontend = NULL;
        return;
 }
@@ -484,9 +482,7 @@ static int budget_detach (struct saa7146_dev* dev)
 
        if (budget->dvb_frontend) {
                dvb_unregister_frontend(budget->dvb_frontend);
-               dvb_detach(budget->dvb_frontend->ops.release_sec, budget->dvb_frontend);
-               dvb_detach(budget->dvb_frontend->ops.tuner_ops.release, budget->dvb_frontend);
-               dvb_detach(budget->dvb_frontend->ops.release, budget->dvb_frontend);
+               dvb_frontend_detach(budget->dvb_frontend);
        }
 
        err = ttpci_budget_deinit (budget);
index 6f58c66d6ef926d572c122da642ef1846c936464..234199875f53f77c094251969c1713eb91dcb34d 100644 (file)
@@ -1625,9 +1625,7 @@ static void frontend_init(struct ttusb* ttusb)
        } else {
                if (dvb_register_frontend(&ttusb->adapter, ttusb->fe)) {
                        printk("dvb-ttusb-budget: Frontend registration failed!\n");
-                       dvb_detach(ttusb->fe->ops.release_sec, ttusb->fe);
-                       dvb_detach(ttusb->fe->ops.tuner_ops.release, ttusb->fe);
-                       dvb_detach(ttusb->fe->ops.release, ttusb->fe);
+                       dvb_frontend_detach(ttusb->fe);
                        ttusb->fe = NULL;
                }
        }
@@ -1766,9 +1764,7 @@ static void ttusb_disconnect(struct usb_interface *intf)
        dvb_dmx_release(&ttusb->dvb_demux);
        if (ttusb->fe != NULL) {
                dvb_unregister_frontend(ttusb->fe);
-               dvb_detach(ttusb->fe->ops.release_sec, ttusb->fe);
-               dvb_detach(ttusb->fe->ops.tuner_ops.release, ttusb->fe);
-               dvb_detach(ttusb->fe->ops.release, ttusb->fe);
+               dvb_frontend_detach(ttusb->fe);
        }
        i2c_del_adapter(&ttusb->i2c_adap);
        dvb_unregister_adapter(&ttusb->adapter);
index 376d354b27f69a61d47b68b61168db52d16505ac..f53edf1923b7de3fa558c2adf4c42980f97ad608 100644 (file)
@@ -223,9 +223,7 @@ fail_dmxdev:
 fail_dmx:
        dvb_unregister_frontend(dvb->frontend);
 fail_frontend:
-       dvb_detach(dvb->frontend->ops.release_sec, dvb->frontend);
-       dvb_detach(dvb->frontend->ops.tuner_ops.release, dvb->frontend);
-       dvb_detach(dvb->frontend->ops.release, dvb->frontend);
+       dvb_frontend_detach(dvb->frontend);
        dvb_unregister_adapter(&dvb->adapter);
 fail_adapter:
        return result;
@@ -239,9 +237,7 @@ void videobuf_dvb_unregister(struct videobuf_dvb *dvb)
        dvb_dmxdev_release(&dvb->dmxdev);
        dvb_dmx_release(&dvb->demux);
        dvb_unregister_frontend(dvb->frontend);
-       dvb_detach(dvb->frontend->ops.release_sec, dvb->frontend);
-       dvb_detach(dvb->frontend->ops.tuner_ops.release, dvb->frontend);
-       dvb_detach(dvb->frontend->ops.release, dvb->frontend);
+       dvb_frontend_detach(dvb->frontend);
        dvb_unregister_adapter(&dvb->adapter);
 }