From c168f838ac1cd9b3c701337003302d610d12af80 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Mon, 3 Jan 2011 18:26:14 +0000 Subject: [PATCH] dahdi: Add the span onto the list as the very last thing Signed-off-by: Shaun Ruffell Acked-by: Kinsey Moore git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9582 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/dahdi-base.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index f0ec082..90d6841 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -6090,6 +6090,8 @@ int dahdi_register(struct dahdi_span *span, int prefmaster) { int x; int res = 0; + int spanno; + unsigned long flags; if (!span) return -EINVAL; @@ -6119,15 +6121,12 @@ int dahdi_register(struct dahdi_span *span, int prefmaster) } if (x < DAHDI_MAX_SPANS) { - spans[x] = span; - if (maxspans < x + 1) - maxspans = x + 1; + spanno = x; } else { module_printk(KERN_ERR, "Too many DAHDI spans registered\n"); return -EBUSY; } - set_bit(DAHDI_FLAGBIT_REGISTERED, &span->flags); span->spanno = x; spin_lock_init(&span->lock); @@ -6181,6 +6180,13 @@ int dahdi_register(struct dahdi_span *span, int prefmaster) } } + spin_lock_irqsave(&chan_lock, flags); + spans[spanno] = span; + if (maxspans < x + 1) + maxspans = x + 1; + spin_unlock_irqrestore(&chan_lock, flags); + set_bit(DAHDI_FLAGBIT_REGISTERED, &span->flags); + return 0; unreg_channels: @@ -6209,6 +6215,7 @@ int dahdi_unregister(struct dahdi_span *span) module_printk(KERN_ERR, "Span %s does not appear to be registered\n", span->name); return -1; } + /* Shutdown the span if it's running */ if (span->flags & DAHDI_FLAG_RUNNING) if (span->ops->shutdown) @@ -6218,6 +6225,12 @@ int dahdi_unregister(struct dahdi_span *span) module_printk(KERN_ERR, "Span %s has spanno %d which is something else\n", span->name, span->spanno); return -1; } + + clear_bit(DAHDI_FLAGBIT_REGISTERED, &span->flags); + spin_lock_irqsave(&chan_lock, flags); + spans[span->spanno] = NULL; + spin_unlock_irqrestore(&chan_lock, flags); + if (debug & DEBUG_MAIN) module_printk(KERN_NOTICE, "Unregistering Span '%s' with %d channels\n", span->name, span->channels); #ifdef CONFIG_PROC_FS @@ -6230,9 +6243,6 @@ int dahdi_unregister(struct dahdi_span *span) CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, span->chans[x]->channo)); } - spans[span->spanno] = NULL; - span->spanno = 0; - clear_bit(DAHDI_FLAGBIT_REGISTERED, &span->flags); for (x=0;xchannels;x++) dahdi_chan_unreg(span->chans[x]); @@ -6263,7 +6273,7 @@ int dahdi_unregister(struct dahdi_span *span) } master = new_master; } - + span->spanno = 0; return 0; }