diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2011-01-10 21:42:00 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2011-01-10 21:42:00 +0000 |
commit | 823557a20bc704e1ce472adb15e84be8fcb53a85 (patch) | |
tree | 19184959007f4e68eebd056d2f4a894245ec3d64 /drivers/dahdi/dahdi-base.c | |
parent | 7c6726dddc5fae48f0d9d3e0eeb658c5987df7ca (diff) |
span_sysfs_{create,remove}
* Separate out device generation in dahdi_[un]register to separate
functions.
* As we don't keep anywhere the information of whether or not
* there's
an existing device node for a channel, I abuse an unused flag:
DAHDI_FLAGBIT_DEVFILE (25), to mark if the channel has a sysfs node.
DAHDI_FLAGBIT_DEVFILE is expected to be replaced later on with a proper
pointer to the device (or embedding of the device). I prefer a simple
flag for now as it does not break ABI.
Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Shaun Ruffell <sruffell@digium.com>
git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9625 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'drivers/dahdi/dahdi-base.c')
-rw-r--r-- | drivers/dahdi/dahdi-base.c | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index d0849d3..acecd94 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -6445,6 +6445,54 @@ static long dahdi_ioctl_compat(struct file *file, unsigned int cmd, } #endif +static void span_sysfs_remove(struct dahdi_span *span) +{ + int x; + for (x = 0; x < span->channels; x++) { + struct dahdi_chan *chan = span->chans[x]; + if (!test_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags)) + continue; + + CLASS_DEV_DESTROY(dahdi_class, + MKDEV(DAHDI_MAJOR, chan->channo)); + clear_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags); + } +} + +static int span_sysfs_create(struct dahdi_span *span) +{ + int res = 0; + int x; + + for (x = 0; x < span->channels; x++) { + struct dahdi_chan *chan = span->chans[x]; + char chan_name[32]; + void *dummy; + + if (chan->channo >= 250) + continue; + if (test_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags)) + continue; + + snprintf(chan_name, sizeof(chan_name), "dahdi!%d", + chan->channo); + dummy = (void *)CLASS_DEV_CREATE(dahdi_class, + MKDEV(DAHDI_MAJOR, chan->channo), + NULL, chan_name); + if (IS_ERR(dummy)) { + res = PTR_ERR(dummy); + goto cleanup; + } + + set_bit(DAHDI_FLAGBIT_DEVFILE, &chan->flags); + } + return 0; + +cleanup: + span_sysfs_remove(span); + return res; +} + /** * _get_next_channo - Return the next taken channel number from the span list. * @span: The span with which to start the search. @@ -6518,6 +6566,7 @@ static int _dahdi_register(struct dahdi_span *span, int prefmaster) struct list_head *loc = &span_list; unsigned long flags; unsigned int channo; + int res = 0; if (!span || !span->ops || !span->ops->owner) return -EINVAL; @@ -6560,15 +6609,7 @@ static int _dahdi_register(struct dahdi_span *span, int prefmaster) } #endif - for (x = 0; x < span->channels; x++) { - if (span->chans[x]->channo < 250) { - char chan_name[32]; - snprintf(chan_name, sizeof(chan_name), "dahdi!%d", - span->chans[x]->channo); - CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, - span->chans[x]->channo), NULL, chan_name); - } - } + res = span_sysfs_create(span); if (debug & DEBUG_MAIN) { module_printk(KERN_NOTICE, "Registered Span %d ('%s') with " @@ -6637,10 +6678,7 @@ static int _dahdi_unregister(struct dahdi_span *span) remove_proc_entry(span->proc_entry->name, root_proc_entry); #endif /* CONFIG_PROC_FS */ - for (x = 0; x < span->channels; x++) { - if (span->chans[x]->channo < 250) - CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, span->chans[x]->channo)); - } + span_sysfs_remove(span); for (x=0;x<span->channels;x++) dahdi_chan_unreg(span->chans[x]); |