From 5a9e9d4f8b7c38a9fff9e4c2c4499dcdee82d2e6 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Tue, 3 Apr 2012 19:44:27 +0000 Subject: dahdi_dynamic: Do not call into dahdi_dynamic without holding reference. Instead of registering a function pointer, register a dahdi_dynamic_ops structure that contains the owner as well as the ioctl callback. This way dahdi.ko can bump up the reference count on dahdi_dynamic.ko before calling the ioctl callback. Also, use the registration mutex to guard against the module being unloaded between the time the structure pointer was checked, and the module reference is taken. Signed-off-by: Shaun Ruffell git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@10623 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/dahdi_dynamic.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'drivers/dahdi/dahdi_dynamic.c') diff --git a/drivers/dahdi/dahdi_dynamic.c b/drivers/dahdi/dahdi_dynamic.c index 79c8bba..602ebe9 100644 --- a/drivers/dahdi/dahdi_dynamic.c +++ b/drivers/dahdi/dahdi_dynamic.c @@ -818,10 +818,13 @@ static void check_for_red_alarm(unsigned long ignored) mod_timer(&alarmcheck, jiffies + 1 * HZ); } +static const struct dahdi_dynamic_ops dahdi_dynamic_ops = { + .owner = THIS_MODULE, + .ioctl = dahdi_dynamic_ioctl, +}; + static int dahdi_dynamic_init(void) { - dahdi_set_dynamic_ioctl(dahdi_dynamic_ioctl); - /* Start process to check for RED ALARM */ init_timer(&alarmcheck); alarmcheck.expires = 0; @@ -832,19 +835,22 @@ static int dahdi_dynamic_init(void) #ifdef ENABLE_TASKLETS tasklet_init(&dahdi_dynamic_tlet, dahdi_dynamic_tasklet, 0); #endif + dahdi_set_dynamic_ops(&dahdi_dynamic_ops); + printk(KERN_INFO "DAHDI Dynamic Span support LOADED\n"); return 0; } static void dahdi_dynamic_cleanup(void) { + dahdi_set_dynamic_ops(NULL); + #ifdef ENABLE_TASKLETS if (taskletpending) { tasklet_disable(&dahdi_dynamic_tlet); tasklet_kill(&dahdi_dynamic_tlet); } #endif - dahdi_set_dynamic_ioctl(NULL); del_timer(&alarmcheck); printk(KERN_INFO "DAHDI Dynamic Span support unloaded\n"); } -- cgit v1.2.3