From 9a58a80a701bdb2d220cdab4914218df5b48d781 Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Thu, 14 Jan 2010 03:10:54 -0800 Subject: proc_fops: convert drivers/isdn/ to seq_file Convert code away from ->read_proc/->write_proc interfaces. Switch to proc_create()/proc_create_data() which make addition of proc entries reliable wrt NULL ->proc_fops, NULL ->data and so on. Problem with ->read_proc et al is described here commit 786d7e1612f0b0adb6046f19b906609e4fe8b1ba "Fix rmmod/read/write races in /proc entries" [akpm@linux-foundation.org: CONFIG_PROC_FS=n build fix] Signed-off-by: Alexey Dobriyan Signed-off-by: Tilman Schmidt Signed-off-by: Karsten Keil Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 99 ++++++---------- drivers/isdn/capi/capidrv.c | 55 +++------ drivers/isdn/capi/kcapi.c | 8 +- drivers/isdn/gigaset/capi.c | 75 ++++++------ drivers/isdn/hardware/avm/avmcard.h | 6 +- drivers/isdn/hardware/avm/b1.c | 54 +++++---- drivers/isdn/hardware/avm/b1dma.c | 71 ++++++------ drivers/isdn/hardware/avm/b1isa.c | 2 +- drivers/isdn/hardware/avm/b1pci.c | 4 +- drivers/isdn/hardware/avm/b1pcmcia.c | 2 +- drivers/isdn/hardware/avm/c4.c | 53 +++++---- drivers/isdn/hardware/avm/t1isa.c | 2 +- drivers/isdn/hardware/avm/t1pci.c | 2 +- drivers/isdn/hardware/eicon/capimain.c | 40 ++++--- drivers/isdn/hardware/eicon/diva_didd.c | 45 ++++---- drivers/isdn/hardware/eicon/divasi.c | 48 ++++---- drivers/isdn/hardware/eicon/divasproc.c | 198 ++++++++++++++------------------ drivers/isdn/hysdn/hycapi.c | 56 ++++----- 18 files changed, 384 insertions(+), 436 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 65bf91e16a42..79f9364aded6 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -33,6 +33,7 @@ #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ #include #include +#include #include #include #include @@ -1407,114 +1408,84 @@ static void capinc_tty_exit(void) * /proc/capi/capi20: * minor applid nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt */ -static int proc_capidev_read_proc(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int capi20_proc_show(struct seq_file *m, void *v) { struct capidev *cdev; struct list_head *l; - int len = 0; read_lock(&capidev_list_lock); list_for_each(l, &capidev_list) { cdev = list_entry(l, struct capidev, list); - len += sprintf(page+len, "0 %d %lu %lu %lu %lu\n", + seq_printf(m, "0 %d %lu %lu %lu %lu\n", cdev->ap.applid, cdev->ap.nrecvctlpkt, cdev->ap.nrecvdatapkt, cdev->ap.nsentctlpkt, cdev->ap.nsentdatapkt); - if (len <= off) { - off -= len; - len = 0; - } else { - if (len-off > count) - goto endloop; - } } - -endloop: read_unlock(&capidev_list_lock); - if (len < count) - *eof = 1; - if (len > count) len = count; - if (len < 0) len = 0; - return len; + return 0; } +static int capi20_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, capi20_proc_show, NULL); +} + +static const struct file_operations capi20_proc_fops = { + .owner = THIS_MODULE, + .open = capi20_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + /* * /proc/capi/capi20ncci: * applid ncci */ -static int proc_capincci_read_proc(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int capi20ncci_proc_show(struct seq_file *m, void *v) { struct capidev *cdev; struct capincci *np; struct list_head *l; - int len = 0; read_lock(&capidev_list_lock); list_for_each(l, &capidev_list) { cdev = list_entry(l, struct capidev, list); for (np=cdev->nccis; np; np = np->next) { - len += sprintf(page+len, "%d 0x%x\n", + seq_printf(m, "%d 0x%x\n", cdev->ap.applid, np->ncci); - if (len <= off) { - off -= len; - len = 0; - } else { - if (len-off > count) - goto endloop; - } } } -endloop: read_unlock(&capidev_list_lock); - *start = page+off; - if (len < count) - *eof = 1; - if (len>count) len = count; - if (len<0) len = 0; - return len; + return 0; } -static struct procfsentries { - char *name; - mode_t mode; - int (*read_proc)(char *page, char **start, off_t off, - int count, int *eof, void *data); - struct proc_dir_entry *procent; -} procfsentries[] = { - /* { "capi", S_IFDIR, 0 }, */ - { "capi/capi20", 0 , proc_capidev_read_proc }, - { "capi/capi20ncci", 0 , proc_capincci_read_proc }, +static int capi20ncci_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, capi20ncci_proc_show, NULL); +} + +static const struct file_operations capi20ncci_proc_fops = { + .owner = THIS_MODULE, + .open = capi20ncci_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, }; static void __init proc_init(void) { - int nelem = ARRAY_SIZE(procfsentries); - int i; - - for (i=0; i < nelem; i++) { - struct procfsentries *p = procfsentries + i; - p->procent = create_proc_entry(p->name, p->mode, NULL); - if (p->procent) p->procent->read_proc = p->read_proc; - } + proc_create("capi/capi20", 0, NULL, &capi20_proc_fops); + proc_create("capi/capi20ncci", 0, NULL, &capi20ncci_proc_fops); } static void __exit proc_exit(void) { - int nelem = ARRAY_SIZE(procfsentries); - int i; - - for (i=nelem-1; i >= 0; i--) { - struct procfsentries *p = procfsentries + i; - if (p->procent) { - remove_proc_entry(p->name, NULL); - p->procent = NULL; - } - } + remove_proc_entry("capi/capi20", NULL); + remove_proc_entry("capi/capi20ncci", NULL); } /* -------- init function and module interface ---------------------- */ diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c index 66b7d7a86474..bb450152fb74 100644 --- a/drivers/isdn/capi/capidrv.c +++ b/drivers/isdn/capi/capidrv.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -2229,59 +2230,37 @@ static void lower_callback(unsigned int cmd, u32 contr, void *data) * /proc/capi/capidrv: * nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt */ -static int proc_capidrv_read_proc(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int capidrv_proc_show(struct seq_file *m, void *v) { - int len = 0; - - len += sprintf(page+len, "%lu %lu %lu %lu\n", + seq_printf(m, "%lu %lu %lu %lu\n", global.ap.nrecvctlpkt, global.ap.nrecvdatapkt, global.ap.nsentctlpkt, global.ap.nsentdatapkt); - if (off+count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len-off) ? count : len-off); + return 0; +} + +static int capidrv_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, capidrv_proc_show, NULL); } -static struct procfsentries { - char *name; - mode_t mode; - int (*read_proc)(char *page, char **start, off_t off, - int count, int *eof, void *data); - struct proc_dir_entry *procent; -} procfsentries[] = { - /* { "capi", S_IFDIR, 0 }, */ - { "capi/capidrv", 0 , proc_capidrv_read_proc }, +static const struct file_operations capidrv_proc_fops = { + .owner = THIS_MODULE, + .open = capidrv_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, }; static void __init proc_init(void) { - int nelem = ARRAY_SIZE(procfsentries); - int i; - - for (i=0; i < nelem; i++) { - struct procfsentries *p = procfsentries + i; - p->procent = create_proc_entry(p->name, p->mode, NULL); - if (p->procent) p->procent->read_proc = p->read_proc; - } + proc_create("capi/capidrv", 0, NULL, &capidrv_proc_fops); } static void __exit proc_exit(void) { - int nelem = ARRAY_SIZE(procfsentries); - int i; - - for (i=nelem-1; i >= 0; i--) { - struct procfsentries *p = procfsentries + i; - if (p->procent) { - remove_proc_entry(p->name, NULL); - p->procent = NULL; - } - } + remove_proc_entry("capi/capidrv", NULL); } static int __init capidrv_init(void) diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index dc506ab99cac..b0bacf377c18 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -490,13 +490,7 @@ attach_capi_ctr(struct capi_ctr *card) card->traceflag = showcapimsgs; sprintf(card->procfn, "capi/controllers/%d", card->cnr); - card->procent = create_proc_entry(card->procfn, 0, NULL); - if (card->procent) { - card->procent->read_proc = - (int (*)(char *,char **,off_t,int,int *,void *)) - card->ctr_read_proc; - card->procent->data = card; - } + card->procent = proc_create_data(card->procfn, 0, NULL, card->proc_fops, card); ncards++; printk(KERN_NOTICE "kcapi: Controller [%03d]: %s attached\n", diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c index 3f5cd06af104..6f0ae32906bf 100644 --- a/drivers/isdn/gigaset/capi.c +++ b/drivers/isdn/gigaset/capi.c @@ -13,6 +13,8 @@ #include "gigaset.h" #include +#include +#include #include #include #include @@ -2106,35 +2108,22 @@ static char *gigaset_procinfo(struct capi_ctr *ctr) return ctr->name; /* ToDo: more? */ } -/** - * gigaset_ctr_read_proc() - build controller proc file entry - * @page: buffer of PAGE_SIZE bytes for receiving the entry. - * @start: unused. - * @off: unused. - * @count: unused. - * @eof: unused. - * @ctr: controller descriptor structure. - * - * Return value: length of generated entry - */ -static int gigaset_ctr_read_proc(char *page, char **start, off_t off, - int count, int *eof, struct capi_ctr *ctr) +static int gigaset_proc_show(struct seq_file *m, void *v) { + struct capi_ctr *ctr = m->private; struct cardstate *cs = ctr->driverdata; char *s; int i; - int len = 0; - len += sprintf(page+len, "%-16s %s\n", "name", ctr->name); - len += sprintf(page+len, "%-16s %s %s\n", "dev", + + seq_printf(m, "%-16s %s\n", "name", ctr->name); + seq_printf(m, "%-16s %s %s\n", "dev", dev_driver_string(cs->dev), dev_name(cs->dev)); - len += sprintf(page+len, "%-16s %d\n", "id", cs->myid); + seq_printf(m, "%-16s %d\n", "id", cs->myid); if (cs->gotfwver) - len += sprintf(page+len, "%-16s %d.%d.%d.%d\n", "firmware", + seq_printf(m, "%-16s %d.%d.%d.%d\n", "firmware", cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]); - len += sprintf(page+len, "%-16s %d\n", "channels", - cs->channels); - len += sprintf(page+len, "%-16s %s\n", "onechannel", - cs->onechannel ? "yes" : "no"); + seq_printf(m, "%-16s %d\n", "channels", cs->channels); + seq_printf(m, "%-16s %s\n", "onechannel", cs->onechannel ? "yes" : "no"); switch (cs->mode) { case M_UNKNOWN: @@ -2152,7 +2141,7 @@ static int gigaset_ctr_read_proc(char *page, char **start, off_t off, default: s = "??"; } - len += sprintf(page+len, "%-16s %s\n", "mode", s); + seq_printf(m, "%-16s %s\n", "mode", s); switch (cs->mstate) { case MS_UNINITIALIZED: @@ -2176,25 +2165,21 @@ static int gigaset_ctr_read_proc(char *page, char **start, off_t off, default: s = "??"; } - len += sprintf(page+len, "%-16s %s\n", "mstate", s); + seq_printf(m, "%-16s %s\n", "mstate", s); - len += sprintf(page+len, "%-16s %s\n", "running", - cs->running ? "yes" : "no"); - len += sprintf(page+len, "%-16s %s\n", "connected", - cs->connected ? "yes" : "no"); - len += sprintf(page+len, "%-16s %s\n", "isdn_up", - cs->isdn_up ? "yes" : "no"); - len += sprintf(page+len, "%-16s %s\n", "cidmode", - cs->cidmode ? "yes" : "no"); + seq_printf(m, "%-16s %s\n", "running", cs->running ? "yes" : "no"); + seq_printf(m, "%-16s %s\n", "connected", cs->connected ? "yes" : "no"); + seq_printf(m, "%-16s %s\n", "isdn_up", cs->isdn_up ? "yes" : "no"); + seq_printf(m, "%-16s %s\n", "cidmode", cs->cidmode ? "yes" : "no"); for (i = 0; i < cs->channels; i++) { - len += sprintf(page+len, "[%d]%-13s %d\n", i, "corrupted", + seq_printf(m, "[%d]%-13s %d\n", i, "corrupted", cs->bcs[i].corrupted); - len += sprintf(page+len, "[%d]%-13s %d\n", i, "trans_down", + seq_printf(m, "[%d]%-13s %d\n", i, "trans_down", cs->bcs[i].trans_down); - len += sprintf(page+len, "[%d]%-13s %d\n", i, "trans_up", + seq_printf(m, "[%d]%-13s %d\n", i, "trans_up", cs->bcs[i].trans_up); - len += sprintf(page+len, "[%d]%-13s %d\n", i, "chstate", + seq_printf(m, "[%d]%-13s %d\n", i, "chstate", cs->bcs[i].chstate); switch (cs->bcs[i].proto2) { case L2_BITSYNC: @@ -2209,11 +2194,23 @@ static int gigaset_ctr_read_proc(char *page, char **start, off_t off, default: s = "??"; } - len += sprintf(page+len, "[%d]%-13s %s\n", i, "proto2", s); + seq_printf(m, "[%d]%-13s %s\n", i, "proto2", s); } - return len; + return 0; } +static int gigaset_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, gigaset_proc_show, PDE(inode)->data); +} + +static const struct file_operations gigaset_proc_fops = { + .owner = THIS_MODULE, + .open = gigaset_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; static struct capi_driver capi_driver_gigaset = { .name = "gigaset", @@ -2256,7 +2253,7 @@ int gigaset_isdn_register(struct cardstate *cs, const char *isdnid) iif->ctr.release_appl = gigaset_release_appl; iif->ctr.send_message = gigaset_send_message; iif->ctr.procinfo = gigaset_procinfo; - iif->ctr.ctr_read_proc = gigaset_ctr_read_proc; + iif->ctr.proc_fops = &gigaset_proc_fops; INIT_LIST_HEAD(&iif->appls); skb_queue_head_init(&iif->sendqueue); atomic_set(&iif->sendqlen, 0); diff --git a/drivers/isdn/hardware/avm/avmcard.h b/drivers/isdn/hardware/avm/avmcard.h index d964f07e4a56..a70e8854461d 100644 --- a/drivers/isdn/hardware/avm/avmcard.h +++ b/drivers/isdn/hardware/avm/avmcard.h @@ -556,8 +556,7 @@ u16 b1_send_message(struct capi_ctr *ctrl, struct sk_buff *skb); void b1_parse_version(avmctrl_info *card); irqreturn_t b1_interrupt(int interrupt, void *devptr); -int b1ctl_read_proc(char *page, char **start, off_t off, - int count, int *eof, struct capi_ctr *ctrl); +extern const struct file_operations b1ctl_proc_fops; avmcard_dmainfo *avmcard_dma_alloc(char *name, struct pci_dev *, long rsize, long ssize); @@ -577,7 +576,6 @@ void b1dma_register_appl(struct capi_ctr *ctrl, capi_register_params *rp); void b1dma_release_appl(struct capi_ctr *ctrl, u16 appl); u16 b1dma_send_message(struct capi_ctr *ctrl, struct sk_buff *skb); -int b1dmactl_read_proc(char *page, char **start, off_t off, - int count, int *eof, struct capi_ctr *ctrl); +extern const struct file_operations b1dmactl_proc_fops; #endif /* _AVMCARD_H_ */ diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c index a7c0083e78a7..c38fa0f4c729 100644 --- a/drivers/isdn/hardware/avm/b1.c +++ b/drivers/isdn/hardware/avm/b1.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -634,18 +636,17 @@ irqreturn_t b1_interrupt(int interrupt, void *devptr) } /* ------------------------------------------------------------- */ -int b1ctl_read_proc(char *page, char **start, off_t off, - int count, int *eof, struct capi_ctr *ctrl) +static int b1ctl_proc_show(struct seq_file *m, void *v) { + struct capi_ctr *ctrl = m->private; avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; u8 flag; - int len = 0; char *s; - len += sprintf(page+len, "%-16s %s\n", "name", card->name); - len += sprintf(page+len, "%-16s 0x%x\n", "io", card->port); - len += sprintf(page+len, "%-16s %d\n", "irq", card->irq); + seq_printf(m, "%-16s %s\n", "name", card->name); + seq_printf(m, "%-16s 0x%x\n", "io", card->port); + seq_printf(m, "%-16s %d\n", "irq", card->irq); switch (card->cardtype) { case avm_b1isa: s = "B1 ISA"; break; case avm_b1pci: s = "B1 PCI"; break; @@ -658,20 +659,20 @@ int b1ctl_read_proc(char *page, char **start, off_t off, case avm_c2: s = "C2"; break; default: s = "???"; break; } - len += sprintf(page+len, "%-16s %s\n", "type", s); + seq_printf(m, "%-16s %s\n", "type", s); if (card->cardtype == avm_t1isa) - len += sprintf(page+len, "%-16s %d\n", "cardnr", card->cardnr); + seq_printf(m, "%-16s %d\n", "cardnr", card->cardnr); if ((s = cinfo->version[VER_DRIVER]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_driver", s); + seq_printf(m, "%-16s %s\n", "ver_driver", s); if ((s = cinfo->version[VER_CARDTYPE]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s); + seq_printf(m, "%-16s %s\n", "ver_cardtype", s); if ((s = cinfo->version[VER_SERIAL]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_serial", s); + seq_printf(m, "%-16s %s\n", "ver_serial", s); if (card->cardtype != avm_m1) { flag = ((u8 *)(ctrl->profile.manu))[3]; if (flag) - len += sprintf(page+len, "%-16s%s%s%s%s%s%s%s\n", + seq_printf(m, "%-16s%s%s%s%s%s%s%s\n", "protocol", (flag & 0x01) ? " DSS1" : "", (flag & 0x02) ? " CT1" : "", @@ -685,7 +686,7 @@ int b1ctl_read_proc(char *page, char **start, off_t off, if (card->cardtype != avm_m1) { flag = ((u8 *)(ctrl->profile.manu))[5]; if (flag) - len += sprintf(page+len, "%-16s%s%s%s%s\n", + seq_printf(m, "%-16s%s%s%s%s\n", "linetype", (flag & 0x01) ? " point to point" : "", (flag & 0x02) ? " point to multipoint" : "", @@ -693,16 +694,25 @@ int b1ctl_read_proc(char *page, char **start, off_t off, (flag & 0x04) ? " leased line with D-channel" : "" ); } - len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname); - - if (off+count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len-off) ? count : len-off); + seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname); + + return 0; +} + +static int b1ctl_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, b1ctl_proc_show, PDE(inode)->data); } +const struct file_operations b1ctl_proc_fops = { + .owner = THIS_MODULE, + .open = b1ctl_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +EXPORT_SYMBOL(b1ctl_proc_fops); + /* ------------------------------------------------------------- */ #ifdef CONFIG_PCI @@ -781,8 +791,6 @@ EXPORT_SYMBOL(b1_send_message); EXPORT_SYMBOL(b1_parse_version); EXPORT_SYMBOL(b1_interrupt); -EXPORT_SYMBOL(b1ctl_read_proc); - static int __init b1_init(void) { char *p; diff --git a/drivers/isdn/hardware/avm/b1dma.c b/drivers/isdn/hardware/avm/b1dma.c index 0e84aaae43fd..124550d0dbf3 100644 --- a/drivers/isdn/hardware/avm/b1dma.c +++ b/drivers/isdn/hardware/avm/b1dma.c @@ -11,6 +11,8 @@ #include #include +#include +#include #include #include #include @@ -855,21 +857,20 @@ u16 b1dma_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) /* ------------------------------------------------------------- */ -int b1dmactl_read_proc(char *page, char **start, off_t off, - int count, int *eof, struct capi_ctr *ctrl) +static int b1dmactl_proc_show(struct seq_file *m, void *v) { + struct capi_ctr *ctrl = m->private; avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; u8 flag; - int len = 0; char *s; u32 txoff, txlen, rxoff, rxlen, csr; unsigned long flags; - len += sprintf(page+len, "%-16s %s\n", "name", card->name); - len += sprintf(page+len, "%-16s 0x%x\n", "io", card->port); - len += sprintf(page+len, "%-16s %d\n", "irq", card->irq); - len += sprintf(page+len, "%-16s 0x%lx\n", "membase", card->membase); + seq_printf(m, "%-16s %s\n", "name", card->name); + seq_printf(m, "%-16s 0x%x\n", "io", card->port); + seq_printf(m, "%-16s %d\n", "irq", card->irq); + seq_printf(m, "%-16s 0x%lx\n", "membase", card->membase); switch (card->cardtype) { case avm_b1isa: s = "B1 ISA"; break; case avm_b1pci: s = "B1 PCI"; break; @@ -882,18 +883,18 @@ int b1dmactl_read_proc(char *page, char **start, off_t off, case avm_c2: s = "C2"; break; default: s = "???"; break; } - len += sprintf(page+len, "%-16s %s\n", "type", s); + seq_printf(m, "%-16s %s\n", "type", s); if ((s = cinfo->version[VER_DRIVER]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_driver", s); + seq_printf(m, "%-16s %s\n", "ver_driver", s); if ((s = cinfo->version[VER_CARDTYPE]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s); + seq_printf(m, "%-16s %s\n", "ver_cardtype", s); if ((s = cinfo->version[VER_SERIAL]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_serial", s); + seq_printf(m, "%-16s %s\n", "ver_serial", s); if (card->cardtype != avm_m1) { flag = ((u8 *)(ctrl->profile.manu))[3]; if (flag) - len += sprintf(page+len, "%-16s%s%s%s%s%s%s%s\n", + seq_printf(m, "%-16s%s%s%s%s%s%s%s\n", "protocol", (flag & 0x01) ? " DSS1" : "", (flag & 0x02) ? " CT1" : "", @@ -907,7 +908,7 @@ int b1dmactl_read_proc(char *page, char **start, off_t off, if (card->cardtype != avm_m1) { flag = ((u8 *)(ctrl->profile.manu))[5]; if (flag) - len += sprintf(page+len, "%-16s%s%s%s%s\n", + seq_printf(m, "%-16s%s%s%s%s\n", "linetype", (flag & 0x01) ? " point to point" : "", (flag & 0x02) ? " point to multipoint" : "", @@ -915,7 +916,7 @@ int b1dmactl_read_proc(char *page, char **start, off_t off, (flag & 0x04) ? " leased line with D-channel" : "" ); } - len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname); + seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname); spin_lock_irqsave(&card->lock, flags); @@ -930,27 +931,30 @@ int b1dmactl_read_proc(char *page, char **start, off_t off, spin_unlock_irqrestore(&card->lock, flags); - len += sprintf(page+len, "%-16s 0x%lx\n", - "csr (cached)", (unsigned long)card->csr); - len += sprintf(page+len, "%-16s 0x%lx\n", - "csr", (unsigned long)csr); - len += sprintf(page+len, "%-16s %lu\n", - "txoff", (unsigned long)txoff); - len += sprintf(page+len, "%-16s %lu\n", - "txlen", (unsigned long)txlen); - len += sprintf(page+len, "%-16s %lu\n", - "rxoff", (unsigned long)rxoff); - len += sprintf(page+len, "%-16s %lu\n", - "rxlen", (unsigned long)rxlen); - - if (off+count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len-off) ? count : len-off); + seq_printf(m, "%-16s 0x%lx\n", "csr (cached)", (unsigned long)card->csr); + seq_printf(m, "%-16s 0x%lx\n", "csr", (unsigned long)csr); + seq_printf(m, "%-16s %lu\n", "txoff", (unsigned long)txoff); + seq_printf(m, "%-16s %lu\n", "txlen", (unsigned long)txlen); + seq_printf(m, "%-16s %lu\n", "rxoff", (unsigned long)rxoff); + seq_printf(m, "%-16s %lu\n", "rxlen", (unsigned long)rxlen); + + return 0; +} + +static int b1dmactl_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, b1dmactl_proc_show, PDE(inode)->data); } +const struct file_operations b1dmactl_proc_fops = { + .owner = THIS_MODULE, + .open = b1dmactl_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +EXPORT_SYMBOL(b1dmactl_proc_fops); + /* ------------------------------------------------------------- */ EXPORT_SYMBOL(b1dma_reset); @@ -963,7 +967,6 @@ EXPORT_SYMBOL(b1dma_reset_ctr); EXPORT_SYMBOL(b1dma_register_appl); EXPORT_SYMBOL(b1dma_release_appl); EXPORT_SYMBOL(b1dma_send_message); -EXPORT_SYMBOL(b1dmactl_read_proc); static int __init b1dma_init(void) { diff --git a/drivers/isdn/hardware/avm/b1isa.c b/drivers/isdn/hardware/avm/b1isa.c index 6461a32bc838..ff5390546f92 100644 --- a/drivers/isdn/hardware/avm/b1isa.c +++ b/drivers/isdn/hardware/avm/b1isa.c @@ -121,7 +121,7 @@ static int b1isa_probe(struct pci_dev *pdev) cinfo->capi_ctrl.load_firmware = b1_load_firmware; cinfo->capi_ctrl.reset_ctr = b1_reset_ctr; cinfo->capi_ctrl.procinfo = b1isa_procinfo; - cinfo->capi_ctrl.ctr_read_proc = b1ctl_read_proc; + cinfo->capi_ctrl.proc_fops = &b1ctl_proc_fops; strcpy(cinfo->capi_ctrl.name, card->name); retval = attach_capi_ctr(&cinfo->capi_ctrl); diff --git a/drivers/isdn/hardware/avm/b1pci.c b/drivers/isdn/hardware/avm/b1pci.c index 5b314a2c4049..c97e4315079d 100644 --- a/drivers/isdn/hardware/avm/b1pci.c +++ b/drivers/isdn/hardware/avm/b1pci.c @@ -112,7 +112,7 @@ static int b1pci_probe(struct capicardparams *p, struct pci_dev *pdev) cinfo->capi_ctrl.load_firmware = b1_load_firmware; cinfo->capi_ctrl.reset_ctr = b1_reset_ctr; cinfo->capi_ctrl.procinfo = b1pci_procinfo; - cinfo->capi_ctrl.ctr_read_proc = b1ctl_read_proc; + cinfo->capi_ctrl.proc_fops = &b1ctl_proc_fops; strcpy(cinfo->capi_ctrl.name, card->name); cinfo->capi_ctrl.owner = THIS_MODULE; @@ -251,7 +251,7 @@ static int b1pciv4_probe(struct capicardparams *p, struct pci_dev *pdev) cinfo->capi_ctrl.load_firmware = b1dma_load_firmware; cinfo->capi_ctrl.reset_ctr = b1dma_reset_ctr; cinfo->capi_ctrl.procinfo = b1pciv4_procinfo; - cinfo->capi_ctrl.ctr_read_proc = b1dmactl_read_proc; + cinfo->capi_ctrl.proc_fops = &b1dmactl_proc_fops; strcpy(cinfo->capi_ctrl.name, card->name); retval = attach_capi_ctr(&cinfo->capi_ctrl); diff --git a/drivers/isdn/hardware/avm/b1pcmcia.c b/drivers/isdn/hardware/avm/b1pcmcia.c index 7740403b40e1..d6391e0afeea 100644 --- a/drivers/isdn/hardware/avm/b1pcmcia.c +++ b/drivers/isdn/hardware/avm/b1pcmcia.c @@ -108,7 +108,7 @@ static int b1pcmcia_add_card(unsigned int port, unsigned irq, cinfo->capi_ctrl.load_firmware = b1_load_firmware; cinfo->capi_ctrl.reset_ctr = b1_reset_ctr; cinfo->capi_ctrl.procinfo = b1pcmcia_procinfo; - cinfo->capi_ctrl.ctr_read_proc = b1ctl_read_proc; + cinfo->capi_ctrl.proc_fops = &b1ctl_proc_fops; strcpy(cinfo->capi_ctrl.name, card->name); retval = attach_capi_ctr(&cinfo->capi_ctrl); diff --git a/drivers/isdn/hardware/avm/c4.c b/drivers/isdn/hardware/avm/c4.c index 6833301a45fc..de6e6b311819 100644 --- a/drivers/isdn/hardware/avm/c4.c +++ b/drivers/isdn/hardware/avm/c4.c @@ -11,6 +11,8 @@ #include #include +#include +#include #include #include #include @@ -1062,19 +1064,18 @@ static char *c4_procinfo(struct capi_ctr *ctrl) return cinfo->infobuf; } -static int c4_read_proc(char *page, char **start, off_t off, - int count, int *eof, struct capi_ctr *ctrl) +static int c4_proc_show(struct seq_file *m, void *v) { + struct capi_ctr *ctrl = m->private; avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); avmcard *card = cinfo->card; u8 flag; - int len = 0; char *s; - len += sprintf(page+len, "%-16s %s\n", "name", card->name); - len += sprintf(page+len, "%-16s 0x%x\n", "io", card->port); - len += sprintf(page+len, "%-16s %d\n", "irq", card->irq); - len += sprintf(page+len, "%-16s 0x%lx\n", "membase", card->membase); + seq_printf(m, "%-16s %s\n", "name", card->name); + seq_printf(m, "%-16s 0x%x\n", "io", card->port); + seq_printf(m, "%-16s %d\n", "irq", card->irq); + seq_printf(m, "%-16s 0x%lx\n", "membase", card->membase); switch (card->cardtype) { case avm_b1isa: s = "B1 ISA"; break; case avm_b1pci: s = "B1 PCI"; break; @@ -1087,18 +1088,18 @@ static int c4_read_proc(char *page, char **start, off_t off, case avm_c2: s = "C2"; break; default: s = "???"; break; } - len += sprintf(page+len, "%-16s %s\n", "type", s); + seq_printf(m, "%-16s %s\n", "type", s); if ((s = cinfo->version[VER_DRIVER]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_driver", s); + seq_printf(m, "%-16s %s\n", "ver_driver", s); if ((s = cinfo->version[VER_CARDTYPE]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s); + seq_printf(m, "%-16s %s\n", "ver_cardtype", s); if ((s = cinfo->version[VER_SERIAL]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_serial", s); + seq_printf(m, "%-16s %s\n", "ver_serial", s); if (card->cardtype != avm_m1) { flag = ((u8 *)(ctrl->profile.manu))[3]; if (flag) - len += sprintf(page+len, "%-16s%s%s%s%s%s%s%s\n", + seq_printf(m, "%-16s%s%s%s%s%s%s%s\n", "protocol", (flag & 0x01) ? " DSS1" : "", (flag & 0x02) ? " CT1" : "", @@ -1112,7 +1113,7 @@ static int c4_read_proc(char *page, char **start, off_t off, if (card->cardtype != avm_m1) { flag = ((u8 *)(ctrl->profile.manu))[5]; if (flag) - len += sprintf(page+len, "%-16s%s%s%s%s\n", + seq_printf(m, "%-16s%s%s%s%s\n", "linetype", (flag & 0x01) ? " point to point" : "", (flag & 0x02) ? " point to multipoint" : "", @@ -1120,16 +1121,24 @@ static int c4_read_proc(char *page, char **start, off_t off, (flag & 0x04) ? " leased line with D-channel" : "" ); } - len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname); - - if (off+count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len-off) ? count : len-off); + seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname); + + return 0; } +static int c4_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, c4_proc_show, PDE(inode)->data); +} + +static const struct file_operations c4_proc_fops = { + .owner = THIS_MODULE, + .open = c4_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + /* ------------------------------------------------------------- */ static int c4_add_card(struct capicardparams *p, struct pci_dev *dev, @@ -1201,7 +1210,7 @@ static int c4_add_card(struct capicardparams *p, struct pci_dev *dev, cinfo->capi_ctrl.load_firmware = c4_load_firmware; cinfo->capi_ctrl.reset_ctr = c4_reset_ctr; cinfo->capi_ctrl.procinfo = c4_procinfo; - cinfo->capi_ctrl.ctr_read_proc = c4_read_proc; + cinfo->capi_ctrl.proc_fops = &c4_proc_fops; strcpy(cinfo->capi_ctrl.name, card->name); retval = attach_capi_ctr(&cinfo->capi_ctrl); diff --git a/drivers/isdn/hardware/avm/t1isa.c b/drivers/isdn/hardware/avm/t1isa.c index 1c53fd49adb6..baeeb3c2a3ee 100644 --- a/drivers/isdn/hardware/avm/t1isa.c +++ b/drivers/isdn/hardware/avm/t1isa.c @@ -429,7 +429,7 @@ static int t1isa_probe(struct pci_dev *pdev, int cardnr) cinfo->capi_ctrl.load_firmware = t1isa_load_firmware; cinfo->capi_ctrl.reset_ctr = t1isa_reset_ctr; cinfo->capi_ctrl.procinfo = t1isa_procinfo; - cinfo->capi_ctrl.ctr_read_proc = b1ctl_read_proc; + cinfo->capi_ctrl.proc_fops = &b1ctl_proc_fops; strcpy(cinfo->capi_ctrl.name, card->name); retval = attach_capi_ctr(&cinfo->capi_ctrl); diff --git a/drivers/isdn/hardware/avm/t1pci.c b/drivers/isdn/hardware/avm/t1pci.c index e6d298d75146..5a3f83098018 100644 --- a/drivers/isdn/hardware/avm/t1pci.c +++ b/drivers/isdn/hardware/avm/t1pci.c @@ -119,7 +119,7 @@ static int t1pci_add_card(struct capicardparams *p, struct pci_dev *pdev) cinfo->capi_ctrl.load_firmware = b1dma_load_firmware; cinfo->capi_ctrl.reset_ctr = b1dma_reset_ctr; cinfo->capi_ctrl.procinfo = t1pci_procinfo; - cinfo->capi_ctrl.ctr_read_proc = b1dmactl_read_proc; + cinfo->capi_ctrl.proc_fops = &b1dmactl_proc_fops; strcpy(cinfo->capi_ctrl.name, card->name); retval = attach_capi_ctr(&cinfo->capi_ctrl); diff --git a/drivers/isdn/hardware/eicon/capimain.c b/drivers/isdn/hardware/eicon/capimain.c index 98fcdfc7ca55..0f073cd73763 100644 --- a/drivers/isdn/hardware/eicon/capimain.c +++ b/drivers/isdn/hardware/eicon/capimain.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "os_capi.h" @@ -75,25 +76,32 @@ void diva_os_free_message_buffer(diva_os_message_buffer_s * dmb) /* * proc function for controller info */ -static int diva_ctl_read_proc(char *page, char **start, off_t off, - int count, int *eof, struct capi_ctr *ctrl) +static int diva_ctl_proc_show(struct seq_file *m, void *v) { + struct capi_ctr *ctrl = m->private; diva_card *card = (diva_card *) ctrl->driverdata; - int len = 0; - - len += sprintf(page + len, "%s\n", ctrl->name); - len += sprintf(page + len, "Serial No. : %s\n", ctrl->serial); - len += sprintf(page + len, "Id : %d\n", card->Id); - len += sprintf(page + len, "Channels : %d\n", card->d.channels); - - if (off + count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len - off) ? count : len - off); + + seq_printf(m, "%s\n", ctrl->name); + seq_printf(m, "Serial No. : %s\n", ctrl->serial); + seq_printf(m, "Id : %d\n", card->Id); + seq_printf(m, "Channels : %d\n", card->d.channels); + + return 0; +} + +static int diva_ctl_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, diva_ctl_proc_show, NULL); } +static const struct file_operations diva_ctl_proc_fops = { + .owner = THIS_MODULE, + .open = diva_ctl_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + /* * set additional os settings in capi_ctr struct */ @@ -102,7 +110,7 @@ void diva_os_set_controller_struct(struct capi_ctr *ctrl) ctrl->driver_name = DRIVERLNAME; ctrl->load_firmware = NULL; ctrl->reset_ctr = NULL; - ctrl->ctr_read_proc = diva_ctl_read_proc; + ctrl->proc_fops = &diva_ctl_proc_fops; ctrl->owner = THIS_MODULE; } diff --git a/drivers/isdn/hardware/eicon/diva_didd.c b/drivers/isdn/hardware/eicon/diva_didd.c index 993b14cf1778..5d06a7437824 100644 --- a/drivers/isdn/hardware/eicon/diva_didd.c +++ b/drivers/isdn/hardware/eicon/diva_didd.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "platform.h" @@ -62,39 +63,41 @@ static char *getrev(const char *revision) return rev; } -static int -proc_read(char *page, char **start, off_t off, int count, int *eof, - void *data) +static int divadidd_proc_show(struct seq_file *m, void *v) { - int len = 0; char tmprev[32]; strcpy(tmprev, main_revision); - len += sprintf(page + len, "%s\n", DRIVERNAME); - len += sprintf(page + len, "name : %s\n", DRIVERLNAME); - len += sprintf(page + len, "release : %s\n", DRIVERRELEASE_DIDD); - len += sprintf(page + len, "build : %s(%s)\n", + seq_printf(m, "%s\n", DRIVERNAME); + seq_printf(m, "name : %s\n", DRIVERLNAME); + seq_printf(m, "release : %s\n", DRIVERRELEASE_DIDD); + seq_printf(m, "build : %s(%s)\n", diva_didd_common_code_build, DIVA_BUILD); - len += sprintf(page + len, "revision : %s\n", getrev(tmprev)); - - if (off + count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len - off) ? count : len - off); + seq_printf(m, "revision : %s\n", getrev(tmprev)); + + return 0; } +static int divadidd_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, divadidd_proc_show, NULL); +} + +static const struct file_operations divadidd_proc_fops = { + .owner = THIS_MODULE, + .open = divadidd_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static int DIVA_INIT_FUNCTION create_proc(void) { proc_net_eicon = proc_mkdir("eicon", init_net.proc_net); if (proc_net_eicon) { - if ((proc_didd = - create_proc_entry(DRIVERLNAME, S_IFREG | S_IRUGO, - proc_net_eicon))) { - proc_didd->read_proc = proc_read; - } + proc_didd = proc_create(DRIVERLNAME, S_IRUGO, proc_net_eicon, + &divadidd_proc_fops); return (1); } return (0); diff --git a/drivers/isdn/hardware/eicon/divasi.c b/drivers/isdn/hardware/eicon/divasi.c index 69e71ebe7841..f577719ab3fa 100644 --- a/drivers/isdn/hardware/eicon/divasi.c +++ b/drivers/isdn/hardware/eicon/divasi.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -86,39 +87,40 @@ static void diva_um_timer_function(unsigned long data); extern struct proc_dir_entry *proc_net_eicon; static struct proc_dir_entry *um_idi_proc_entry = NULL; -static int -um_idi_proc_read(char *page, char **start, off_t off, int count, int *eof, - void *data) +static int um_idi_proc_show(struct seq_file *m, void *v) { - int len = 0; char tmprev[32]; - len += sprintf(page + len, "%s\n", DRIVERNAME); - len += sprintf(page + len, "name : %s\n", DRIVERLNAME); - len += sprintf(page + len, "release : %s\n", DRIVERRELEASE_IDI); + seq_printf(m, "%s\n", DRIVERNAME); + seq_printf(m, "name : %s\n", DRIVERLNAME); + seq_printf(m, "release : %s\n", DRIVERRELEASE_IDI); strcpy(tmprev, main_revision); - len += sprintf(page + len, "revision : %s\n", getrev(tmprev)); - len += sprintf(page + len, "build : %s\n", DIVA_BUILD); - len += sprintf(page + len, "major : %d\n", major); - - if (off + count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len - off) ? count : len - off); + seq_printf(m, "revision : %s\n", getrev(tmprev)); + seq_printf(m, "build : %s\n", DIVA_BUILD); + seq_printf(m, "major : %d\n", major); + + return 0; +} + +static int um_idi_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, um_idi_proc_show, NULL); } +static const struct file_operations um_idi_proc_fops = { + .owner = THIS_MODULE, + .open = um_idi_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static int DIVA_INIT_FUNCTION create_um_idi_proc(void) { - um_idi_proc_entry = create_proc_entry(DRIVERLNAME, - S_IFREG | S_IRUGO | S_IWUSR, - proc_net_eicon); + um_idi_proc_entry = proc_create(DRIVERLNAME, S_IRUGO, proc_net_eicon, + &um_idi_proc_fops); if (!um_idi_proc_entry) return (0); - - um_idi_proc_entry->read_proc = um_idi_proc_read; - return (1); } diff --git a/drivers/isdn/hardware/eicon/divasproc.c b/drivers/isdn/hardware/eicon/divasproc.c index 040827288ec9..46d44a942624 100644 --- a/drivers/isdn/hardware/eicon/divasproc.c +++ b/drivers/isdn/hardware/eicon/divasproc.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -141,14 +142,10 @@ void remove_divas_proc(void) } } -/* -** write group_optimization -*/ -static int -write_grp_opt(struct file *file, const char __user *buffer, unsigned long count, - void *data) +static ssize_t grp_opt_proc_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data; + diva_os_xdi_adapter_t *a = PDE(file->f_path.dentry->d_inode)->data; PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1]; if ((count == 1) || (count == 2)) { @@ -172,14 +169,10 @@ write_grp_opt(struct file *file, const char __user *buffer, unsigned long count, return (-EINVAL); } -/* -** write dynamic_l1_down -*/ -static int -write_d_l1_down(struct file *file, const char __user *buffer, unsigned long count, - void *data) +static ssize_t d_l1_down_proc_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data; + diva_os_xdi_adapter_t *a = PDE(file->f_path.dentry->d_inode)->data; PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1]; if ((count == 1) || (count == 2)) { @@ -203,63 +196,62 @@ write_d_l1_down(struct file *file, const char __user *buffer, unsigned long coun return (-EINVAL); } - -/* -** read dynamic_l1_down -*/ -static int -read_d_l1_down(char *page, char **start, off_t off, int count, int *eof, - void *data) +static int d_l1_down_proc_show(struct seq_file *m, void *v) { - int len = 0; - diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data; + diva_os_xdi_adapter_t *a = m->private; PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1]; - len += sprintf(page + len, "%s\n", + seq_printf(m, "%s\n", (IoAdapter->capi_cfg. cfg_1 & DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON) ? "1" : "0"); + return 0; +} - if (off + count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len - off) ? count : len - off); +static int d_l1_down_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, d_l1_down_proc_show, PDE(inode)->data); } -/* -** read group_optimization -*/ -static int -read_grp_opt(char *page, char **start, off_t off, int count, int *eof, - void *data) +static const struct file_operations d_l1_down_proc_fops = { + .owner = THIS_MODULE, + .open = d_l1_down_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .write = d_l1_down_proc_write, +}; + +static int grp_opt_proc_show(struct seq_file *m, void *v) { - int len = 0; - diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data; + diva_os_xdi_adapter_t *a = m->private; PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1]; - len += sprintf(page + len, "%s\n", + seq_printf(m, "%s\n", (IoAdapter->capi_cfg. cfg_1 & DIVA_XDI_CAPI_CFG_1_GROUP_POPTIMIZATION_ON) ? "1" : "0"); + return 0; +} - if (off + count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len - off) ? count : len - off); +static int grp_opt_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, grp_opt_proc_show, PDE(inode)->data); } -/* -** info write -*/ -static int -info_write(struct file *file, const char __user *buffer, unsigned long count, - void *data) +static const struct file_operations grp_opt_proc_fops = { + .owner = THIS_MODULE, + .open = grp_opt_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .write = grp_opt_proc_write, +}; + +static ssize_t info_proc_write(struct file *file, const char __user *buffer, + size_t count, loff_t *pos) { - diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data; + diva_os_xdi_adapter_t *a = PDE(file->f_path.dentry->d_inode)->data; PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1]; char c[4]; @@ -277,63 +269,46 @@ info_write(struct file *file, const char __user *buffer, unsigned long count, return (-EINVAL); } -/* -** info read -*/ -static int -info_read(char *page, char **start, off_t off, int count, int *eof, - void *data) +static int info_proc_show(struct seq_file *m, void *v) { int i = 0; - int len = 0; char *p; char tmpser[16]; - diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) data; + diva_os_xdi_adapter_t *a = m->private; PISDN_ADAPTER IoAdapter = IoAdapters[a->controller - 1]; - len += - sprintf(page + len, "Name : %s\n", - IoAdapter->Properties.Name); - len += sprintf(page + len, "DSP state : %08x\n", a->dsp_mask); - len += sprintf(page + len, "Channels : %02d\n", - IoAdapter->Properties.Channels); - len += sprintf(page + len, "E. max/used : %03d/%03d\n", + seq_printf(m, "Name : %s\n", IoAdapter->Properties.Name); + seq_printf(m, "DSP state : %08x\n", a->dsp_mask); + seq_printf(m, "Channels : %02d\n", IoAdapter->Properties.Channels); + seq_printf(m, "E. max/used : %03d/%03d\n", IoAdapter->e_max, IoAdapter->e_count); diva_get_vserial_number(IoAdapter, tmpser); - len += sprintf(page + len, "Serial : %s\n", tmpser); - len += - sprintf(page + len, "IRQ : %d\n", - IoAdapter->irq_info.irq_nr); - len += sprintf(page + len, "CardIndex : %d\n", a->CardIndex); - len += sprintf(page + len, "CardOrdinal : %d\n", a->CardOrdinal); - len += sprintf(page + len, "Controller : %d\n", a->controller); - len += sprintf(page + len, "Bus-Type : %s\n", + seq_printf(m, "Serial : %s\n", tmpser); + seq_printf(m, "IRQ : %d\n", IoAdapter->irq_info.irq_nr); + seq_printf(m, "CardIndex : %d\n", a->CardIndex); + seq_printf(m, "CardOrdinal : %d\n", a->CardOrdinal); + seq_printf(m, "Controller : %d\n", a->controller); + seq_printf(m, "Bus-Type : %s\n", (a->Bus == DIVAS_XDI_ADAPTER_BUS_ISA) ? "ISA" : "PCI"); - len += sprintf(page + len, "Port-Name : %s\n", a->port_name); + seq_printf(m, "Port-Name : %s\n", a->port_name); if (a->Bus == DIVAS_XDI_ADAPTER_BUS_PCI) { - len += - sprintf(page + len, "PCI-bus : %d\n", - a->resources.pci.bus); - len += - sprintf(page + len, "PCI-func : %d\n", - a->resources.pci.func); + seq_printf(m, "PCI-bus : %d\n", a->resources.pci.bus); + seq_printf(m, "PCI-func : %d\n", a->resources.pci.func); for (i = 0; i < 8; i++) { if (a->resources.pci.bar[i]) { - len += - sprintf(page + len, + seq_printf(m, "Mem / I/O %d : 0x%x / mapped : 0x%lx", i, a->resources.pci.bar[i], (unsigned long) a->resources. pci.addr[i]); if (a->resources.pci.length[i]) { - len += - sprintf(page + len, + seq_printf(m, " / length : %d", a->resources.pci. length[i]); } - len += sprintf(page + len, "\n"); + seq_putc(m, '\n'); } } } @@ -353,16 +328,25 @@ info_read(char *page, char **start, off_t off, int count, int *eof, } else { p = "ready"; } - len += sprintf(page + len, "State : %s\n", p); + seq_printf(m, "State : %s\n", p); - if (off + count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len - off) ? count : len - off); + return 0; +} + +static int info_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, info_proc_show, PDE(inode)->data); } +static const struct file_operations info_proc_fops = { + .owner = THIS_MODULE, + .open = info_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .write = info_proc_write, +}; + /* ** adapter proc init/de-init */ @@ -380,28 +364,20 @@ int create_adapter_proc(diva_os_xdi_adapter_t * a) return (0); a->proc_adapter_dir = (void *) de; - if (!(pe = - create_proc_entry(info_proc_name, S_IFREG | S_IRUGO | S_IWUSR, de))) + pe = proc_create_data(info_proc_name, S_IRUGO | S_IWUSR, de, + &info_proc_fops, a); + if (!pe) return (0); a->proc_info = (void *) pe; - pe->write_proc = info_write; - pe->read_proc = info_read; - pe->data = a; - if ((pe = create_proc_entry(grp_opt_proc_name, - S_IFREG | S_IRUGO | S_IWUSR, de))) { + pe = proc_create_data(grp_opt_proc_name, S_IRUGO | S_IWUSR, de, + &grp_opt_proc_fops, a); + if (pe) a->proc_grp_opt = (void *) pe; - pe->write_proc = write_grp_opt; - pe->read_proc = read_grp_opt; - pe->data = a; - } - if ((pe = create_proc_entry(d_l1_down_proc_name, - S_IFREG | S_IRUGO | S_IWUSR, de))) { + pe = proc_create_data(d_l1_down_proc_name, S_IRUGO | S_IWUSR, de, + &d_l1_down_proc_fops, a); + if (pe) a->proc_d_l1_down = (void *) pe; - pe->write_proc = write_d_l1_down; - pe->read_proc = read_d_l1_down; - pe->data = a; - } DBG_TRC(("proc entry %s created", tmp)); diff --git a/drivers/isdn/hysdn/hycapi.c b/drivers/isdn/hysdn/hycapi.c index 4ffaa14b9fc4..fe874afa4f81 100644 --- a/drivers/isdn/hysdn/hycapi.c +++ b/drivers/isdn/hysdn/hycapi.c @@ -11,6 +11,8 @@ */ #include +#include +#include #include #include #include @@ -432,26 +434,16 @@ static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) return retval; } -/********************************************************************* -hycapi_read_proc - -Informations provided in the /proc/capi-entries. - -*********************************************************************/ - -static int hycapi_read_proc(char *page, char **start, off_t off, - int count, int *eof, struct capi_ctr *ctrl) +static int hycapi_proc_show(struct seq_file *m, void *v) { + struct capi_ctr *ctrl = m->private; hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata); hysdn_card *card = cinfo->card; - int len = 0; char *s; -#ifdef HYCAPI_PRINTFNAMES - printk(KERN_NOTICE "hycapi_read_proc\n"); -#endif - len += sprintf(page+len, "%-16s %s\n", "name", cinfo->cardname); - len += sprintf(page+len, "%-16s 0x%x\n", "io", card->iobase); - len += sprintf(page+len, "%-16s %d\n", "irq", card->irq); + + seq_printf(m, "%-16s %s\n", "name", cinfo->cardname); + seq_printf(m, "%-16s 0x%x\n", "io", card->iobase); + seq_printf(m, "%-16s %d\n", "irq", card->irq); switch (card->brdtype) { case BD_PCCARD: s = "HYSDN Hycard"; break; @@ -461,24 +453,32 @@ static int hycapi_read_proc(char *page, char **start, off_t off, case BD_PLEXUS: s = "HYSDN Plexus30"; break; default: s = "???"; break; } - len += sprintf(page+len, "%-16s %s\n", "type", s); + seq_printf(m, "%-16s %s\n", "type", s); if ((s = cinfo->version[VER_DRIVER]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_driver", s); + seq_printf(m, "%-16s %s\n", "ver_driver", s); if ((s = cinfo->version[VER_CARDTYPE]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s); + seq_printf(m, "%-16s %s\n", "ver_cardtype", s); if ((s = cinfo->version[VER_SERIAL]) != NULL) - len += sprintf(page+len, "%-16s %s\n", "ver_serial", s); + seq_printf(m, "%-16s %s\n", "ver_serial", s); - len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname); + seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname); - if (off+count >= len) - *eof = 1; - if (len < off) - return 0; - *start = page + off; - return ((count < len-off) ? count : len-off); + return 0; +} + +static int hycapi_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, hycapi_proc_show, PDE(inode)->data); } +static const struct file_operations hycapi_proc_fops = { + .owner = THIS_MODULE, + .open = hycapi_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + /************************************************************** hycapi_load_firmware @@ -774,7 +774,7 @@ hycapi_capi_create(hysdn_card *card) ctrl->load_firmware = hycapi_load_firmware; ctrl->reset_ctr = hycapi_reset_ctr; ctrl->procinfo = hycapi_procinfo; - ctrl->ctr_read_proc = hycapi_read_proc; + ctrl->proc_fops = &hycapi_proc_fops; strcpy(ctrl->name, cinfo->cardname); ctrl->owner = THIS_MODULE; -- cgit v1.2.3 From e23e11792a77c7d54f363841cd5e33074fb0c8c9 Mon Sep 17 00:00:00 2001 From: Roel Kluin Date: Tue, 2 Feb 2010 12:43:44 +0000 Subject: hisax: timeout off by one in waitrecmsg() With `while (timeout++ < maxdelay)' timeout reaches maxdelay + 1 after the loop This is probably unlikely a problem in practice. Signed-off-by: Roel Kluin Cc: Karsten Keil Signed-off-by: Andrew Morton Signed-off-by: David S. Miller --- drivers/isdn/hisax/isar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c index bfeb9b6aa043..6bde16c00fb5 100644 --- a/drivers/isdn/hisax/isar.c +++ b/drivers/isdn/hisax/isar.c @@ -138,7 +138,7 @@ waitrecmsg(struct IsdnCardState *cs, u_char *len, while((!(cs->BC_Read_Reg(cs, 0, ISAR_IRQBIT) & ISAR_IRQSTA)) && (timeout++ < maxdelay)) udelay(1); - if (timeout >= maxdelay) { + if (timeout > maxdelay) { printk(KERN_WARNING"isar recmsg IRQSTA timeout\n"); return(0); } -- cgit v1.2.3 From f0f4d641d4ebfeb4194e9c26dfa6286802e2e8d1 Mon Sep 17 00:00:00 2001 From: Darren Jenkins Date: Tue, 2 Feb 2010 12:43:45 +0000 Subject: hardware/mISDN/mISDNinfineon.c: bail out of loop on error If setup_instance() fails we kfree() the card, and then use it in the next loop iteration. So lets bail out of the loop instead. Coverity CID: 13357 Signed-off-by: Darren Jenkins Cc: Karsten Keil Signed-off-by: Andrew Morton Signed-off-by: David S. Miller --- drivers/isdn/hardware/mISDN/mISDNinfineon.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/isdn') diff --git a/drivers/isdn/hardware/mISDN/mISDNinfineon.c b/drivers/isdn/hardware/mISDN/mISDNinfineon.c index 62441ba53b95..36c6c616a655 100644 --- a/drivers/isdn/hardware/mISDN/mISDNinfineon.c +++ b/drivers/isdn/hardware/mISDN/mISDNinfineon.c @@ -1133,6 +1133,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (err) { kfree(sc); release_card(card); + break; } else card->sc[i - 1] = sc; } -- cgit v1.2.3 From 3e5981774755f2f967cd1d3f3898576cff20e565 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Tue, 2 Feb 2010 12:43:46 +0000 Subject: isdn: mISDN, don't compile unused stuff Remove these compiler warnings: drivers/isdn/hardware/mISDN/w6692.c:534: warning: `setvolume' defined but not used drivers/isdn/hardware/mISDN/w6692.c:561: warning: `enable_pots' defined but not used by moving the functions inside #if 0 ... #endif. And an alternative is to remove them completely if nobody has plans to use them. Signed-off-by: Jiri Slaby Cc: Karsten Keil Signed-off-by: Andrew Morton Signed-off-by: David S. Miller --- drivers/isdn/hardware/mISDN/w6692.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/isdn') diff --git a/drivers/isdn/hardware/mISDN/w6692.c b/drivers/isdn/hardware/mISDN/w6692.c index d3f1077b709b..2952a58c7a61 100644 --- a/drivers/isdn/hardware/mISDN/w6692.c +++ b/drivers/isdn/hardware/mISDN/w6692.c @@ -529,6 +529,7 @@ W6692_fill_Bfifo(struct w6692_ch *wch) } } +#if 0 static int setvolume(struct w6692_ch *wch, int mic, struct sk_buff *skb) { @@ -571,6 +572,7 @@ enable_pots(struct w6692_ch *wch) WriteW6692(card, W_PCTL, card->pctl); return 0; } +#endif static int disable_pots(struct w6692_ch *wch) -- cgit v1.2.3 From 650b2ef5d7f1378f65e6a313909d783e4b6477ed Mon Sep 17 00:00:00 2001 From: Roel Kluin Date: Tue, 2 Feb 2010 12:43:47 +0000 Subject: mISDN: positive error return should be negative in mode_hfcmulti() The error return should be negative. Its only caller that acts upon its return, handle_bmsg(), transmits the positive error but can also return negative errors. Signed-off-by: Roel Kluin Cc: Karsten Keil Signed-off-by: Andrew Morton Signed-off-by: David S. Miller --- drivers/isdn/hardware/mISDN/hfcmulti.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/hardware/mISDN/hfcmulti.c b/drivers/isdn/hardware/mISDN/hfcmulti.c index 1a1420d7a828..ad36df9b759c 100644 --- a/drivers/isdn/hardware/mISDN/hfcmulti.c +++ b/drivers/isdn/hardware/mISDN/hfcmulti.c @@ -2846,7 +2846,7 @@ mode_hfcmulti(struct hfc_multi *hc, int ch, int protocol, int slot_tx, int conf; if (ch < 0 || ch > 31) - return EINVAL; + return -EINVAL; oslot_tx = hc->chan[ch].slot_tx; oslot_rx = hc->chan[ch].slot_rx; conf = hc->chan[ch].conf; -- cgit v1.2.3 From c947862f9126983537a4cc11e07d26882d60b7e7 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:05 +0000 Subject: CAPI: Fix leaks in capifs_new_ncci When something went wrong during capifs_new_ncci, the looked up dentry was not properly released. Neither was the allocated inode. Refactor the function to avoid leaks. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capifs.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capifs.c b/drivers/isdn/capi/capifs.c index 9f8f67b6c07f..dc68fcb122a0 100644 --- a/drivers/isdn/capi/capifs.c +++ b/drivers/isdn/capi/capifs.c @@ -152,22 +152,33 @@ static struct dentry *get_node(int num) void capifs_new_ncci(unsigned int number, dev_t device) { struct dentry *dentry; - struct inode *inode = new_inode(capifs_mnt->mnt_sb); - if (!inode) - return; - inode->i_ino = number+2; + struct inode *inode; dentry = get_node(number); + if (IS_ERR(dentry)) + goto unlock_out; + + if (dentry->d_inode) { + dput(dentry); + goto unlock_out; + } + + inode = new_inode(capifs_mnt->mnt_sb); + if (!inode) { + dput(dentry); + goto unlock_out; + } /* config contents is protected by root's i_mutex */ inode->i_uid = config.setuid ? config.uid : current_fsuid(); inode->i_gid = config.setgid ? config.gid : current_fsgid(); inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; + inode->i_ino = number + 2; init_special_inode(inode, S_IFCHR|config.mode, device); - //inode->i_op = &capifs_file_inode_operations; - if (!IS_ERR(dentry) && !dentry->d_inode) - d_instantiate(dentry, inode); + d_instantiate(dentry, inode); + +unlock_out: mutex_unlock(&capifs_root->d_inode->i_mutex); } -- cgit v1.2.3 From 90926f0e58dcd9f4ca877961000568a3be787f2f Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:06 +0000 Subject: CAPI: Sanitize capifs API Instead of looking up the dentry of an NCCI node again in capifs_free_ncci pass the pointer via the capifs user. This patch also reduces the #ifdef mess in capi.c a bit as far as capifs was causing it. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 14 ++++++------- drivers/isdn/capi/capifs.c | 50 +++++++++++++++++++++++++++------------------- drivers/isdn/capi/capifs.h | 21 +++++++++++++++++-- 3 files changed, 54 insertions(+), 31 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 79f9364aded6..dc5ac52986ee 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -42,9 +42,8 @@ #include #include #include -#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) + #include "capifs.h" -#endif static char *revision = "$Revision: 1.1.2.7 $"; @@ -96,6 +95,7 @@ struct capiminor { struct list_head list; struct capincci *nccip; unsigned int minor; + struct dentry *capifs_dentry; struct capi20_appl *ap; u32 ncci; @@ -328,9 +328,9 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "set mp->nccip\n"); #endif -#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) - capifs_new_ncci(mp->minor, MKDEV(capi_ttymajor, mp->minor)); -#endif + mp->capifs_dentry = + capifs_new_ncci(mp->minor, + MKDEV(capi_ttymajor, mp->minor)); } #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ for (pp=&cdev->nccis; *pp; pp = &(*pp)->next) @@ -353,9 +353,7 @@ static void capincci_free(struct capidev *cdev, u32 ncci) *pp = (*pp)->next; #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE if ((mp = np->minorp) != NULL) { -#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) - capifs_free_ncci(mp->minor); -#endif + capifs_free_ncci(mp->capifs_dentry); if (mp->tty) { mp->nccip = NULL; #ifdef _DEBUG_REFCOUNT diff --git a/drivers/isdn/capi/capifs.c b/drivers/isdn/capi/capifs.c index dc68fcb122a0..91aafadd413f 100644 --- a/drivers/isdn/capi/capifs.c +++ b/drivers/isdn/capi/capifs.c @@ -141,31 +141,32 @@ static struct file_system_type capifs_fs_type = { .kill_sb = kill_anon_super, }; -static struct dentry *get_node(int num) -{ - char s[10]; - struct dentry *root = capifs_root; - mutex_lock(&root->d_inode->i_mutex); - return lookup_one_len(s, root, sprintf(s, "%d", num)); -} - -void capifs_new_ncci(unsigned int number, dev_t device) +struct dentry *capifs_new_ncci(unsigned int number, dev_t device) { struct dentry *dentry; struct inode *inode; + char name[10]; + int namelen; - dentry = get_node(number); - if (IS_ERR(dentry)) + mutex_lock(&capifs_root->d_inode->i_mutex); + + namelen = sprintf(name, "%d", number); + dentry = lookup_one_len(name, capifs_root, namelen); + if (IS_ERR(dentry)) { + dentry = NULL; goto unlock_out; + } if (dentry->d_inode) { dput(dentry); + dentry = NULL; goto unlock_out; } inode = new_inode(capifs_mnt->mnt_sb); if (!inode) { dput(dentry); + dentry = NULL; goto unlock_out; } @@ -177,24 +178,31 @@ void capifs_new_ncci(unsigned int number, dev_t device) init_special_inode(inode, S_IFCHR|config.mode, device); d_instantiate(dentry, inode); + dget(dentry); unlock_out: mutex_unlock(&capifs_root->d_inode->i_mutex); + + return dentry; } -void capifs_free_ncci(unsigned int number) +void capifs_free_ncci(struct dentry *dentry) { - struct dentry *dentry = get_node(number); - - if (!IS_ERR(dentry)) { - struct inode *inode = dentry->d_inode; - if (inode) { - inode->i_nlink--; - d_delete(dentry); - dput(dentry); - } + struct inode *inode; + + if (!dentry) + return; + + mutex_lock(&capifs_root->d_inode->i_mutex); + + inode = dentry->d_inode; + if (inode) { + drop_nlink(inode); + d_delete(dentry); dput(dentry); } + dput(dentry); + mutex_unlock(&capifs_root->d_inode->i_mutex); } diff --git a/drivers/isdn/capi/capifs.h b/drivers/isdn/capi/capifs.h index d0bd4c3c430a..e193d1189531 100644 --- a/drivers/isdn/capi/capifs.h +++ b/drivers/isdn/capi/capifs.h @@ -7,5 +7,22 @@ * */ -void capifs_new_ncci(unsigned int num, dev_t device); -void capifs_free_ncci(unsigned int num); +#include + +#if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) + +struct dentry *capifs_new_ncci(unsigned int num, dev_t device); +void capifs_free_ncci(struct dentry *dentry); + +#else + +static inline struct dentry *capifs_new_ncci(unsigned int num, dev_t device) +{ + return NULL; +} + +static inline void capifs_free_ncci(struct dentry *dentry) +{ +} + +#endif -- cgit v1.2.3 From 07ad603ab8e3cc35762c15043b59a6ef76542454 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:07 +0000 Subject: CAPI: Eliminate capifs_root variable capifs_mnt->mnt_sb->s_root already contains what we need. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capifs.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capifs.c b/drivers/isdn/capi/capifs.c index 91aafadd413f..6ae0edf29c85 100644 --- a/drivers/isdn/capi/capifs.c +++ b/drivers/isdn/capi/capifs.c @@ -32,7 +32,6 @@ static char *revision = "$Revision: 1.1.2.3 $"; #define CAPIFS_SUPER_MAGIC (('C'<<8)|'N') static struct vfsmount *capifs_mnt; -static struct dentry *capifs_root; static struct { int setuid; @@ -118,7 +117,7 @@ capifs_fill_super(struct super_block *s, void *data, int silent) inode->i_fop = &simple_dir_operations; inode->i_nlink = 2; - capifs_root = s->s_root = d_alloc_root(inode); + s->s_root = d_alloc_root(inode); if (s->s_root) return 0; @@ -143,15 +142,17 @@ static struct file_system_type capifs_fs_type = { struct dentry *capifs_new_ncci(unsigned int number, dev_t device) { + struct super_block *s = capifs_mnt->mnt_sb; + struct dentry *root = s->s_root; struct dentry *dentry; struct inode *inode; char name[10]; int namelen; - mutex_lock(&capifs_root->d_inode->i_mutex); + mutex_lock(&root->d_inode->i_mutex); namelen = sprintf(name, "%d", number); - dentry = lookup_one_len(name, capifs_root, namelen); + dentry = lookup_one_len(name, root, namelen); if (IS_ERR(dentry)) { dentry = NULL; goto unlock_out; @@ -163,7 +164,7 @@ struct dentry *capifs_new_ncci(unsigned int number, dev_t device) goto unlock_out; } - inode = new_inode(capifs_mnt->mnt_sb); + inode = new_inode(s); if (!inode) { dput(dentry); dentry = NULL; @@ -181,19 +182,20 @@ struct dentry *capifs_new_ncci(unsigned int number, dev_t device) dget(dentry); unlock_out: - mutex_unlock(&capifs_root->d_inode->i_mutex); + mutex_unlock(&root->d_inode->i_mutex); return dentry; } void capifs_free_ncci(struct dentry *dentry) { + struct dentry *root = capifs_mnt->mnt_sb->s_root; struct inode *inode; if (!dentry) return; - mutex_lock(&capifs_root->d_inode->i_mutex); + mutex_lock(&root->d_inode->i_mutex); inode = dentry->d_inode; if (inode) { @@ -203,7 +205,7 @@ void capifs_free_ncci(struct dentry *dentry) } dput(dentry); - mutex_unlock(&capifs_root->d_inode->i_mutex); + mutex_unlock(&root->d_inode->i_mutex); } static int __init capifs_init(void) -- cgit v1.2.3 From e11e7ac1ecac6b25439c003c5ca661cd399ec35d Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:08 +0000 Subject: CAPI: Pin capifs instead of mounting it Auto-mounting the capifs during module init prevents unloading its module. Instead, pin the filesystem as long as some NCCI node exists. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capifs.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capifs.c b/drivers/isdn/capi/capifs.c index 6ae0edf29c85..51c01efe2fe4 100644 --- a/drivers/isdn/capi/capifs.c +++ b/drivers/isdn/capi/capifs.c @@ -32,6 +32,7 @@ static char *revision = "$Revision: 1.1.2.3 $"; #define CAPIFS_SUPER_MAGIC (('C'<<8)|'N') static struct vfsmount *capifs_mnt; +static int capifs_mnt_count; static struct { int setuid; @@ -140,7 +141,7 @@ static struct file_system_type capifs_fs_type = { .kill_sb = kill_anon_super, }; -struct dentry *capifs_new_ncci(unsigned int number, dev_t device) +static struct dentry *new_ncci(unsigned int number, dev_t device) { struct super_block *s = capifs_mnt->mnt_sb; struct dentry *root = s->s_root; @@ -187,6 +188,20 @@ unlock_out: return dentry; } +struct dentry *capifs_new_ncci(unsigned int number, dev_t device) +{ + struct dentry *dentry; + + if (simple_pin_fs(&capifs_fs_type, &capifs_mnt, &capifs_mnt_count) < 0) + return NULL; + + dentry = new_ncci(number, device); + if (!dentry) + simple_release_fs(&capifs_mnt, &capifs_mnt_count); + + return dentry; +} + void capifs_free_ncci(struct dentry *dentry) { struct dentry *root = capifs_mnt->mnt_sb->s_root; @@ -206,6 +221,8 @@ void capifs_free_ncci(struct dentry *dentry) dput(dentry); mutex_unlock(&root->d_inode->i_mutex); + + simple_release_fs(&capifs_mnt, &capifs_mnt_count); } static int __init capifs_init(void) @@ -222,13 +239,6 @@ static int __init capifs_init(void) strcpy(rev, "1.0"); err = register_filesystem(&capifs_fs_type); - if (!err) { - capifs_mnt = kern_mount(&capifs_fs_type); - if (IS_ERR(capifs_mnt)) { - err = PTR_ERR(capifs_mnt); - unregister_filesystem(&capifs_fs_type); - } - } if (!err) printk(KERN_NOTICE "capifs: Rev %s\n", rev); return err; @@ -237,7 +247,6 @@ static int __init capifs_init(void) static void __exit capifs_exit(void) { unregister_filesystem(&capifs_fs_type); - mntput(capifs_mnt); } EXPORT_SYMBOL(capifs_new_ncci); -- cgit v1.2.3 From 88549d6b76346e677da8d2d52b37615df18a4345 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:09 +0000 Subject: CAPI: Reduce chattiness during module loading/removal The CVS revisions dumped by all CAPI modules are meaningless today. And that some CAPI module is loaded or removed does not necessarily deserve a message. Just keep the message of the central module, capi.ko, drop the rest. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 19 +++---------------- drivers/isdn/capi/capidrv.c | 26 -------------------------- drivers/isdn/capi/capifs.c | 20 +------------------- drivers/isdn/capi/kcapi.c | 27 +++++---------------------- 4 files changed, 9 insertions(+), 83 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index dc5ac52986ee..3b077978c496 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -45,8 +45,6 @@ #include "capifs.h" -static char *revision = "$Revision: 1.1.2.7 $"; - MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface"); MODULE_AUTHOR("Carsten Paeth"); MODULE_LICENSE("GPL"); @@ -1489,21 +1487,11 @@ static void __exit proc_exit(void) /* -------- init function and module interface ---------------------- */ -static char rev[32]; - static int __init capi_init(void) { - char *p; - char *compileinfo; + const char *compileinfo; int major_ret; - if ((p = strchr(revision, ':')) != NULL && p[1]) { - strlcpy(rev, p + 2, sizeof(rev)); - if ((p = strchr(rev, '$')) != NULL && p > rev) - *(p-1) = 0; - } else - strcpy(rev, "1.0"); - major_ret = register_chrdev(capi_major, "capi20", &capi_fops); if (major_ret < 0) { printk(KERN_ERR "capi20: unable to get major %d\n", capi_major); @@ -1537,8 +1525,8 @@ static int __init capi_init(void) #else compileinfo = " (no middleware)"; #endif - printk(KERN_NOTICE "capi20: Rev %s: started up with major %d%s\n", - rev, capi_major, compileinfo); + printk(KERN_NOTICE "CAPI 2.0 started up with major %d%s\n", + capi_major, compileinfo); return 0; } @@ -1554,7 +1542,6 @@ static void __exit capi_exit(void) #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE capinc_tty_exit(); #endif - printk(KERN_NOTICE "capi: Rev %s: unloaded\n", rev); } module_init(capi_init); diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c index bb450152fb74..7d8899ad5796 100644 --- a/drivers/isdn/capi/capidrv.c +++ b/drivers/isdn/capi/capidrv.c @@ -35,7 +35,6 @@ #include #include "capidrv.h" -static char *revision = "$Revision: 1.1.2.2 $"; static int debugmode = 0; MODULE_DESCRIPTION("CAPI4Linux: Interface to ISDN4Linux"); @@ -2266,19 +2265,9 @@ static void __exit proc_exit(void) static int __init capidrv_init(void) { capi_profile profile; - char rev[32]; - char *p; u32 ncontr, contr; u16 errcode; - if ((p = strchr(revision, ':')) != NULL && p[1]) { - strncpy(rev, p + 2, sizeof(rev)); - rev[sizeof(rev)-1] = 0; - if ((p = strchr(rev, '$')) != NULL && p > rev) - *(p-1) = 0; - } else - strcpy(rev, "1.0"); - global.ap.rparam.level3cnt = -2; /* number of bchannels twice */ global.ap.rparam.datablkcnt = 16; global.ap.rparam.datablklen = 2048; @@ -2306,29 +2295,14 @@ static int __init capidrv_init(void) } proc_init(); - printk(KERN_NOTICE "capidrv: Rev %s: loaded\n", rev); return 0; } static void __exit capidrv_exit(void) { - char rev[32]; - char *p; - - if ((p = strchr(revision, ':')) != NULL) { - strncpy(rev, p + 1, sizeof(rev)); - rev[sizeof(rev)-1] = 0; - if ((p = strchr(rev, '$')) != NULL) - *p = 0; - } else { - strcpy(rev, " ??? "); - } - capi20_release(&global.ap); proc_exit(); - - printk(KERN_NOTICE "capidrv: Rev%s: unloaded\n", rev); } module_init(capidrv_init); diff --git a/drivers/isdn/capi/capifs.c b/drivers/isdn/capi/capifs.c index 51c01efe2fe4..8596bd1a4d26 100644 --- a/drivers/isdn/capi/capifs.c +++ b/drivers/isdn/capi/capifs.c @@ -25,10 +25,6 @@ MODULE_LICENSE("GPL"); /* ------------------------------------------------------------------ */ -static char *revision = "$Revision: 1.1.2.3 $"; - -/* ------------------------------------------------------------------ */ - #define CAPIFS_SUPER_MAGIC (('C'<<8)|'N') static struct vfsmount *capifs_mnt; @@ -227,21 +223,7 @@ void capifs_free_ncci(struct dentry *dentry) static int __init capifs_init(void) { - char rev[32]; - char *p; - int err; - - if ((p = strchr(revision, ':')) != NULL && p[1]) { - strlcpy(rev, p + 2, sizeof(rev)); - if ((p = strchr(rev, '$')) != NULL && p > rev) - *(p-1) = 0; - } else - strcpy(rev, "1.0"); - - err = register_filesystem(&capifs_fs_type); - if (!err) - printk(KERN_NOTICE "capifs: Rev %s\n", rev); - return err; + return register_filesystem(&capifs_fs_type); } static void __exit capifs_exit(void) diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index b0bacf377c18..ef564ee1c06c 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -35,10 +35,6 @@ #endif #include -static char *revision = "$Revision: 1.1.2.8 $"; - -/* ------------------------------------------------------------- */ - static int showcapimsgs = 0; MODULE_DESCRIPTION("CAPI4Linux: kernel CAPI layer"); @@ -1165,25 +1161,12 @@ EXPORT_SYMBOL(capi20_set_callback); static int __init kcapi_init(void) { - char *p; - char rev[32]; - int ret; - - ret = cdebug_init(); - if (ret) - return ret; - kcapi_proc_init(); + int err; - if ((p = strchr(revision, ':')) != NULL && p[1]) { - strlcpy(rev, p + 2, sizeof(rev)); - if ((p = strchr(rev, '$')) != NULL && p > rev) - *(p-1) = 0; - } else - strcpy(rev, "1.0"); - - printk(KERN_NOTICE "CAPI Subsystem Rev %s\n", rev); - - return 0; + err = cdebug_init(); + if (!err) + kcapi_proc_init(); + return err; } static void __exit kcapi_exit(void) -- cgit v1.2.3 From 522530311b35ec8fc4785062441dd2d63967ac55 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:10 +0000 Subject: CAPI: Call a controller 'controller', not 'card' At least for our internal use, fix the misnomers that refer to a CAPI controller as 'card'. No functional changes. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/kcapi.c | 320 +++++++++++++++++++++-------------------- drivers/isdn/capi/kcapi.h | 8 +- drivers/isdn/capi/kcapi_proc.c | 17 ++- 3 files changed, 177 insertions(+), 168 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index ef564ee1c06c..f37c13b4ddc7 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -67,24 +67,24 @@ static DEFINE_RWLOCK(application_lock); static DEFINE_MUTEX(controller_mutex); struct capi20_appl *capi_applications[CAPI_MAXAPPL]; -struct capi_ctr *capi_cards[CAPI_MAXCONTR]; +struct capi_ctr *capi_controller[CAPI_MAXCONTR]; -static int ncards; +static int ncontrollers; /* -------- controller ref counting -------------------------------------- */ static inline struct capi_ctr * -capi_ctr_get(struct capi_ctr *card) +capi_ctr_get(struct capi_ctr *ctr) { - if (!try_module_get(card->owner)) + if (!try_module_get(ctr->owner)) return NULL; - return card; + return ctr; } static inline void -capi_ctr_put(struct capi_ctr *card) +capi_ctr_put(struct capi_ctr *ctr) { - module_put(card->owner); + module_put(ctr->owner); } /* ------------------------------------------------------------- */ @@ -94,7 +94,7 @@ static inline struct capi_ctr *get_capi_ctr_by_nr(u16 contr) if (contr - 1 >= CAPI_MAXCONTR) return NULL; - return capi_cards[contr - 1]; + return capi_controller[contr - 1]; } static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid) @@ -144,46 +144,48 @@ static inline int capi_subcmd_valid(u8 subcmd) /* ------------------------------------------------------------ */ -static void register_appl(struct capi_ctr *card, u16 applid, capi_register_params *rparam) +static void +register_appl(struct capi_ctr *ctr, u16 applid, capi_register_params *rparam) { - card = capi_ctr_get(card); + ctr = capi_ctr_get(ctr); - if (card) - card->register_appl(card, applid, rparam); + if (ctr) + ctr->register_appl(ctr, applid, rparam); else - printk(KERN_WARNING "%s: cannot get card resources\n", __func__); + printk(KERN_WARNING "%s: cannot get controller resources\n", + __func__); } -static void release_appl(struct capi_ctr *card, u16 applid) +static void release_appl(struct capi_ctr *ctr, u16 applid) { DBG("applid %#x", applid); - card->release_appl(card, applid); - capi_ctr_put(card); + ctr->release_appl(ctr, applid); + capi_ctr_put(ctr); } /* -------- KCI_CONTRUP --------------------------------------- */ static void notify_up(u32 contr) { - struct capi_ctr *card = get_capi_ctr_by_nr(contr); + struct capi_ctr *ctr = get_capi_ctr_by_nr(contr); struct capi20_appl *ap; u16 applid; if (showcapimsgs & 1) { printk(KERN_DEBUG "kcapi: notify up contr %d\n", contr); } - if (!card) { + if (!ctr) { printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); return; } for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { ap = get_capi_appl_by_nr(applid); if (!ap || ap->release_in_progress) continue; - register_appl(card, applid, &ap->rparam); + register_appl(ctr, applid, &ap->rparam); if (ap->callback && !ap->release_in_progress) - ap->callback(KCI_CONTRUP, contr, &card->profile); + ap->callback(KCI_CONTRUP, contr, &ctr->profile); } } @@ -269,14 +271,15 @@ static void recv_handler(struct work_struct *work) /** * capi_ctr_handle_message() - handle incoming CAPI message - * @card: controller descriptor structure. + * @ctr: controller descriptor structure. * @appl: application ID. * @skb: message. * * Called by hardware driver to pass a CAPI message to the application. */ -void capi_ctr_handle_message(struct capi_ctr * card, u16 appl, struct sk_buff *skb) +void capi_ctr_handle_message(struct capi_ctr *ctr, u16 appl, + struct sk_buff *skb) { struct capi20_appl *ap; int showctl = 0; @@ -284,43 +287,45 @@ void capi_ctr_handle_message(struct capi_ctr * card, u16 appl, struct sk_buff *s unsigned long flags; _cdebbuf *cdb; - if (card->cardstate != CARD_RUNNING) { + if (ctr->state != CAPI_CTR_RUNNING) { cdb = capi_message2str(skb->data); if (cdb) { printk(KERN_INFO "kcapi: controller [%03d] not active, got: %s", - card->cnr, cdb->buf); + ctr->cnr, cdb->buf); cdebbuf_free(cdb); } else printk(KERN_INFO "kcapi: controller [%03d] not active, cannot trace\n", - card->cnr); + ctr->cnr); goto error; } cmd = CAPIMSG_COMMAND(skb->data); subcmd = CAPIMSG_SUBCOMMAND(skb->data); if (cmd == CAPI_DATA_B3 && subcmd == CAPI_IND) { - card->nrecvdatapkt++; - if (card->traceflag > 2) showctl |= 2; + ctr->nrecvdatapkt++; + if (ctr->traceflag > 2) + showctl |= 2; } else { - card->nrecvctlpkt++; - if (card->traceflag) showctl |= 2; + ctr->nrecvctlpkt++; + if (ctr->traceflag) + showctl |= 2; } - showctl |= (card->traceflag & 1); + showctl |= (ctr->traceflag & 1); if (showctl & 2) { if (showctl & 1) { printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u\n", - card->cnr, CAPIMSG_APPID(skb->data), + ctr->cnr, CAPIMSG_APPID(skb->data), capi_cmd2str(cmd, subcmd), CAPIMSG_LEN(skb->data)); } else { cdb = capi_message2str(skb->data); if (cdb) { printk(KERN_DEBUG "kcapi: got [%03d] %s\n", - card->cnr, cdb->buf); + ctr->cnr, cdb->buf); cdebbuf_free(cdb); } else printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u, cannot trace\n", - card->cnr, CAPIMSG_APPID(skb->data), + ctr->cnr, CAPIMSG_APPID(skb->data), capi_cmd2str(cmd, subcmd), CAPIMSG_LEN(skb->data)); } @@ -356,74 +361,75 @@ EXPORT_SYMBOL(capi_ctr_handle_message); /** * capi_ctr_ready() - signal CAPI controller ready - * @card: controller descriptor structure. + * @ctr: controller descriptor structure. * * Called by hardware driver to signal that the controller is up and running. */ -void capi_ctr_ready(struct capi_ctr * card) +void capi_ctr_ready(struct capi_ctr *ctr) { - card->cardstate = CARD_RUNNING; + ctr->state = CAPI_CTR_RUNNING; - printk(KERN_NOTICE "kcapi: card [%03d] \"%s\" ready.\n", - card->cnr, card->name); + printk(KERN_NOTICE "kcapi: controller [%03d] \"%s\" ready.\n", + ctr->cnr, ctr->name); - notify_push(KCI_CONTRUP, card->cnr, 0, 0); + notify_push(KCI_CONTRUP, ctr->cnr, 0, 0); } EXPORT_SYMBOL(capi_ctr_ready); /** * capi_ctr_down() - signal CAPI controller not ready - * @card: controller descriptor structure. + * @ctr: controller descriptor structure. * * Called by hardware driver to signal that the controller is down and * unavailable for use. */ -void capi_ctr_down(struct capi_ctr * card) +void capi_ctr_down(struct capi_ctr *ctr) { u16 appl; DBG(""); - if (card->cardstate == CARD_DETECTED) + if (ctr->state == CAPI_CTR_DETECTED) return; - card->cardstate = CARD_DETECTED; + ctr->state = CAPI_CTR_DETECTED; - memset(card->manu, 0, sizeof(card->manu)); - memset(&card->version, 0, sizeof(card->version)); - memset(&card->profile, 0, sizeof(card->profile)); - memset(card->serial, 0, sizeof(card->serial)); + memset(ctr->manu, 0, sizeof(ctr->manu)); + memset(&ctr->version, 0, sizeof(ctr->version)); + memset(&ctr->profile, 0, sizeof(ctr->profile)); + memset(ctr->serial, 0, sizeof(ctr->serial)); for (appl = 1; appl <= CAPI_MAXAPPL; appl++) { struct capi20_appl *ap = get_capi_appl_by_nr(appl); if (!ap || ap->release_in_progress) continue; - capi_ctr_put(card); + capi_ctr_put(ctr); } - printk(KERN_NOTICE "kcapi: card [%03d] down.\n", card->cnr); + printk(KERN_NOTICE "kcapi: controller [%03d] down.\n", ctr->cnr); - notify_push(KCI_CONTRDOWN, card->cnr, 0, 0); + notify_push(KCI_CONTRDOWN, ctr->cnr, 0, 0); } EXPORT_SYMBOL(capi_ctr_down); /** * capi_ctr_suspend_output() - suspend controller - * @card: controller descriptor structure. + * @ctr: controller descriptor structure. * * Called by hardware driver to stop data flow. */ -void capi_ctr_suspend_output(struct capi_ctr *card) +void capi_ctr_suspend_output(struct capi_ctr *ctr) { - if (!card->blocked) { - printk(KERN_DEBUG "kcapi: card [%03d] suspend\n", card->cnr); - card->blocked = 1; + if (!ctr->blocked) { + printk(KERN_DEBUG "kcapi: controller [%03d] suspend\n", + ctr->cnr); + ctr->blocked = 1; } } @@ -431,16 +437,17 @@ EXPORT_SYMBOL(capi_ctr_suspend_output); /** * capi_ctr_resume_output() - resume controller - * @card: controller descriptor structure. + * @ctr: controller descriptor structure. * * Called by hardware driver to resume data flow. */ -void capi_ctr_resume_output(struct capi_ctr *card) +void capi_ctr_resume_output(struct capi_ctr *ctr) { - if (card->blocked) { - printk(KERN_DEBUG "kcapi: card [%03d] resume\n", card->cnr); - card->blocked = 0; + if (ctr->blocked) { + printk(KERN_DEBUG "kcapi: controller [%03d] resumed\n", + ctr->cnr); + ctr->blocked = 0; } } @@ -450,21 +457,20 @@ EXPORT_SYMBOL(capi_ctr_resume_output); /** * attach_capi_ctr() - register CAPI controller - * @card: controller descriptor structure. + * @ctr: controller descriptor structure. * * Called by hardware driver to register a controller with the CAPI subsystem. * Return value: 0 on success, error code < 0 on error */ -int -attach_capi_ctr(struct capi_ctr *card) +int attach_capi_ctr(struct capi_ctr *ctr) { int i; mutex_lock(&controller_mutex); for (i = 0; i < CAPI_MAXCONTR; i++) { - if (capi_cards[i] == NULL) + if (!capi_controller[i]) break; } if (i == CAPI_MAXCONTR) { @@ -472,25 +478,25 @@ attach_capi_ctr(struct capi_ctr *card) printk(KERN_ERR "kcapi: out of controller slots\n"); return -EBUSY; } - capi_cards[i] = card; + capi_controller[i] = ctr; mutex_unlock(&controller_mutex); - card->nrecvctlpkt = 0; - card->nrecvdatapkt = 0; - card->nsentctlpkt = 0; - card->nsentdatapkt = 0; - card->cnr = i + 1; - card->cardstate = CARD_DETECTED; - card->blocked = 0; - card->traceflag = showcapimsgs; - - sprintf(card->procfn, "capi/controllers/%d", card->cnr); - card->procent = proc_create_data(card->procfn, 0, NULL, card->proc_fops, card); - - ncards++; - printk(KERN_NOTICE "kcapi: Controller [%03d]: %s attached\n", - card->cnr, card->name); + ctr->nrecvctlpkt = 0; + ctr->nrecvdatapkt = 0; + ctr->nsentctlpkt = 0; + ctr->nsentdatapkt = 0; + ctr->cnr = i + 1; + ctr->state = CAPI_CTR_DETECTED; + ctr->blocked = 0; + ctr->traceflag = showcapimsgs; + + sprintf(ctr->procfn, "capi/controllers/%d", ctr->cnr); + ctr->procent = proc_create_data(ctr->procfn, 0, NULL, ctr->proc_fops, ctr); + + ncontrollers++; + printk(KERN_NOTICE "kcapi: controller [%03d]: %s attached\n", + ctr->cnr, ctr->name); return 0; } @@ -498,27 +504,27 @@ EXPORT_SYMBOL(attach_capi_ctr); /** * detach_capi_ctr() - unregister CAPI controller - * @card: controller descriptor structure. + * @ctr: controller descriptor structure. * * Called by hardware driver to remove the registration of a controller * with the CAPI subsystem. * Return value: 0 on success, error code < 0 on error */ -int detach_capi_ctr(struct capi_ctr *card) +int detach_capi_ctr(struct capi_ctr *ctr) { - if (card->cardstate != CARD_DETECTED) - capi_ctr_down(card); + if (ctr->state != CAPI_CTR_DETECTED) + capi_ctr_down(ctr); - ncards--; + ncontrollers--; - if (card->procent) { - remove_proc_entry(card->procfn, NULL); - card->procent = NULL; + if (ctr->procent) { + remove_proc_entry(ctr->procfn, NULL); + ctr->procent = NULL; } - capi_cards[card->cnr - 1] = NULL; - printk(KERN_NOTICE "kcapi: Controller [%03d]: %s unregistered\n", - card->cnr, card->name); + capi_controller[ctr->cnr - 1] = NULL; + printk(KERN_NOTICE "kcapi: controller [%03d]: %s unregistered\n", + ctr->cnr, ctr->name); return 0; } @@ -576,7 +582,8 @@ u16 capi20_isinstalled(void) { int i; for (i = 0; i < CAPI_MAXCONTR; i++) { - if (capi_cards[i] && capi_cards[i]->cardstate == CARD_RUNNING) + if (capi_controller[i] && + capi_controller[i]->state == CAPI_CTR_RUNNING) return CAPI_NOERROR; } return CAPI_REGNOTINSTALLED; @@ -635,9 +642,10 @@ u16 capi20_register(struct capi20_appl *ap) mutex_lock(&controller_mutex); for (i = 0; i < CAPI_MAXCONTR; i++) { - if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING) + if (!capi_controller[i] || + capi_controller[i]->state != CAPI_CTR_RUNNING) continue; - register_appl(capi_cards[i], applid, &ap->rparam); + register_appl(capi_controller[i], applid, &ap->rparam); } mutex_unlock(&controller_mutex); @@ -674,9 +682,10 @@ u16 capi20_release(struct capi20_appl *ap) mutex_lock(&controller_mutex); for (i = 0; i < CAPI_MAXCONTR; i++) { - if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING) + if (!capi_controller[i] || + capi_controller[i]->state != CAPI_CTR_RUNNING) continue; - release_appl(capi_cards[i], ap->applid); + release_appl(capi_controller[i], ap->applid); } mutex_unlock(&controller_mutex); @@ -703,13 +712,13 @@ EXPORT_SYMBOL(capi20_release); u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb) { - struct capi_ctr *card; + struct capi_ctr *ctr; int showctl = 0; u8 cmd, subcmd; DBG("applid %#x", ap->applid); - if (ncards == 0) + if (ncontrollers == 0) return CAPI_REGNOTINSTALLED; if ((ap->applid == 0) || ap->release_in_progress) return CAPI_ILLAPPNR; @@ -717,28 +726,30 @@ u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb) || !capi_cmd_valid(CAPIMSG_COMMAND(skb->data)) || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb->data))) return CAPI_ILLCMDORSUBCMDORMSGTOSMALL; - card = get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb->data)); - if (!card || card->cardstate != CARD_RUNNING) { - card = get_capi_ctr_by_nr(1); // XXX why? - if (!card || card->cardstate != CARD_RUNNING) + ctr = get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb->data)); + if (!ctr || ctr->state != CAPI_CTR_RUNNING) { + ctr = get_capi_ctr_by_nr(1); /* XXX why? */ + if (!ctr || ctr->state != CAPI_CTR_RUNNING) return CAPI_REGNOTINSTALLED; } - if (card->blocked) + if (ctr->blocked) return CAPI_SENDQUEUEFULL; cmd = CAPIMSG_COMMAND(skb->data); subcmd = CAPIMSG_SUBCOMMAND(skb->data); if (cmd == CAPI_DATA_B3 && subcmd== CAPI_REQ) { - card->nsentdatapkt++; + ctr->nsentdatapkt++; ap->nsentdatapkt++; - if (card->traceflag > 2) showctl |= 2; + if (ctr->traceflag > 2) + showctl |= 2; } else { - card->nsentctlpkt++; + ctr->nsentctlpkt++; ap->nsentctlpkt++; - if (card->traceflag) showctl |= 2; + if (ctr->traceflag) + showctl |= 2; } - showctl |= (card->traceflag & 1); + showctl |= (ctr->traceflag & 1); if (showctl & 2) { if (showctl & 1) { printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u\n", @@ -761,7 +772,7 @@ u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb) CAPIMSG_LEN(skb->data)); } } - return card->send_message(card, skb); + return ctr->send_message(ctr, skb); } EXPORT_SYMBOL(capi20_put_message); @@ -778,16 +789,16 @@ EXPORT_SYMBOL(capi20_put_message); u16 capi20_get_manufacturer(u32 contr, u8 *buf) { - struct capi_ctr *card; + struct capi_ctr *ctr; if (contr == 0) { strlcpy(buf, capi_manufakturer, CAPI_MANUFACTURER_LEN); return CAPI_NOERROR; } - card = get_capi_ctr_by_nr(contr); - if (!card || card->cardstate != CARD_RUNNING) + ctr = get_capi_ctr_by_nr(contr); + if (!ctr || ctr->state != CAPI_CTR_RUNNING) return CAPI_REGNOTINSTALLED; - strlcpy(buf, card->manu, CAPI_MANUFACTURER_LEN); + strlcpy(buf, ctr->manu, CAPI_MANUFACTURER_LEN); return CAPI_NOERROR; } @@ -805,17 +816,17 @@ EXPORT_SYMBOL(capi20_get_manufacturer); u16 capi20_get_version(u32 contr, struct capi_version *verp) { - struct capi_ctr *card; + struct capi_ctr *ctr; if (contr == 0) { *verp = driver_version; return CAPI_NOERROR; } - card = get_capi_ctr_by_nr(contr); - if (!card || card->cardstate != CARD_RUNNING) + ctr = get_capi_ctr_by_nr(contr); + if (!ctr || ctr->state != CAPI_CTR_RUNNING) return CAPI_REGNOTINSTALLED; - memcpy((void *) verp, &card->version, sizeof(capi_version)); + memcpy(verp, &ctr->version, sizeof(capi_version)); return CAPI_NOERROR; } @@ -833,17 +844,17 @@ EXPORT_SYMBOL(capi20_get_version); u16 capi20_get_serial(u32 contr, u8 *serial) { - struct capi_ctr *card; + struct capi_ctr *ctr; if (contr == 0) { strlcpy(serial, driver_serial, CAPI_SERIAL_LEN); return CAPI_NOERROR; } - card = get_capi_ctr_by_nr(contr); - if (!card || card->cardstate != CARD_RUNNING) + ctr = get_capi_ctr_by_nr(contr); + if (!ctr || ctr->state != CAPI_CTR_RUNNING) return CAPI_REGNOTINSTALLED; - strlcpy((void *) serial, card->serial, CAPI_SERIAL_LEN); + strlcpy(serial, ctr->serial, CAPI_SERIAL_LEN); return CAPI_NOERROR; } @@ -861,18 +872,17 @@ EXPORT_SYMBOL(capi20_get_serial); u16 capi20_get_profile(u32 contr, struct capi_profile *profp) { - struct capi_ctr *card; + struct capi_ctr *ctr; if (contr == 0) { - profp->ncontroller = ncards; + profp->ncontroller = ncontrollers; return CAPI_NOERROR; } - card = get_capi_ctr_by_nr(contr); - if (!card || card->cardstate != CARD_RUNNING) + ctr = get_capi_ctr_by_nr(contr); + if (!ctr || ctr->state != CAPI_CTR_RUNNING) return CAPI_REGNOTINSTALLED; - memcpy((void *) profp, &card->profile, - sizeof(struct capi_profile)); + memcpy(profp, &ctr->profile, sizeof(struct capi_profile)); return CAPI_NOERROR; } @@ -885,7 +895,7 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) avmb1_extcarddef cdef; avmb1_resetdef rdef; capicardparams cparams; - struct capi_ctr *card; + struct capi_ctr *ctr; struct capi_driver *driver = NULL; capiloaddata ldata; struct list_head *l; @@ -958,26 +968,26 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) sizeof(avmb1_loadandconfigdef))) return -EFAULT; } - card = get_capi_ctr_by_nr(ldef.contr); - if (!card) + ctr = get_capi_ctr_by_nr(ldef.contr); + if (!ctr) return -EINVAL; - card = capi_ctr_get(card); - if (!card) + ctr = capi_ctr_get(ctr); + if (!ctr) return -ESRCH; - if (card->load_firmware == NULL) { + if (ctr->load_firmware == NULL) { printk(KERN_DEBUG "kcapi: load: no load function\n"); - capi_ctr_put(card); + capi_ctr_put(ctr); return -ESRCH; } if (ldef.t4file.len <= 0) { printk(KERN_DEBUG "kcapi: load: invalid parameter: length of t4file is %d ?\n", ldef.t4file.len); - capi_ctr_put(card); + capi_ctr_put(ctr); return -EINVAL; } if (ldef.t4file.data == NULL) { printk(KERN_DEBUG "kcapi: load: invalid parameter: dataptr is 0\n"); - capi_ctr_put(card); + capi_ctr_put(ctr); return -EINVAL; } @@ -988,46 +998,46 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) ldata.configuration.data = ldef.t4config.data; ldata.configuration.len = ldef.t4config.len; - if (card->cardstate != CARD_DETECTED) { + if (ctr->state != CAPI_CTR_DETECTED) { printk(KERN_INFO "kcapi: load: contr=%d not in detect state\n", ldef.contr); - capi_ctr_put(card); + capi_ctr_put(ctr); return -EBUSY; } - card->cardstate = CARD_LOADING; + ctr->state = CAPI_CTR_LOADING; - retval = card->load_firmware(card, &ldata); + retval = ctr->load_firmware(ctr, &ldata); if (retval) { - card->cardstate = CARD_DETECTED; - capi_ctr_put(card); + ctr->state = CAPI_CTR_DETECTED; + capi_ctr_put(ctr); return retval; } - while (card->cardstate != CARD_RUNNING) { + while (ctr->state != CAPI_CTR_RUNNING) { msleep_interruptible(100); /* 0.1 sec */ if (signal_pending(current)) { - capi_ctr_put(card); + capi_ctr_put(ctr); return -EINTR; } } - capi_ctr_put(card); + capi_ctr_put(ctr); return 0; case AVMB1_RESETCARD: if (copy_from_user(&rdef, data, sizeof(avmb1_resetdef))) return -EFAULT; - card = get_capi_ctr_by_nr(rdef.contr); - if (!card) + ctr = get_capi_ctr_by_nr(rdef.contr); + if (!ctr) return -ESRCH; - if (card->cardstate == CARD_DETECTED) + if (ctr->state == CAPI_CTR_DETECTED) return 0; - card->reset_ctr(card); + ctr->reset_ctr(ctr); - while (card->cardstate > CARD_DETECTED) { + while (ctr->state > CAPI_CTR_DETECTED) { msleep_interruptible(100); /* 0.1 sec */ @@ -1052,7 +1062,7 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) int capi20_manufacturer(unsigned int cmd, void __user *data) { - struct capi_ctr *card; + struct capi_ctr *ctr; switch (cmd) { #ifdef AVMB1_COMPAT @@ -1070,13 +1080,13 @@ int capi20_manufacturer(unsigned int cmd, void __user *data) if (copy_from_user(&fdef, data, sizeof(kcapi_flagdef))) return -EFAULT; - card = get_capi_ctr_by_nr(fdef.contr); - if (!card) + ctr = get_capi_ctr_by_nr(fdef.contr); + if (!ctr) return -ESRCH; - card->traceflag = fdef.flag; + ctr->traceflag = fdef.flag; printk(KERN_INFO "kcapi: contr [%03d] set trace=%d\n", - card->cnr, card->traceflag); + ctr->cnr, ctr->traceflag); return 0; } case KCAPI_CMD_ADDCARD: diff --git a/drivers/isdn/capi/kcapi.h b/drivers/isdn/capi/kcapi.h index 244711f7f838..f62c53bd6a97 100644 --- a/drivers/isdn/capi/kcapi.h +++ b/drivers/isdn/capi/kcapi.h @@ -24,16 +24,16 @@ printk(KERN_DEBUG "%s: " format "\n" , __func__ , ## arg); \ #endif enum { - CARD_DETECTED = 1, - CARD_LOADING = 2, - CARD_RUNNING = 3, + CAPI_CTR_DETECTED = 1, + CAPI_CTR_LOADING = 2, + CAPI_CTR_RUNNING = 3, }; extern struct list_head capi_drivers; extern rwlock_t capi_drivers_list_lock; extern struct capi20_appl *capi_applications[CAPI_MAXAPPL]; -extern struct capi_ctr *capi_cards[CAPI_MAXCONTR]; +extern struct capi_ctr *capi_controller[CAPI_MAXCONTR]; #ifdef CONFIG_PROC_FS diff --git a/drivers/isdn/capi/kcapi_proc.c b/drivers/isdn/capi/kcapi_proc.c index 09d4db764d22..59fd16a4ad8e 100644 --- a/drivers/isdn/capi/kcapi_proc.c +++ b/drivers/isdn/capi/kcapi_proc.c @@ -15,13 +15,12 @@ #include #include -static char * -cardstate2str(unsigned short cardstate) +static char *state2str(unsigned short state) { - switch (cardstate) { - case CARD_DETECTED: return "detected"; - case CARD_LOADING: return "loading"; - case CARD_RUNNING: return "running"; + switch (state) { + case CAPI_CTR_DETECTED: return "detected"; + case CAPI_CTR_LOADING: return "loading"; + case CAPI_CTR_RUNNING: return "running"; default: return "???"; } } @@ -38,7 +37,7 @@ cardstate2str(unsigned short cardstate) static void *controller_start(struct seq_file *seq, loff_t *pos) { if (*pos < CAPI_MAXCONTR) - return &capi_cards[*pos]; + return &capi_controller[*pos]; return NULL; } @@ -47,7 +46,7 @@ static void *controller_next(struct seq_file *seq, void *v, loff_t *pos) { ++*pos; if (*pos < CAPI_MAXCONTR) - return &capi_cards[*pos]; + return &capi_controller[*pos]; return NULL; } @@ -65,7 +64,7 @@ static int controller_show(struct seq_file *seq, void *v) seq_printf(seq, "%d %-10s %-8s %-16s %s\n", ctr->cnr, ctr->driver_name, - cardstate2str(ctr->cardstate), + state2str(ctr->state), ctr->name, ctr->procinfo ? ctr->procinfo(ctr) : ""); -- cgit v1.2.3 From 9717fb8b64ed41be9dd074bc8010bafd33046f1a Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:11 +0000 Subject: CAPI: Convert capi drivers rwlock into mutex Turn the lock protecting registered capi drivers into a mutex and apply it consistently. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/kcapi.c | 49 +++++++++++++++++++----------------------- drivers/isdn/capi/kcapi.h | 2 +- drivers/isdn/capi/kcapi_proc.c | 8 +++---- 3 files changed, 27 insertions(+), 32 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index f37c13b4ddc7..c46964fc17c7 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -61,7 +61,7 @@ static char capi_manufakturer[64] = "AVM Berlin"; #define NCCI2CTRL(ncci) (((ncci) >> 24) & 0x7f) LIST_HEAD(capi_drivers); -DEFINE_RWLOCK(capi_drivers_list_lock); +DEFINE_MUTEX(capi_drivers_lock); static DEFINE_RWLOCK(application_lock); static DEFINE_MUTEX(controller_mutex); @@ -540,11 +540,9 @@ EXPORT_SYMBOL(detach_capi_ctr); void register_capi_driver(struct capi_driver *driver) { - unsigned long flags; - - write_lock_irqsave(&capi_drivers_list_lock, flags); + mutex_lock(&capi_drivers_lock); list_add_tail(&driver->list, &capi_drivers); - write_unlock_irqrestore(&capi_drivers_list_lock, flags); + mutex_unlock(&capi_drivers_lock); } EXPORT_SYMBOL(register_capi_driver); @@ -558,11 +556,9 @@ EXPORT_SYMBOL(register_capi_driver); void unregister_capi_driver(struct capi_driver *driver) { - unsigned long flags; - - write_lock_irqsave(&capi_drivers_list_lock, flags); + mutex_lock(&capi_drivers_lock); list_del(&driver->list); - write_unlock_irqrestore(&capi_drivers_list_lock, flags); + mutex_unlock(&capi_drivers_lock); } EXPORT_SYMBOL(unregister_capi_driver); @@ -899,7 +895,6 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) struct capi_driver *driver = NULL; capiloaddata ldata; struct list_head *l; - unsigned long flags; int retval; switch (cmd) { @@ -919,7 +914,8 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) cparams.irq = cdef.irq; cparams.cardnr = cdef.cardnr; - read_lock_irqsave(&capi_drivers_list_lock, flags); + mutex_lock(&capi_drivers_lock); + switch (cdef.cardtype) { case AVM_CARDTYPE_B1: list_for_each(l, &capi_drivers) { @@ -940,18 +936,15 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) break; } if (!driver) { - read_unlock_irqrestore(&capi_drivers_list_lock, flags); printk(KERN_ERR "kcapi: driver not loaded.\n"); - return -EIO; - } - if (!driver->add_card) { - read_unlock_irqrestore(&capi_drivers_list_lock, flags); + retval = -EIO; + } else if (!driver->add_card) { printk(KERN_ERR "kcapi: driver has no add card function.\n"); - return -EIO; - } + retval = -EIO; + } else + retval = driver->add_card(driver, &cparams); - retval = driver->add_card(driver, &cparams); - read_unlock_irqrestore(&capi_drivers_list_lock, flags); + mutex_unlock(&capi_drivers_lock); return retval; case AVMB1_LOAD: @@ -1107,6 +1100,8 @@ int capi20_manufacturer(unsigned int cmd, void __user *data) cparams.cardtype = 0; cdef.driver[sizeof(cdef.driver)-1] = 0; + mutex_lock(&capi_drivers_lock); + list_for_each(l, &capi_drivers) { driver = list_entry(l, struct capi_driver, list); if (strcmp(driver->name, cdef.driver) == 0) @@ -1115,15 +1110,15 @@ int capi20_manufacturer(unsigned int cmd, void __user *data) if (driver == NULL) { printk(KERN_ERR "kcapi: driver \"%s\" not loaded.\n", cdef.driver); - return -ESRCH; - } - - if (!driver->add_card) { + retval = -ESRCH; + } else if (!driver->add_card) { printk(KERN_ERR "kcapi: driver \"%s\" has no add card function.\n", cdef.driver); - return -EIO; - } + retval = -EIO; + } else + retval = driver->add_card(driver, &cparams); - return driver->add_card(driver, &cparams); + mutex_unlock(&capi_drivers_lock); + return retval; } default: diff --git a/drivers/isdn/capi/kcapi.h b/drivers/isdn/capi/kcapi.h index f62c53bd6a97..07c58500fe48 100644 --- a/drivers/isdn/capi/kcapi.h +++ b/drivers/isdn/capi/kcapi.h @@ -30,7 +30,7 @@ enum { }; extern struct list_head capi_drivers; -extern rwlock_t capi_drivers_list_lock; +extern struct mutex capi_drivers_lock; extern struct capi20_appl *capi_applications[CAPI_MAXAPPL]; extern struct capi_ctr *capi_controller[CAPI_MAXCONTR]; diff --git a/drivers/isdn/capi/kcapi_proc.c b/drivers/isdn/capi/kcapi_proc.c index 59fd16a4ad8e..71b07610ff31 100644 --- a/drivers/isdn/capi/kcapi_proc.c +++ b/drivers/isdn/capi/kcapi_proc.c @@ -238,9 +238,9 @@ static const struct file_operations proc_applstats_ops = { // --------------------------------------------------------------------------- static void *capi_driver_start(struct seq_file *seq, loff_t *pos) - __acquires(&capi_drivers_list_lock) + __acquires(&capi_drivers_lock) { - read_lock(&capi_drivers_list_lock); + mutex_lock(&capi_drivers_lock); return seq_list_start(&capi_drivers, *pos); } @@ -250,9 +250,9 @@ static void *capi_driver_next(struct seq_file *seq, void *v, loff_t *pos) } static void capi_driver_stop(struct seq_file *seq, void *v) - __releases(&capi_drivers_list_lock) + __releases(&capi_drivers_lock) { - read_unlock(&capi_drivers_list_lock); + mutex_unlock(&capi_drivers_lock); } static int capi_driver_show(struct seq_file *seq, void *v) -- cgit v1.2.3 From 3efecf7a49cde47e5f2deb1d5504951ff4bede53 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:12 +0000 Subject: CAPI: Rework capi_ctr_ready/down This step prepares the application of proper controller locking: Push all state changing work into the notify handler that are called by capi_ctr_ready and capi_ctr_down, switch detach_capi_ctr to issue a synchronous ctr_down. Also ensure that we do not go through any action if the state did not change. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/kcapi.c | 95 +++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 45 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index c46964fc17c7..9362a7a66aa1 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -169,44 +169,74 @@ static void release_appl(struct capi_ctr *ctr, u16 applid) static void notify_up(u32 contr) { - struct capi_ctr *ctr = get_capi_ctr_by_nr(contr); struct capi20_appl *ap; + struct capi_ctr *ctr; u16 applid; - if (showcapimsgs & 1) { + if (showcapimsgs & 1) printk(KERN_DEBUG "kcapi: notify up contr %d\n", contr); - } - if (!ctr) { + + ctr = get_capi_ctr_by_nr(contr); + if (ctr) { + if (ctr->state == CAPI_CTR_RUNNING) + return; + + ctr->state = CAPI_CTR_RUNNING; + + for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { + ap = get_capi_appl_by_nr(applid); + if (!ap || ap->release_in_progress) + continue; + register_appl(ctr, applid, &ap->rparam); + if (ap->callback && !ap->release_in_progress) + ap->callback(KCI_CONTRUP, contr, + &ctr->profile); + } + } else printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); - return; - } - for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { - ap = get_capi_appl_by_nr(applid); - if (!ap || ap->release_in_progress) continue; - register_appl(ctr, applid, &ap->rparam); - if (ap->callback && !ap->release_in_progress) - ap->callback(KCI_CONTRUP, contr, &ctr->profile); - } } /* -------- KCI_CONTRDOWN ------------------------------------- */ -static void notify_down(u32 contr) +static void ctr_down(struct capi_ctr *ctr) { struct capi20_appl *ap; u16 applid; - if (showcapimsgs & 1) { - printk(KERN_DEBUG "kcapi: notify down contr %d\n", contr); - } + if (ctr->state == CAPI_CTR_DETECTED) + return; + + ctr->state = CAPI_CTR_DETECTED; + + memset(ctr->manu, 0, sizeof(ctr->manu)); + memset(&ctr->version, 0, sizeof(ctr->version)); + memset(&ctr->profile, 0, sizeof(ctr->profile)); + memset(ctr->serial, 0, sizeof(ctr->serial)); for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { ap = get_capi_appl_by_nr(applid); - if (ap && ap->callback && !ap->release_in_progress) - ap->callback(KCI_CONTRDOWN, contr, NULL); + if (ap && !ap->release_in_progress) { + if (ap->callback) + ap->callback(KCI_CONTRDOWN, ctr->cnr, NULL); + capi_ctr_put(ctr); + } } } +static void notify_down(u32 contr) +{ + struct capi_ctr *ctr; + + if (showcapimsgs & 1) + printk(KERN_DEBUG "kcapi: notify down contr %d\n", contr); + + ctr = get_capi_ctr_by_nr(contr); + if (ctr) + ctr_down(ctr); + else + printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); +} + static void notify_handler(struct work_struct *work) { struct capi_notifier *np = @@ -368,8 +398,6 @@ EXPORT_SYMBOL(capi_ctr_handle_message); void capi_ctr_ready(struct capi_ctr *ctr) { - ctr->state = CAPI_CTR_RUNNING; - printk(KERN_NOTICE "kcapi: controller [%03d] \"%s\" ready.\n", ctr->cnr, ctr->name); @@ -388,28 +416,6 @@ EXPORT_SYMBOL(capi_ctr_ready); void capi_ctr_down(struct capi_ctr *ctr) { - u16 appl; - - DBG(""); - - if (ctr->state == CAPI_CTR_DETECTED) - return; - - ctr->state = CAPI_CTR_DETECTED; - - memset(ctr->manu, 0, sizeof(ctr->manu)); - memset(&ctr->version, 0, sizeof(ctr->version)); - memset(&ctr->profile, 0, sizeof(ctr->profile)); - memset(ctr->serial, 0, sizeof(ctr->serial)); - - for (appl = 1; appl <= CAPI_MAXAPPL; appl++) { - struct capi20_appl *ap = get_capi_appl_by_nr(appl); - if (!ap || ap->release_in_progress) - continue; - - capi_ctr_put(ctr); - } - printk(KERN_NOTICE "kcapi: controller [%03d] down.\n", ctr->cnr); notify_push(KCI_CONTRDOWN, ctr->cnr, 0, 0); @@ -513,8 +519,7 @@ EXPORT_SYMBOL(attach_capi_ctr); int detach_capi_ctr(struct capi_ctr *ctr) { - if (ctr->state != CAPI_CTR_DETECTED) - capi_ctr_down(ctr); + ctr_down(ctr); ncontrollers--; -- cgit v1.2.3 From ef69bb2ec6036945da1d3d3f07b75253f484f693 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:13 +0000 Subject: CAPI: Rework controller state notifier Another step towards proper locking: Rework the callback provided to capidrv for controller state changes. This is so far attached to an application, which would require us to hold the corresponding lock across notification calls. But there is no direct relation between a controller up/down event and an application, so let's decouple them and provide a notifier call chain for those events instead. This notifier chain is first of all used internally. Here we request the highest priority to unsure that housekeeping work is done before any other notifications. The chain is exported via [un]register_capictr_notifier to our only user, capidrv, to replace the racy and unfixable capi20_set_callback. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capidrv.c | 22 ++++++--- drivers/isdn/capi/kcapi.c | 112 ++++++++++++++++++++------------------------ 2 files changed, 67 insertions(+), 67 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c index 7d8899ad5796..bf55ed5f38e3 100644 --- a/drivers/isdn/capi/capidrv.c +++ b/drivers/isdn/capi/capidrv.c @@ -2210,19 +2210,24 @@ static int capidrv_delcontr(u16 contr) } -static void lower_callback(unsigned int cmd, u32 contr, void *data) +static int +lower_callback(struct notifier_block *nb, unsigned long val, void *v) { + capi_profile profile; + u32 contr = (long)v; - switch (cmd) { - case KCI_CONTRUP: + switch (val) { + case CAPICTR_UP: printk(KERN_INFO "capidrv: controller %hu up\n", contr); - (void) capidrv_addcontr(contr, (capi_profile *) data); + if (capi20_get_profile(contr, &profile) == CAPI_NOERROR) + (void) capidrv_addcontr(contr, &profile); break; - case KCI_CONTRDOWN: + case CAPICTR_DOWN: printk(KERN_INFO "capidrv: controller %hu down\n", contr); (void) capidrv_delcontr(contr); break; } + return NOTIFY_OK; } /* @@ -2262,6 +2267,10 @@ static void __exit proc_exit(void) remove_proc_entry("capi/capidrv", NULL); } +static struct notifier_block capictr_nb = { + .notifier_call = lower_callback, +}; + static int __init capidrv_init(void) { capi_profile profile; @@ -2278,7 +2287,7 @@ static int __init capidrv_init(void) return -EIO; } - capi20_set_callback(&global.ap, lower_callback); + register_capictr_notifier(&capictr_nb); errcode = capi20_get_profile(0, &profile); if (errcode != CAPI_NOERROR) { @@ -2300,6 +2309,7 @@ static int __init capidrv_init(void) static void __exit capidrv_exit(void) { + unregister_capictr_notifier(&capictr_nb); capi20_release(&global.ap); proc_exit(); diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index 9362a7a66aa1..e08914d33be1 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -44,12 +44,10 @@ module_param(showcapimsgs, uint, 0); /* ------------------------------------------------------------- */ -struct capi_notifier { +struct capictr_event { struct work_struct work; - unsigned int cmd; + unsigned int type; u32 controller; - u16 applid; - u32 ncci; }; /* ------------------------------------------------------------- */ @@ -71,6 +69,8 @@ struct capi_ctr *capi_controller[CAPI_MAXCONTR]; static int ncontrollers; +static BLOCKING_NOTIFIER_HEAD(ctr_notifier_list); + /* -------- controller ref counting -------------------------------------- */ static inline struct capi_ctr * @@ -165,8 +165,6 @@ static void release_appl(struct capi_ctr *ctr, u16 applid) capi_ctr_put(ctr); } -/* -------- KCI_CONTRUP --------------------------------------- */ - static void notify_up(u32 contr) { struct capi20_appl *ap; @@ -188,16 +186,11 @@ static void notify_up(u32 contr) if (!ap || ap->release_in_progress) continue; register_appl(ctr, applid, &ap->rparam); - if (ap->callback && !ap->release_in_progress) - ap->callback(KCI_CONTRUP, contr, - &ctr->profile); } } else printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); } -/* -------- KCI_CONTRDOWN ------------------------------------- */ - static void ctr_down(struct capi_ctr *ctr) { struct capi20_appl *ap; @@ -215,11 +208,8 @@ static void ctr_down(struct capi_ctr *ctr) for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { ap = get_capi_appl_by_nr(applid); - if (ap && !ap->release_in_progress) { - if (ap->callback) - ap->callback(KCI_CONTRDOWN, ctr->cnr, NULL); + if (ap && !ap->release_in_progress) capi_ctr_put(ctr); - } } } @@ -237,45 +227,63 @@ static void notify_down(u32 contr) printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); } -static void notify_handler(struct work_struct *work) +static int +notify_handler(struct notifier_block *nb, unsigned long val, void *v) { - struct capi_notifier *np = - container_of(work, struct capi_notifier, work); + u32 contr = (long)v; - switch (np->cmd) { - case KCI_CONTRUP: - notify_up(np->controller); + switch (val) { + case CAPICTR_UP: + notify_up(contr); break; - case KCI_CONTRDOWN: - notify_down(np->controller); + case CAPICTR_DOWN: + notify_down(contr); break; } + return NOTIFY_OK; +} + +static void do_notify_work(struct work_struct *work) +{ + struct capictr_event *event = + container_of(work, struct capictr_event, work); - kfree(np); + blocking_notifier_call_chain(&ctr_notifier_list, event->type, + (void *)(long)event->controller); + kfree(event); } /* * The notifier will result in adding/deleteing of devices. Devices can * only removed in user process, not in bh. */ -static int notify_push(unsigned int cmd, u32 controller, u16 applid, u32 ncci) +static int notify_push(unsigned int event_type, u32 controller) { - struct capi_notifier *np = kmalloc(sizeof(*np), GFP_ATOMIC); + struct capictr_event *event = kmalloc(sizeof(*event), GFP_ATOMIC); - if (!np) + if (!event) return -ENOMEM; - INIT_WORK(&np->work, notify_handler); - np->cmd = cmd; - np->controller = controller; - np->applid = applid; - np->ncci = ncci; + INIT_WORK(&event->work, do_notify_work); + event->type = event_type; + event->controller = controller; - schedule_work(&np->work); + schedule_work(&event->work); return 0; } - +int register_capictr_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&ctr_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(register_capictr_notifier); + +int unregister_capictr_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&ctr_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(unregister_capictr_notifier); + /* -------- Receiver ------------------------------------------ */ static void recv_handler(struct work_struct *work) @@ -401,7 +409,7 @@ void capi_ctr_ready(struct capi_ctr *ctr) printk(KERN_NOTICE "kcapi: controller [%03d] \"%s\" ready.\n", ctr->cnr, ctr->name); - notify_push(KCI_CONTRUP, ctr->cnr, 0, 0); + notify_push(CAPICTR_UP, ctr->cnr); } EXPORT_SYMBOL(capi_ctr_ready); @@ -418,7 +426,7 @@ void capi_ctr_down(struct capi_ctr *ctr) { printk(KERN_NOTICE "kcapi: controller [%03d] down.\n", ctr->cnr); - notify_push(KCI_CONTRDOWN, ctr->cnr, 0, 0); + notify_push(CAPICTR_DOWN, ctr->cnr); } EXPORT_SYMBOL(capi_ctr_down); @@ -633,7 +641,6 @@ u16 capi20_register(struct capi20_appl *ap) ap->nrecvdatapkt = 0; ap->nsentctlpkt = 0; ap->nsentdatapkt = 0; - ap->callback = NULL; mutex_init(&ap->recv_mtx); skb_queue_head_init(&ap->recv_queue); INIT_WORK(&ap->recv_work, recv_handler); @@ -1137,30 +1144,6 @@ int capi20_manufacturer(unsigned int cmd, void __user *data) EXPORT_SYMBOL(capi20_manufacturer); -/* temporary hack */ - -/** - * capi20_set_callback() - set CAPI application notification callback function - * @ap: CAPI application descriptor structure. - * @callback: callback function (NULL to remove). - * - * If not NULL, the callback function will be called to notify the - * application of the addition or removal of a controller. - * The first argument (cmd) will tell whether the controller was added - * (KCI_CONTRUP) or removed (KCI_CONTRDOWN). - * The second argument (contr) will be the controller number. - * For cmd==KCI_CONTRUP the third argument (data) will be a pointer to the - * new controller's capability profile structure. - */ - -void capi20_set_callback(struct capi20_appl *ap, - void (*callback) (unsigned int cmd, __u32 contr, void *data)) -{ - ap->callback = callback; -} - -EXPORT_SYMBOL(capi20_set_callback); - /* ------------------------------------------------------------- */ /* -------- Init & Cleanup ------------------------------------- */ /* ------------------------------------------------------------- */ @@ -1169,10 +1152,17 @@ EXPORT_SYMBOL(capi20_set_callback); * init / exit functions */ +static struct notifier_block capictr_nb = { + .notifier_call = notify_handler, + .priority = INT_MAX, +}; + static int __init kcapi_init(void) { int err; + register_capictr_notifier(&capictr_nb); + err = cdebug_init(); if (!err) kcapi_proc_init(); -- cgit v1.2.3 From 0ca3a017a7373a4545dd7b345a8a0cecc16bc7e2 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:14 +0000 Subject: CAPI: Rework locking of controller data structures This patch applies the mutex so far only protecting the controller list to (almost) all accesses of controller data structures. It also reworks waiting on state changes in old_capi_manufacturer so that it no longer poll and holds a module reference to the controller owner while waiting (the latter was partly done already). Modification and checking of the blocked state remains racy by design, the caller is responsible for dealing with this. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/kcapi.c | 291 +++++++++++++++++++++++++++++------------ drivers/isdn/capi/kcapi.h | 5 +- drivers/isdn/capi/kcapi_proc.c | 5 + 3 files changed, 214 insertions(+), 87 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index e08914d33be1..a99f7e3f8f51 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -61,11 +61,12 @@ static char capi_manufakturer[64] = "AVM Berlin"; LIST_HEAD(capi_drivers); DEFINE_MUTEX(capi_drivers_lock); +struct capi_ctr *capi_controller[CAPI_MAXCONTR]; +DEFINE_MUTEX(capi_controller_lock); + static DEFINE_RWLOCK(application_lock); -static DEFINE_MUTEX(controller_mutex); struct capi20_appl *capi_applications[CAPI_MAXAPPL]; -struct capi_ctr *capi_controller[CAPI_MAXCONTR]; static int ncontrollers; @@ -171,13 +172,15 @@ static void notify_up(u32 contr) struct capi_ctr *ctr; u16 applid; + mutex_lock(&capi_controller_lock); + if (showcapimsgs & 1) printk(KERN_DEBUG "kcapi: notify up contr %d\n", contr); ctr = get_capi_ctr_by_nr(contr); if (ctr) { if (ctr->state == CAPI_CTR_RUNNING) - return; + goto unlock_out; ctr->state = CAPI_CTR_RUNNING; @@ -187,19 +190,24 @@ static void notify_up(u32 contr) continue; register_appl(ctr, applid, &ap->rparam); } + + wake_up_interruptible_all(&ctr->state_wait_queue); } else printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); + +unlock_out: + mutex_unlock(&capi_controller_lock); } -static void ctr_down(struct capi_ctr *ctr) +static void ctr_down(struct capi_ctr *ctr, int new_state) { struct capi20_appl *ap; u16 applid; - if (ctr->state == CAPI_CTR_DETECTED) + if (ctr->state == CAPI_CTR_DETECTED || ctr->state == CAPI_CTR_DETACHED) return; - ctr->state = CAPI_CTR_DETECTED; + ctr->state = new_state; memset(ctr->manu, 0, sizeof(ctr->manu)); memset(&ctr->version, 0, sizeof(ctr->version)); @@ -211,20 +219,26 @@ static void ctr_down(struct capi_ctr *ctr) if (ap && !ap->release_in_progress) capi_ctr_put(ctr); } + + wake_up_interruptible_all(&ctr->state_wait_queue); } static void notify_down(u32 contr) { struct capi_ctr *ctr; + mutex_lock(&capi_controller_lock); + if (showcapimsgs & 1) printk(KERN_DEBUG "kcapi: notify down contr %d\n", contr); ctr = get_capi_ctr_by_nr(contr); if (ctr) - ctr_down(ctr); + ctr_down(ctr, CAPI_CTR_DETECTED); else printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); + + mutex_unlock(&capi_controller_lock); } static int @@ -436,6 +450,9 @@ EXPORT_SYMBOL(capi_ctr_down); * @ctr: controller descriptor structure. * * Called by hardware driver to stop data flow. + * + * Note: The caller is responsible for synchronizing concurrent state changes + * as well as invocations of capi_ctr_handle_message. */ void capi_ctr_suspend_output(struct capi_ctr *ctr) @@ -454,6 +471,9 @@ EXPORT_SYMBOL(capi_ctr_suspend_output); * @ctr: controller descriptor structure. * * Called by hardware driver to resume data flow. + * + * Note: The caller is responsible for synchronizing concurrent state changes + * as well as invocations of capi_ctr_handle_message. */ void capi_ctr_resume_output(struct capi_ctr *ctr) @@ -481,21 +501,19 @@ int attach_capi_ctr(struct capi_ctr *ctr) { int i; - mutex_lock(&controller_mutex); + mutex_lock(&capi_controller_lock); for (i = 0; i < CAPI_MAXCONTR; i++) { if (!capi_controller[i]) break; } if (i == CAPI_MAXCONTR) { - mutex_unlock(&controller_mutex); + mutex_unlock(&capi_controller_lock); printk(KERN_ERR "kcapi: out of controller slots\n"); return -EBUSY; } capi_controller[i] = ctr; - mutex_unlock(&controller_mutex); - ctr->nrecvctlpkt = 0; ctr->nrecvdatapkt = 0; ctr->nsentctlpkt = 0; @@ -504,11 +522,15 @@ int attach_capi_ctr(struct capi_ctr *ctr) ctr->state = CAPI_CTR_DETECTED; ctr->blocked = 0; ctr->traceflag = showcapimsgs; + init_waitqueue_head(&ctr->state_wait_queue); sprintf(ctr->procfn, "capi/controllers/%d", ctr->cnr); ctr->procent = proc_create_data(ctr->procfn, 0, NULL, ctr->proc_fops, ctr); ncontrollers++; + + mutex_unlock(&capi_controller_lock); + printk(KERN_NOTICE "kcapi: controller [%03d]: %s attached\n", ctr->cnr, ctr->name); return 0; @@ -527,19 +549,29 @@ EXPORT_SYMBOL(attach_capi_ctr); int detach_capi_ctr(struct capi_ctr *ctr) { - ctr_down(ctr); + int err = 0; - ncontrollers--; + mutex_lock(&capi_controller_lock); - if (ctr->procent) { - remove_proc_entry(ctr->procfn, NULL); - ctr->procent = NULL; + ctr_down(ctr, CAPI_CTR_DETACHED); + + if (capi_controller[ctr->cnr - 1] != ctr) { + err = -EINVAL; + goto unlock_out; } capi_controller[ctr->cnr - 1] = NULL; + ncontrollers--; + + if (ctr->procent) + remove_proc_entry(ctr->procfn, NULL); + printk(KERN_NOTICE "kcapi: controller [%03d]: %s unregistered\n", ctr->cnr, ctr->name); - return 0; +unlock_out: + mutex_unlock(&capi_controller_lock); + + return err; } EXPORT_SYMBOL(detach_capi_ctr); @@ -589,13 +621,21 @@ EXPORT_SYMBOL(unregister_capi_driver); u16 capi20_isinstalled(void) { + u16 ret = CAPI_REGNOTINSTALLED; int i; - for (i = 0; i < CAPI_MAXCONTR; i++) { + + mutex_lock(&capi_controller_lock); + + for (i = 0; i < CAPI_MAXCONTR; i++) if (capi_controller[i] && - capi_controller[i]->state == CAPI_CTR_RUNNING) - return CAPI_NOERROR; - } - return CAPI_REGNOTINSTALLED; + capi_controller[i]->state == CAPI_CTR_RUNNING) { + ret = CAPI_NOERROR; + break; + } + + mutex_unlock(&capi_controller_lock); + + return ret; } EXPORT_SYMBOL(capi20_isinstalled); @@ -648,14 +688,16 @@ u16 capi20_register(struct capi20_appl *ap) write_unlock_irqrestore(&application_lock, flags); - mutex_lock(&controller_mutex); + mutex_lock(&capi_controller_lock); + for (i = 0; i < CAPI_MAXCONTR; i++) { if (!capi_controller[i] || capi_controller[i]->state != CAPI_CTR_RUNNING) continue; register_appl(capi_controller[i], applid, &ap->rparam); } - mutex_unlock(&controller_mutex); + + mutex_unlock(&capi_controller_lock); if (showcapimsgs & 1) { printk(KERN_DEBUG "kcapi: appl %d up\n", applid); @@ -688,14 +730,16 @@ u16 capi20_release(struct capi20_appl *ap) capi_applications[ap->applid - 1] = NULL; write_unlock_irqrestore(&application_lock, flags); - mutex_lock(&controller_mutex); + mutex_lock(&capi_controller_lock); + for (i = 0; i < CAPI_MAXCONTR; i++) { if (!capi_controller[i] || capi_controller[i]->state != CAPI_CTR_RUNNING) continue; release_appl(capi_controller[i], ap->applid); } - mutex_unlock(&controller_mutex); + + mutex_unlock(&capi_controller_lock); flush_scheduled_work(); skb_queue_purge(&ap->recv_queue); @@ -734,6 +778,12 @@ u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb) || !capi_cmd_valid(CAPIMSG_COMMAND(skb->data)) || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb->data))) return CAPI_ILLCMDORSUBCMDORMSGTOSMALL; + + /* + * The controller reference is protected by the existence of the + * application passed to us. We assume that the caller properly + * synchronizes this service with capi20_release. + */ ctr = get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb->data)); if (!ctr || ctr->state != CAPI_CTR_RUNNING) { ctr = get_capi_ctr_by_nr(1); /* XXX why? */ @@ -798,16 +848,24 @@ EXPORT_SYMBOL(capi20_put_message); u16 capi20_get_manufacturer(u32 contr, u8 *buf) { struct capi_ctr *ctr; + u16 ret; if (contr == 0) { strlcpy(buf, capi_manufakturer, CAPI_MANUFACTURER_LEN); return CAPI_NOERROR; } + + mutex_lock(&capi_controller_lock); + ctr = get_capi_ctr_by_nr(contr); - if (!ctr || ctr->state != CAPI_CTR_RUNNING) - return CAPI_REGNOTINSTALLED; - strlcpy(buf, ctr->manu, CAPI_MANUFACTURER_LEN); - return CAPI_NOERROR; + if (ctr && ctr->state == CAPI_CTR_RUNNING) { + strlcpy(buf, ctr->manu, CAPI_MANUFACTURER_LEN); + ret = CAPI_NOERROR; + } else + ret = CAPI_REGNOTINSTALLED; + + mutex_unlock(&capi_controller_lock); + return ret; } EXPORT_SYMBOL(capi20_get_manufacturer); @@ -825,17 +883,24 @@ EXPORT_SYMBOL(capi20_get_manufacturer); u16 capi20_get_version(u32 contr, struct capi_version *verp) { struct capi_ctr *ctr; + u16 ret; if (contr == 0) { *verp = driver_version; return CAPI_NOERROR; } + + mutex_lock(&capi_controller_lock); + ctr = get_capi_ctr_by_nr(contr); - if (!ctr || ctr->state != CAPI_CTR_RUNNING) - return CAPI_REGNOTINSTALLED; + if (ctr && ctr->state == CAPI_CTR_RUNNING) { + memcpy(verp, &ctr->version, sizeof(capi_version)); + ret = CAPI_NOERROR; + } else + ret = CAPI_REGNOTINSTALLED; - memcpy(verp, &ctr->version, sizeof(capi_version)); - return CAPI_NOERROR; + mutex_unlock(&capi_controller_lock); + return ret; } EXPORT_SYMBOL(capi20_get_version); @@ -853,17 +918,24 @@ EXPORT_SYMBOL(capi20_get_version); u16 capi20_get_serial(u32 contr, u8 *serial) { struct capi_ctr *ctr; + u16 ret; if (contr == 0) { strlcpy(serial, driver_serial, CAPI_SERIAL_LEN); return CAPI_NOERROR; } + + mutex_lock(&capi_controller_lock); + ctr = get_capi_ctr_by_nr(contr); - if (!ctr || ctr->state != CAPI_CTR_RUNNING) - return CAPI_REGNOTINSTALLED; + if (ctr && ctr->state == CAPI_CTR_RUNNING) { + strlcpy(serial, ctr->serial, CAPI_SERIAL_LEN); + ret = CAPI_NOERROR; + } else + ret = CAPI_REGNOTINSTALLED; - strlcpy(serial, ctr->serial, CAPI_SERIAL_LEN); - return CAPI_NOERROR; + mutex_unlock(&capi_controller_lock); + return ret; } EXPORT_SYMBOL(capi20_get_serial); @@ -881,21 +953,64 @@ EXPORT_SYMBOL(capi20_get_serial); u16 capi20_get_profile(u32 contr, struct capi_profile *profp) { struct capi_ctr *ctr; + u16 ret; if (contr == 0) { profp->ncontroller = ncontrollers; return CAPI_NOERROR; } + + mutex_lock(&capi_controller_lock); + ctr = get_capi_ctr_by_nr(contr); - if (!ctr || ctr->state != CAPI_CTR_RUNNING) - return CAPI_REGNOTINSTALLED; + if (ctr && ctr->state == CAPI_CTR_RUNNING) { + memcpy(profp, &ctr->profile, sizeof(struct capi_profile)); + ret = CAPI_NOERROR; + } else + ret = CAPI_REGNOTINSTALLED; - memcpy(profp, &ctr->profile, sizeof(struct capi_profile)); - return CAPI_NOERROR; + mutex_unlock(&capi_controller_lock); + return ret; } EXPORT_SYMBOL(capi20_get_profile); +/* Must be called with capi_controller_lock held. */ +static int wait_on_ctr_state(struct capi_ctr *ctr, unsigned int state) +{ + DEFINE_WAIT(wait); + int retval = 0; + + ctr = capi_ctr_get(ctr); + if (!ctr) + return -ESRCH; + + for (;;) { + prepare_to_wait(&ctr->state_wait_queue, &wait, + TASK_INTERRUPTIBLE); + + if (ctr->state == state) + break; + if (ctr->state == CAPI_CTR_DETACHED) { + retval = -ESRCH; + break; + } + if (signal_pending(current)) { + retval = -EINTR; + break; + } + + mutex_unlock(&capi_controller_lock); + schedule(); + mutex_lock(&capi_controller_lock); + } + finish_wait(&ctr->state_wait_queue, &wait); + + capi_ctr_put(ctr); + + return retval; +} + #ifdef AVMB1_COMPAT static int old_capi_manufacturer(unsigned int cmd, void __user *data) { @@ -973,27 +1088,30 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) sizeof(avmb1_loadandconfigdef))) return -EFAULT; } + + mutex_lock(&capi_controller_lock); + ctr = get_capi_ctr_by_nr(ldef.contr); - if (!ctr) - return -EINVAL; - ctr = capi_ctr_get(ctr); - if (!ctr) - return -ESRCH; + if (!ctr) { + retval = -EINVAL; + goto load_unlock_out; + } + if (ctr->load_firmware == NULL) { printk(KERN_DEBUG "kcapi: load: no load function\n"); - capi_ctr_put(ctr); - return -ESRCH; + retval = -ESRCH; + goto load_unlock_out; } if (ldef.t4file.len <= 0) { printk(KERN_DEBUG "kcapi: load: invalid parameter: length of t4file is %d ?\n", ldef.t4file.len); - capi_ctr_put(ctr); - return -EINVAL; + retval = -EINVAL; + goto load_unlock_out; } if (ldef.t4file.data == NULL) { printk(KERN_DEBUG "kcapi: load: invalid parameter: dataptr is 0\n"); - capi_ctr_put(ctr); - return -EINVAL; + retval = -EINVAL; + goto load_unlock_out; } ldata.firmware.user = 1; @@ -1005,52 +1123,47 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) if (ctr->state != CAPI_CTR_DETECTED) { printk(KERN_INFO "kcapi: load: contr=%d not in detect state\n", ldef.contr); - capi_ctr_put(ctr); - return -EBUSY; + retval = -EBUSY; + goto load_unlock_out; } ctr->state = CAPI_CTR_LOADING; retval = ctr->load_firmware(ctr, &ldata); - if (retval) { ctr->state = CAPI_CTR_DETECTED; - capi_ctr_put(ctr); - return retval; + goto load_unlock_out; } - while (ctr->state != CAPI_CTR_RUNNING) { - - msleep_interruptible(100); /* 0.1 sec */ + retval = wait_on_ctr_state(ctr, CAPI_CTR_RUNNING); - if (signal_pending(current)) { - capi_ctr_put(ctr); - return -EINTR; - } - } - capi_ctr_put(ctr); - return 0; +load_unlock_out: + mutex_unlock(&capi_controller_lock); + return retval; case AVMB1_RESETCARD: if (copy_from_user(&rdef, data, sizeof(avmb1_resetdef))) return -EFAULT; + + retval = 0; + + mutex_lock(&capi_controller_lock); + ctr = get_capi_ctr_by_nr(rdef.contr); - if (!ctr) - return -ESRCH; + if (!ctr) { + retval = -ESRCH; + goto reset_unlock_out; + } if (ctr->state == CAPI_CTR_DETECTED) - return 0; + goto reset_unlock_out; ctr->reset_ctr(ctr); - while (ctr->state > CAPI_CTR_DETECTED) { - - msleep_interruptible(100); /* 0.1 sec */ - - if (signal_pending(current)) - return -EINTR; - } - return 0; + retval = wait_on_ctr_state(ctr, CAPI_CTR_DETECTED); +reset_unlock_out: + mutex_unlock(&capi_controller_lock); + return retval; } return -EINVAL; } @@ -1068,6 +1181,7 @@ static int old_capi_manufacturer(unsigned int cmd, void __user *data) int capi20_manufacturer(unsigned int cmd, void __user *data) { struct capi_ctr *ctr; + int retval; switch (cmd) { #ifdef AVMB1_COMPAT @@ -1085,14 +1199,20 @@ int capi20_manufacturer(unsigned int cmd, void __user *data) if (copy_from_user(&fdef, data, sizeof(kcapi_flagdef))) return -EFAULT; + mutex_lock(&capi_controller_lock); + ctr = get_capi_ctr_by_nr(fdef.contr); - if (!ctr) - return -ESRCH; + if (ctr) { + ctr->traceflag = fdef.flag; + printk(KERN_INFO "kcapi: contr [%03d] set trace=%d\n", + ctr->cnr, ctr->traceflag); + retval = 0; + } else + retval = -ESRCH; + + mutex_unlock(&capi_controller_lock); - ctr->traceflag = fdef.flag; - printk(KERN_INFO "kcapi: contr [%03d] set trace=%d\n", - ctr->cnr, ctr->traceflag); - return 0; + return retval; } case KCAPI_CMD_ADDCARD: { @@ -1100,7 +1220,6 @@ int capi20_manufacturer(unsigned int cmd, void __user *data) struct capi_driver *driver = NULL; capicardparams cparams; kcapi_carddef cdef; - int retval; if ((retval = copy_from_user(&cdef, data, sizeof(cdef)))) return retval; diff --git a/drivers/isdn/capi/kcapi.h b/drivers/isdn/capi/kcapi.h index 07c58500fe48..f4620b38ec51 100644 --- a/drivers/isdn/capi/kcapi.h +++ b/drivers/isdn/capi/kcapi.h @@ -24,6 +24,7 @@ printk(KERN_DEBUG "%s: " format "\n" , __func__ , ## arg); \ #endif enum { + CAPI_CTR_DETACHED = 0, CAPI_CTR_DETECTED = 1, CAPI_CTR_LOADING = 2, CAPI_CTR_RUNNING = 3, @@ -32,8 +33,10 @@ enum { extern struct list_head capi_drivers; extern struct mutex capi_drivers_lock; -extern struct capi20_appl *capi_applications[CAPI_MAXAPPL]; extern struct capi_ctr *capi_controller[CAPI_MAXCONTR]; +extern struct mutex capi_controller_lock; + +extern struct capi20_appl *capi_applications[CAPI_MAXAPPL]; #ifdef CONFIG_PROC_FS diff --git a/drivers/isdn/capi/kcapi_proc.c b/drivers/isdn/capi/kcapi_proc.c index 71b07610ff31..3e6e17a24389 100644 --- a/drivers/isdn/capi/kcapi_proc.c +++ b/drivers/isdn/capi/kcapi_proc.c @@ -35,7 +35,10 @@ static char *state2str(unsigned short state) // --------------------------------------------------------------------------- static void *controller_start(struct seq_file *seq, loff_t *pos) + __acquires(capi_controller_lock) { + mutex_lock(&capi_controller_lock); + if (*pos < CAPI_MAXCONTR) return &capi_controller[*pos]; @@ -52,7 +55,9 @@ static void *controller_next(struct seq_file *seq, void *v, loff_t *pos) } static void controller_stop(struct seq_file *seq, void *v) + __releases(capi_controller_lock) { + mutex_unlock(&capi_controller_lock); } static int controller_show(struct seq_file *seq, void *v) -- cgit v1.2.3 From 88c896ef87fd0dd4dbf36e8e86e019c74b1f6649 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:15 +0000 Subject: CAPI: Rework application locking Drop the application rw-lock in favour of RCU. This synchronizes capi20_release against capi_ctr_handle_message which may dereference an application from (soft-)IRQ context. Any other access to the application list is now protected by the capi_controller_lock as well. This also allows to safely inspect applications for /proc dumping by holding capi_controller_lock. At this chance, drop some useless release_in_progress checks where we obtained the application pointer from the list (which becomes NULL on release_in_progress). Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/kcapi.c | 52 ++++++++++++++++++------------------------ drivers/isdn/capi/kcapi_proc.c | 11 +++++---- 2 files changed, 29 insertions(+), 34 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index a99f7e3f8f51..0b4c8a7396bc 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -34,6 +34,7 @@ #include #endif #include +#include static int showcapimsgs = 0; @@ -64,8 +65,6 @@ DEFINE_MUTEX(capi_drivers_lock); struct capi_ctr *capi_controller[CAPI_MAXCONTR]; DEFINE_MUTEX(capi_controller_lock); -static DEFINE_RWLOCK(application_lock); - struct capi20_appl *capi_applications[CAPI_MAXAPPL]; static int ncontrollers; @@ -103,7 +102,7 @@ static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid) if (applid - 1 >= CAPI_MAXAPPL) return NULL; - return capi_applications[applid - 1]; + return rcu_dereference(capi_applications[applid - 1]); } /* -------- util functions ------------------------------------ */ @@ -186,7 +185,7 @@ static void notify_up(u32 contr) for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { ap = get_capi_appl_by_nr(applid); - if (!ap || ap->release_in_progress) + if (!ap) continue; register_appl(ctr, applid, &ap->rparam); } @@ -216,7 +215,7 @@ static void ctr_down(struct capi_ctr *ctr, int new_state) for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { ap = get_capi_appl_by_nr(applid); - if (ap && !ap->release_in_progress) + if (ap) capi_ctr_put(ctr); } @@ -336,7 +335,6 @@ void capi_ctr_handle_message(struct capi_ctr *ctr, u16 appl, struct capi20_appl *ap; int showctl = 0; u8 cmd, subcmd; - unsigned long flags; _cdebbuf *cdb; if (ctr->state != CAPI_CTR_RUNNING) { @@ -384,10 +382,10 @@ void capi_ctr_handle_message(struct capi_ctr *ctr, u16 appl, } - read_lock_irqsave(&application_lock, flags); + rcu_read_lock(); ap = get_capi_appl_by_nr(CAPIMSG_APPID(skb->data)); - if ((!ap) || (ap->release_in_progress)) { - read_unlock_irqrestore(&application_lock, flags); + if (!ap) { + rcu_read_unlock(); cdb = capi_message2str(skb->data); if (cdb) { printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s)\n", @@ -401,7 +399,7 @@ void capi_ctr_handle_message(struct capi_ctr *ctr, u16 appl, } skb_queue_tail(&ap->recv_queue, skb); schedule_work(&ap->recv_work); - read_unlock_irqrestore(&application_lock, flags); + rcu_read_unlock(); return; @@ -656,40 +654,35 @@ u16 capi20_register(struct capi20_appl *ap) { int i; u16 applid; - unsigned long flags; DBG(""); if (ap->rparam.datablklen < 128) return CAPI_LOGBLKSIZETOSMALL; - write_lock_irqsave(&application_lock, flags); + ap->nrecvctlpkt = 0; + ap->nrecvdatapkt = 0; + ap->nsentctlpkt = 0; + ap->nsentdatapkt = 0; + mutex_init(&ap->recv_mtx); + skb_queue_head_init(&ap->recv_queue); + INIT_WORK(&ap->recv_work, recv_handler); + ap->release_in_progress = 0; + + mutex_lock(&capi_controller_lock); for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { if (capi_applications[applid - 1] == NULL) break; } if (applid > CAPI_MAXAPPL) { - write_unlock_irqrestore(&application_lock, flags); + mutex_unlock(&capi_controller_lock); return CAPI_TOOMANYAPPLS; } ap->applid = applid; capi_applications[applid - 1] = ap; - ap->nrecvctlpkt = 0; - ap->nrecvdatapkt = 0; - ap->nsentctlpkt = 0; - ap->nsentdatapkt = 0; - mutex_init(&ap->recv_mtx); - skb_queue_head_init(&ap->recv_queue); - INIT_WORK(&ap->recv_work, recv_handler); - ap->release_in_progress = 0; - - write_unlock_irqrestore(&application_lock, flags); - - mutex_lock(&capi_controller_lock); - for (i = 0; i < CAPI_MAXCONTR; i++) { if (!capi_controller[i] || capi_controller[i]->state != CAPI_CTR_RUNNING) @@ -721,16 +714,15 @@ EXPORT_SYMBOL(capi20_register); u16 capi20_release(struct capi20_appl *ap) { int i; - unsigned long flags; DBG("applid %#x", ap->applid); - write_lock_irqsave(&application_lock, flags); + mutex_lock(&capi_controller_lock); + ap->release_in_progress = 1; capi_applications[ap->applid - 1] = NULL; - write_unlock_irqrestore(&application_lock, flags); - mutex_lock(&capi_controller_lock); + synchronize_rcu(); for (i = 0; i < CAPI_MAXCONTR; i++) { if (!capi_controller[i] || diff --git a/drivers/isdn/capi/kcapi_proc.c b/drivers/isdn/capi/kcapi_proc.c index 3e6e17a24389..ea2dff602e49 100644 --- a/drivers/isdn/capi/kcapi_proc.c +++ b/drivers/isdn/capi/kcapi_proc.c @@ -139,9 +139,11 @@ static const struct file_operations proc_contrstats_ops = { // applid nrecvctlpkt nrecvdatapkt nsentctlpkt nsentdatapkt // --------------------------------------------------------------------------- -static void * -applications_start(struct seq_file *seq, loff_t *pos) +static void *applications_start(struct seq_file *seq, loff_t *pos) + __acquires(capi_controller_lock) { + mutex_lock(&capi_controller_lock); + if (*pos < CAPI_MAXAPPL) return &capi_applications[*pos]; @@ -158,9 +160,10 @@ applications_next(struct seq_file *seq, void *v, loff_t *pos) return NULL; } -static void -applications_stop(struct seq_file *seq, void *v) +static void applications_stop(struct seq_file *seq, void *v) + __releases(capi_controller_lock) { + mutex_unlock(&capi_controller_lock); } static int -- cgit v1.2.3 From 501c87a91909efaad91425635b29b01f1473c659 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:16 +0000 Subject: CAPI: Reduce #ifdef mess around CONFIG_ISDN_CAPI_MIDDLEWARE Make the code a bit more readable be providing stub functions for the !CONFIG_ISDN_CAPI_MIDDLEWARE case. Though a few lines are moved around, this comes with no functional changes. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 150 ++++++++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 67 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 3b077978c496..7d2ca6b2564c 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -23,14 +23,10 @@ #include #include #include -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE #include -#ifdef CONFIG_PPP #include #include #include -#endif /* CONFIG_PPP */ -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ #include #include #include @@ -56,17 +52,17 @@ MODULE_LICENSE("GPL"); /* -------- driver information -------------------------------------- */ static struct class *capi_class; - static int capi_major = 68; /* allocated */ + +module_param_named(major, capi_major, uint, 0); + #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE -#define CAPINC_NR_PORTS 32 +#define CAPINC_NR_PORTS 32 #define CAPINC_MAX_PORTS 256 + static int capi_ttymajor = 191; static int capi_ttyminors = CAPINC_NR_PORTS; -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ -module_param_named(major, capi_major, uint, 0); -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE module_param_named(ttymajor, capi_ttymajor, uint, 0); module_param_named(ttyminors, capi_ttyminors, uint, 0); #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ @@ -81,7 +77,6 @@ module_param_named(ttyminors, capi_ttyminors, uint, 0); struct capidev; struct capincci; -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE struct capiminor; struct datahandle_queue { @@ -116,7 +111,6 @@ struct capiminor { int nack; spinlock_t ackqlock; }; -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ /* FIXME: The following lock is a sledgehammer-workaround to a * locking issue with the capiminor (and maybe other) data structure(s). @@ -156,14 +150,13 @@ static DEFINE_RWLOCK(capidev_list_lock); static LIST_HEAD(capidev_list); #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE + static DEFINE_RWLOCK(capiminor_list_lock); static LIST_HEAD(capiminor_list); -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE /* -------- datahandles --------------------------------------------- */ -static int capincci_add_ack(struct capiminor *mp, u16 datahandle) +static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) { struct datahandle_queue *n; unsigned long flags; @@ -301,26 +294,17 @@ static struct capiminor *capiminor_find(unsigned int minor) return p; } -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ /* -------- struct capincci ----------------------------------------- */ -static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) +static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) { - struct capincci *np, **pp; -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE - struct capiminor *mp = NULL; -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ + struct capiminor *mp; - np = kzalloc(sizeof(*np), GFP_ATOMIC); - if (!np) - return NULL; - np->ncci = ncci; - np->cdev = cdev; -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE - mp = NULL; - if (cdev->userflags & CAPIFLAG_HIGHJACKING) - mp = np->minorp = capiminor_alloc(&cdev->ap, ncci); + if (!(cdev->userflags & CAPIFLAG_HIGHJACKING)) + return; + + mp = np->minorp = capiminor_alloc(&cdev->ap, np->ncci); if (mp) { mp->nccip = np; #ifdef _DEBUG_REFCOUNT @@ -330,7 +314,58 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) capifs_new_ncci(mp->minor, MKDEV(capi_ttymajor, mp->minor)); } -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ +} + +static void capincci_free_minor(struct capincci *np) +{ + struct capiminor *mp = np->minorp; + + if (mp) { + capifs_free_ncci(mp->capifs_dentry); + if (mp->tty) { + mp->nccip = NULL; +#ifdef _DEBUG_REFCOUNT + printk(KERN_DEBUG "reset mp->nccip\n"); +#endif + tty_hangup(mp->tty); + } else { + capiminor_free(mp); + } + } +} + +static inline unsigned int capincci_minor_opencount(struct capincci *np) +{ + struct capiminor *mp = np->minorp; + + return mp ? atomic_read(&mp->ttyopencount) : 0; +} + +#else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ + +static inline void +capincci_alloc_minor(struct capidev *cdev, struct capincci *np) { } +static inline void capincci_free_minor(struct capincci *np) { } + +static inline unsigned int capincci_minor_opencount(struct capincci *np) +{ + return 0; +} + +#endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ + +static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) +{ + struct capincci *np, **pp; + + np = kzalloc(sizeof(*np), GFP_ATOMIC); + if (!np) + return NULL; + np->ncci = ncci; + np->cdev = cdev; + + capincci_alloc_minor(cdev, np); + for (pp=&cdev->nccis; *pp; pp = &(*pp)->next) ; *pp = np; @@ -340,29 +375,13 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) static void capincci_free(struct capidev *cdev, u32 ncci) { struct capincci *np, **pp; -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE - struct capiminor *mp; -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ pp=&cdev->nccis; while (*pp) { np = *pp; if (ncci == 0xffffffff || np->ncci == ncci) { *pp = (*pp)->next; -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE - if ((mp = np->minorp) != NULL) { - capifs_free_ncci(mp->capifs_dentry); - if (mp->tty) { - mp->nccip = NULL; -#ifdef _DEBUG_REFCOUNT - printk(KERN_DEBUG "reset mp->nccip\n"); -#endif - tty_hangup(mp->tty); - } else { - capiminor_free(mp); - } - } -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ + capincci_free_minor(np); kfree(np); if (*pp == NULL) return; } else { @@ -552,7 +571,7 @@ static int handle_minor_send(struct capiminor *mp) capimsg_setu16(skb->data, 18, datahandle); capimsg_setu16(skb->data, 20, 0); /* Flags */ - if (capincci_add_ack(mp, datahandle) < 0) { + if (capiminor_add_ack(mp, datahandle) < 0) { skb_pull(skb, CAPI_DATA_B3_REQ_LEN); skb_queue_head(&mp->outqueue, skb); return count; @@ -628,10 +647,13 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) spin_unlock_irqrestore(&workaround_lock, flags); return; } + #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE skb_queue_tail(&cdev->recvqueue, skb); wake_up_interruptible(&cdev->recvwait); + #else /* CONFIG_ISDN_CAPI_MIDDLEWARE */ + mp = np->minorp; if (!mp) { skb_queue_tail(&cdev->recvqueue, skb); @@ -639,10 +661,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) spin_unlock_irqrestore(&workaround_lock, flags); return; } - - if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) { - datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2); #ifdef _DEBUG_DATAFLOW printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n", @@ -672,6 +691,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) wake_up_interruptible(&cdev->recvwait); } #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ + spin_unlock_irqrestore(&workaround_lock, flags); } @@ -929,9 +949,6 @@ capi_ioctl(struct inode *inode, struct file *file, case CAPI_NCCI_OPENCOUNT: { struct capincci *nccip; -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE - struct capiminor *mp; -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ unsigned ncci; int count = 0; if (copy_from_user(&ncci, argp, sizeof(ncci))) @@ -942,11 +959,7 @@ capi_ioctl(struct inode *inode, struct file *file, mutex_unlock(&cdev->ncci_list_mtx); return 0; } -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE - if ((mp = nccip->minorp) != NULL) { - count += atomic_read(&mp->ttyopencount); - } -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ + count += capincci_minor_opencount(nccip); mutex_unlock(&cdev->ncci_list_mtx); return count; } @@ -1396,7 +1409,16 @@ static void capinc_tty_exit(void) put_tty_driver(drv); } -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ +#else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ + +static inline int capinc_tty_init(void) +{ + return 0; +} + +static inline void capinc_tty_exit(void) { } + +#endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ /* -------- /proc functions ----------------------------------------- */ @@ -1505,23 +1527,19 @@ static int __init capi_init(void) device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi"); -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE if (capinc_tty_init() < 0) { device_destroy(capi_class, MKDEV(capi_major, 0)); class_destroy(capi_class); unregister_chrdev(capi_major, "capi20"); return -ENOMEM; } -#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ proc_init(); -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) compileinfo = " (middleware+capifs)"; -#else +#elif defined(CONFIG_ISDN_CAPI_MIDDLEWARE) compileinfo = " (no capifs)"; -#endif #else compileinfo = " (no middleware)"; #endif @@ -1539,9 +1557,7 @@ static void __exit capi_exit(void) class_destroy(capi_class); unregister_chrdev(capi_major, "capi20"); -#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE capinc_tty_exit(); -#endif } module_init(capi_init); -- cgit v1.2.3 From b8f433dc5cd9b910c12ef5cca351bf720d3e68c1 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:17 +0000 Subject: CAPI: Convert capidev_list_lock into a mutex No need for anything "harder" here (specifically no need for irqsave...). Also, make the list removal the first operation of capidev_free to avoid dumping half-released devices via /proc. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 7d2ca6b2564c..623412e22c14 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -146,7 +146,7 @@ struct capidev { /* -------- global variables ---------------------------------------- */ -static DEFINE_RWLOCK(capidev_list_lock); +static DEFINE_MUTEX(capidev_list_lock); static LIST_HEAD(capidev_list); #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE @@ -406,7 +406,6 @@ static struct capincci *capincci_find(struct capidev *cdev, u32 ncci) static struct capidev *capidev_alloc(void) { struct capidev *cdev; - unsigned long flags; cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); if (!cdev) @@ -415,15 +414,19 @@ static struct capidev *capidev_alloc(void) mutex_init(&cdev->ncci_list_mtx); skb_queue_head_init(&cdev->recvqueue); init_waitqueue_head(&cdev->recvwait); - write_lock_irqsave(&capidev_list_lock, flags); + + mutex_lock(&capidev_list_lock); list_add_tail(&cdev->list, &capidev_list); - write_unlock_irqrestore(&capidev_list_lock, flags); + mutex_unlock(&capidev_list_lock); + return cdev; } static void capidev_free(struct capidev *cdev) { - unsigned long flags; + mutex_lock(&capidev_list_lock); + list_del(&cdev->list); + mutex_unlock(&capidev_list_lock); if (cdev->ap.applid) { capi20_release(&cdev->ap); @@ -435,9 +438,6 @@ static void capidev_free(struct capidev *cdev) capincci_free(cdev, 0xffffffff); mutex_unlock(&cdev->ncci_list_mtx); - write_lock_irqsave(&capidev_list_lock, flags); - list_del(&cdev->list); - write_unlock_irqrestore(&capidev_list_lock, flags); kfree(cdev); } @@ -1431,7 +1431,7 @@ static int capi20_proc_show(struct seq_file *m, void *v) struct capidev *cdev; struct list_head *l; - read_lock(&capidev_list_lock); + mutex_lock(&capidev_list_lock); list_for_each(l, &capidev_list) { cdev = list_entry(l, struct capidev, list); seq_printf(m, "0 %d %lu %lu %lu %lu\n", @@ -1441,7 +1441,7 @@ static int capi20_proc_show(struct seq_file *m, void *v) cdev->ap.nsentctlpkt, cdev->ap.nsentdatapkt); } - read_unlock(&capidev_list_lock); + mutex_unlock(&capidev_list_lock); return 0; } @@ -1468,7 +1468,7 @@ static int capi20ncci_proc_show(struct seq_file *m, void *v) struct capincci *np; struct list_head *l; - read_lock(&capidev_list_lock); + mutex_lock(&capidev_list_lock); list_for_each(l, &capidev_list) { cdev = list_entry(l, struct capidev, list); for (np=cdev->nccis; np; np = np->next) { @@ -1477,7 +1477,7 @@ static int capi20ncci_proc_show(struct seq_file *m, void *v) np->ncci); } } - read_unlock(&capidev_list_lock); + mutex_unlock(&capidev_list_lock); return 0; } -- cgit v1.2.3 From eca39dd830dbc58061aa6cd68853c39055236be3 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:18 +0000 Subject: CAPI: Clean up capi_open/release Fold capidev_alloc and capidev_free into capi_open and capi_release - there are no other users. Someone pushed a lock_kernel into capi_open. Drop it, we don't need it. Also remove the useless test from open that checks for private_data == NULL. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 93 ++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 59 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 623412e22c14..9d7c3692c7d7 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -401,46 +401,6 @@ static struct capincci *capincci_find(struct capidev *cdev, u32 ncci) return p; } -/* -------- struct capidev ------------------------------------------ */ - -static struct capidev *capidev_alloc(void) -{ - struct capidev *cdev; - - cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); - if (!cdev) - return NULL; - - mutex_init(&cdev->ncci_list_mtx); - skb_queue_head_init(&cdev->recvqueue); - init_waitqueue_head(&cdev->recvwait); - - mutex_lock(&capidev_list_lock); - list_add_tail(&cdev->list, &capidev_list); - mutex_unlock(&capidev_list_lock); - - return cdev; -} - -static void capidev_free(struct capidev *cdev) -{ - mutex_lock(&capidev_list_lock); - list_del(&cdev->list); - mutex_unlock(&capidev_list_lock); - - if (cdev->ap.applid) { - capi20_release(&cdev->ap); - cdev->ap.applid = 0; - } - skb_queue_purge(&cdev->recvqueue); - - mutex_lock(&cdev->ncci_list_mtx); - capincci_free(cdev, 0xffffffff); - mutex_unlock(&cdev->ncci_list_mtx); - - kfree(cdev); -} - #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE /* -------- handle data queue --------------------------------------- */ @@ -991,30 +951,45 @@ capi_ioctl(struct inode *inode, struct file *file, return -EINVAL; } -static int -capi_open(struct inode *inode, struct file *file) +static int capi_open(struct inode *inode, struct file *file) { - int ret; - - lock_kernel(); - if (file->private_data) - ret = -EEXIST; - else if ((file->private_data = capidev_alloc()) == NULL) - ret = -ENOMEM; - else - ret = nonseekable_open(inode, file); - unlock_kernel(); - return ret; + struct capidev *cdev; + + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); + if (!cdev) + return -ENOMEM; + + mutex_init(&cdev->ncci_list_mtx); + skb_queue_head_init(&cdev->recvqueue); + init_waitqueue_head(&cdev->recvwait); + file->private_data = cdev; + + mutex_lock(&capidev_list_lock); + list_add_tail(&cdev->list, &capidev_list); + mutex_unlock(&capidev_list_lock); + + return nonseekable_open(inode, file); } -static int -capi_release(struct inode *inode, struct file *file) +static int capi_release(struct inode *inode, struct file *file) { - struct capidev *cdev = (struct capidev *)file->private_data; + struct capidev *cdev = file->private_data; - capidev_free(cdev); - file->private_data = NULL; - + mutex_lock(&capidev_list_lock); + list_del(&cdev->list); + mutex_unlock(&capidev_list_lock); + + if (cdev->ap.applid) { + capi20_release(&cdev->ap); + cdev->ap.applid = 0; + } + skb_queue_purge(&cdev->recvqueue); + + mutex_lock(&cdev->ncci_list_mtx); + capincci_free(cdev, 0xffffffff); + mutex_unlock(&cdev->ncci_list_mtx); + + kfree(cdev); return 0; } -- cgit v1.2.3 From 05b4149433ffae789edaf569da8d998c93eed1aa Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:19 +0000 Subject: CAPI: Rework locking of capidev members Rename 'ncci_list_mtx' to 'lock', expressing that it now protects a larger set of capidev members: the NCCI list, ap.applid (ie. the registration of the application), and modifications of userflags. We do not need to protect each and every check for ap.applid because, once an application is registered, it will stay for the whole lifetime of the device. Also, there is no need to apply the capidev mutex during release (if there could be concurrent users, we would crash them anyway by freeing the device at the end of capi_release). Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 181 +++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 93 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 9d7c3692c7d7..403bf8fcb285 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -141,7 +141,7 @@ struct capidev { struct capincci *nccis; - struct mutex ncci_list_mtx; + struct mutex lock; }; /* -------- global variables ---------------------------------------- */ @@ -574,38 +574,31 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) u16 datahandle; #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ struct capincci *np; - u32 ncci; unsigned long flags; + mutex_lock(&cdev->lock); + if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) { u16 info = CAPIMSG_U16(skb->data, 12); // Info field - if ((info & 0xff00) == 0) { - mutex_lock(&cdev->ncci_list_mtx); + if ((info & 0xff00) == 0) capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); - mutex_unlock(&cdev->ncci_list_mtx); - } } - if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) { - mutex_lock(&cdev->ncci_list_mtx); + if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); - mutex_unlock(&cdev->ncci_list_mtx); - } + spin_lock_irqsave(&workaround_lock, flags); if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) { skb_queue_tail(&cdev->recvqueue, skb); wake_up_interruptible(&cdev->recvwait); - spin_unlock_irqrestore(&workaround_lock, flags); - return; + goto unlock_out; } - ncci = CAPIMSG_CONTROL(skb->data); - for (np = cdev->nccis; np && np->ncci != ncci; np = np->next) - ; + + np = capincci_find(cdev, CAPIMSG_CONTROL(skb->data)); if (!np) { printk(KERN_ERR "BUG: capi_signal: ncci not found\n"); skb_queue_tail(&cdev->recvqueue, skb); wake_up_interruptible(&cdev->recvwait); - spin_unlock_irqrestore(&workaround_lock, flags); - return; + goto unlock_out; } #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE @@ -618,8 +611,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) if (!mp) { skb_queue_tail(&cdev->recvqueue, skb); wake_up_interruptible(&cdev->recvwait); - spin_unlock_irqrestore(&workaround_lock, flags); - return; + goto unlock_out; } if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) { datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2); @@ -652,7 +644,9 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) } #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ +unlock_out: spin_unlock_irqrestore(&workaround_lock, flags); + mutex_unlock(&cdev->lock); } /* -------- file_operations for capidev ----------------------------- */ @@ -730,9 +724,9 @@ capi_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos CAPIMSG_SETAPPID(skb->data, cdev->ap.applid); if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) { - mutex_lock(&cdev->ncci_list_mtx); + mutex_lock(&cdev->lock); capincci_free(cdev, CAPIMSG_NCCI(skb->data)); - mutex_unlock(&cdev->ncci_list_mtx); + mutex_unlock(&cdev->lock); } cdev->errcode = capi20_put_message(&cdev->ap, skb); @@ -765,30 +759,35 @@ capi_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { struct capidev *cdev = file->private_data; - struct capi20_appl *ap = &cdev->ap; capi_ioctl_struct data; int retval = -EINVAL; void __user *argp = (void __user *)arg; switch (cmd) { case CAPI_REGISTER: - { - if (ap->applid) - return -EEXIST; + mutex_lock(&cdev->lock); - if (copy_from_user(&cdev->ap.rparam, argp, - sizeof(struct capi_register_params))) - return -EFAULT; - - cdev->ap.private = cdev; - cdev->ap.recv_message = capi_recv_message; - cdev->errcode = capi20_register(ap); - if (cdev->errcode) { - ap->applid = 0; - return -EIO; - } + if (cdev->ap.applid) { + retval = -EEXIST; + goto register_out; + } + if (copy_from_user(&cdev->ap.rparam, argp, + sizeof(struct capi_register_params))) { + retval = -EFAULT; + goto register_out; + } + cdev->ap.private = cdev; + cdev->ap.recv_message = capi_recv_message; + cdev->errcode = capi20_register(&cdev->ap); + retval = (int)cdev->ap.applid; + if (cdev->errcode) { + cdev->ap.applid = 0; + retval = -EIO; } - return (int)ap->applid; + +register_out: + mutex_unlock(&cdev->lock); + return retval; case CAPI_GET_VERSION: { @@ -887,68 +886,67 @@ capi_ioctl(struct inode *inode, struct file *file, return 0; case CAPI_SET_FLAGS: - case CAPI_CLR_FLAGS: - { - unsigned userflags; - if (copy_from_user(&userflags, argp, - sizeof(userflags))) - return -EFAULT; - if (cmd == CAPI_SET_FLAGS) - cdev->userflags |= userflags; - else - cdev->userflags &= ~userflags; - } - return 0; + case CAPI_CLR_FLAGS: { + unsigned userflags; + + if (copy_from_user(&userflags, argp, sizeof(userflags))) + return -EFAULT; + mutex_lock(&cdev->lock); + if (cmd == CAPI_SET_FLAGS) + cdev->userflags |= userflags; + else + cdev->userflags &= ~userflags; + mutex_unlock(&cdev->lock); + return 0; + } case CAPI_GET_FLAGS: if (copy_to_user(argp, &cdev->userflags, sizeof(cdev->userflags))) return -EFAULT; return 0; - case CAPI_NCCI_OPENCOUNT: - { - struct capincci *nccip; - unsigned ncci; - int count = 0; - if (copy_from_user(&ncci, argp, sizeof(ncci))) - return -EFAULT; + case CAPI_NCCI_OPENCOUNT: { + struct capincci *nccip; + unsigned ncci; + int count = 0; - mutex_lock(&cdev->ncci_list_mtx); - if ((nccip = capincci_find(cdev, (u32) ncci)) == NULL) { - mutex_unlock(&cdev->ncci_list_mtx); - return 0; - } - count += capincci_minor_opencount(nccip); - mutex_unlock(&cdev->ncci_list_mtx); - return count; - } - return 0; + if (copy_from_user(&ncci, argp, sizeof(ncci))) + return -EFAULT; + + mutex_lock(&cdev->lock); + nccip = capincci_find(cdev, (u32)ncci); + if (nccip) + count = capincci_minor_opencount(nccip); + mutex_unlock(&cdev->lock); + return count; + } #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE - case CAPI_NCCI_GETUNIT: - { - struct capincci *nccip; - struct capiminor *mp; - unsigned ncci; - int unit = 0; - if (copy_from_user(&ncci, argp, - sizeof(ncci))) - return -EFAULT; - mutex_lock(&cdev->ncci_list_mtx); - nccip = capincci_find(cdev, (u32) ncci); - if (!nccip || (mp = nccip->minorp) == NULL) { - mutex_unlock(&cdev->ncci_list_mtx); - return -ESRCH; - } - unit = mp->minor; - mutex_unlock(&cdev->ncci_list_mtx); - return unit; + case CAPI_NCCI_GETUNIT: { + struct capincci *nccip; + struct capiminor *mp; + unsigned ncci; + int unit = -ESRCH; + + if (copy_from_user(&ncci, argp, sizeof(ncci))) + return -EFAULT; + + mutex_lock(&cdev->lock); + nccip = capincci_find(cdev, (u32)ncci); + if (nccip) { + mp = nccip->minorp; + if (mp) + unit = mp->minor; } - return 0; + mutex_unlock(&cdev->lock); + return unit; + } #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ + + default: + return -EINVAL; } - return -EINVAL; } static int capi_open(struct inode *inode, struct file *file) @@ -959,7 +957,7 @@ static int capi_open(struct inode *inode, struct file *file) if (!cdev) return -ENOMEM; - mutex_init(&cdev->ncci_list_mtx); + mutex_init(&cdev->lock); skb_queue_head_init(&cdev->recvqueue); init_waitqueue_head(&cdev->recvwait); file->private_data = cdev; @@ -979,15 +977,10 @@ static int capi_release(struct inode *inode, struct file *file) list_del(&cdev->list); mutex_unlock(&capidev_list_lock); - if (cdev->ap.applid) { + if (cdev->ap.applid) capi20_release(&cdev->ap); - cdev->ap.applid = 0; - } skb_queue_purge(&cdev->recvqueue); - - mutex_lock(&cdev->ncci_list_mtx); capincci_free(cdev, 0xffffffff); - mutex_unlock(&cdev->ncci_list_mtx); kfree(cdev); return 0; @@ -1446,11 +1439,13 @@ static int capi20ncci_proc_show(struct seq_file *m, void *v) mutex_lock(&capidev_list_lock); list_for_each(l, &capidev_list) { cdev = list_entry(l, struct capidev, list); + mutex_lock(&cdev->lock); for (np=cdev->nccis; np; np = np->next) { seq_printf(m, "%d 0x%x\n", cdev->ap.applid, np->ncci); } + mutex_unlock(&cdev->lock); } mutex_unlock(&capidev_list_lock); return 0; -- cgit v1.2.3 From 54f0fad3d8414cf770c1cf25a1d98fcaec899b5a Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:20 +0000 Subject: CAPI: Use non-atomic allocation during NCCI setup Both capincci_alloc and capiminor_alloc run in non-atomic context, update their memory allocations accordingly. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 403bf8fcb285..f8f86602c57e 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -217,7 +217,7 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) unsigned int minor = 0; unsigned long flags; - mp = kzalloc(sizeof(*mp), GFP_ATOMIC); + mp = kzalloc(sizeof(*mp), GFP_KERNEL); if (!mp) { printk(KERN_ERR "capi: can't alloc capiminor\n"); return NULL; @@ -358,7 +358,7 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) { struct capincci *np, **pp; - np = kzalloc(sizeof(*np), GFP_ATOMIC); + np = kzalloc(sizeof(*np), GFP_KERNEL); if (!np) return NULL; np->ncci = ncci; -- cgit v1.2.3 From 28a1dbb6f7feade304f43798feb15f6978516624 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:21 +0000 Subject: CAPI: Fix racy capi_read capi_read still used interruptible_sleep_on, risking to miss a wakeup this way. Convert it to wait_event_interruptible. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index f8f86602c57e..8abec9655e1a 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -657,24 +657,19 @@ capi_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) struct capidev *cdev = (struct capidev *)file->private_data; struct sk_buff *skb; size_t copied; + int err; if (!cdev->ap.applid) return -ENODEV; - if ((skb = skb_dequeue(&cdev->recvqueue)) == NULL) { - + skb = skb_dequeue(&cdev->recvqueue); + if (!skb) { if (file->f_flags & O_NONBLOCK) return -EAGAIN; - - for (;;) { - interruptible_sleep_on(&cdev->recvwait); - if ((skb = skb_dequeue(&cdev->recvqueue)) != NULL) - break; - if (signal_pending(current)) - break; - } - if (skb == NULL) - return -ERESTARTNOHAND; + err = wait_event_interruptible(cdev->recvwait, + (skb = skb_dequeue(&cdev->recvqueue))); + if (err) + return err; } if (skb->len > count) { skb_queue_head(&cdev->recvqueue, skb); -- cgit v1.2.3 From 884f5c447901ca9da75432fe8a7a2c2a00327d22 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:22 +0000 Subject: CAPI: Switch NCCI list to standard doubly linked list Replace open-coded NCCI list management with standard mechanisms. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 52 +++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 8abec9655e1a..6704b2b004aa 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -122,7 +122,7 @@ struct capiminor { static DEFINE_SPINLOCK(workaround_lock); struct capincci { - struct capincci *next; + struct list_head list; u32 ncci; struct capidev *cdev; #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE @@ -139,7 +139,7 @@ struct capidev { struct sk_buff_head recvqueue; wait_queue_head_t recvwait; - struct capincci *nccis; + struct list_head nccis; struct mutex lock; }; @@ -356,7 +356,7 @@ static inline unsigned int capincci_minor_opencount(struct capincci *np) static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) { - struct capincci *np, **pp; + struct capincci *np; np = kzalloc(sizeof(*np), GFP_KERNEL); if (!np) @@ -366,39 +366,31 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) capincci_alloc_minor(cdev, np); - for (pp=&cdev->nccis; *pp; pp = &(*pp)->next) - ; - *pp = np; - return np; + list_add_tail(&np->list, &cdev->nccis); + + return np; } static void capincci_free(struct capidev *cdev, u32 ncci) { - struct capincci *np, **pp; + struct capincci *np, *tmp; - pp=&cdev->nccis; - while (*pp) { - np = *pp; + list_for_each_entry_safe(np, tmp, &cdev->nccis, list) if (ncci == 0xffffffff || np->ncci == ncci) { - *pp = (*pp)->next; capincci_free_minor(np); + list_del(&np->list); kfree(np); - if (*pp == NULL) return; - } else { - pp = &(*pp)->next; } - } } static struct capincci *capincci_find(struct capidev *cdev, u32 ncci) { - struct capincci *p; + struct capincci *np; - for (p=cdev->nccis; p ; p = p->next) { - if (p->ncci == ncci) - break; - } - return p; + list_for_each_entry(np, &cdev->nccis, list) + if (np->ncci == ncci) + return np; + return NULL; } #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE @@ -955,6 +947,7 @@ static int capi_open(struct inode *inode, struct file *file) mutex_init(&cdev->lock); skb_queue_head_init(&cdev->recvqueue); init_waitqueue_head(&cdev->recvwait); + INIT_LIST_HEAD(&cdev->nccis); file->private_data = cdev; mutex_lock(&capidev_list_lock); @@ -1427,19 +1420,14 @@ static const struct file_operations capi20_proc_fops = { */ static int capi20ncci_proc_show(struct seq_file *m, void *v) { - struct capidev *cdev; - struct capincci *np; - struct list_head *l; + struct capidev *cdev; + struct capincci *np; mutex_lock(&capidev_list_lock); - list_for_each(l, &capidev_list) { - cdev = list_entry(l, struct capidev, list); + list_for_each_entry(cdev, &capidev_list, list) { mutex_lock(&cdev->lock); - for (np=cdev->nccis; np; np = np->next) { - seq_printf(m, "%d 0x%x\n", - cdev->ap.applid, - np->ncci); - } + list_for_each_entry(np, &cdev->nccis, list) + seq_printf(m, "%d 0x%x\n", cdev->ap.applid, np->ncci); mutex_unlock(&cdev->lock); } mutex_unlock(&capidev_list_lock); -- cgit v1.2.3 From 81d17fe5e29d863027824928e1c336baa9abfee9 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:23 +0000 Subject: CAPI: Switch capiminor list to array Using a plain array of pointers simplifies the management of capiminors. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 75 ++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 6704b2b004aa..46f85ae85f5f 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -85,7 +85,6 @@ struct datahandle_queue { }; struct capiminor { - struct list_head list; struct capincci *nccip; unsigned int minor; struct dentry *capifs_dentry; @@ -151,8 +150,8 @@ static LIST_HEAD(capidev_list); #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE -static DEFINE_RWLOCK(capiminor_list_lock); -static LIST_HEAD(capiminor_list); +static DEFINE_RWLOCK(capiminors_lock); +static struct capiminor **capiminors; /* -------- datahandles --------------------------------------------- */ @@ -213,8 +212,8 @@ static void capiminor_del_all_ack(struct capiminor *mp) static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) { - struct capiminor *mp, *p; - unsigned int minor = 0; + struct capiminor *mp; + unsigned int minor; unsigned long flags; mp = kzalloc(sizeof(*mp), GFP_KERNEL); @@ -233,31 +232,23 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) skb_queue_head_init(&mp->inqueue); skb_queue_head_init(&mp->outqueue); - /* Allocate the least unused minor number. - */ - write_lock_irqsave(&capiminor_list_lock, flags); - if (list_empty(&capiminor_list)) - list_add(&mp->list, &capiminor_list); - else { - list_for_each_entry(p, &capiminor_list, list) { - if (p->minor > minor) - break; - minor++; - } - - if (minor < capi_ttyminors) { - mp->minor = minor; - list_add(&mp->list, p->list.prev); + /* Allocate the least unused minor number. */ + write_lock_irqsave(&capiminors_lock, flags); + for (minor = 0; minor < capi_ttyminors; minor++) + if (!capiminors[minor]) { + capiminors[minor] = mp; + break; } - } - write_unlock_irqrestore(&capiminor_list_lock, flags); + write_unlock_irqrestore(&capiminors_lock, flags); - if (!(minor < capi_ttyminors)) { + if (minor == capi_ttyminors) { printk(KERN_NOTICE "capi: out of minors\n"); - kfree(mp); + kfree(mp); return NULL; } + mp->minor = minor; + return mp; } @@ -265,9 +256,9 @@ static void capiminor_free(struct capiminor *mp) { unsigned long flags; - write_lock_irqsave(&capiminor_list_lock, flags); - list_del(&mp->list); - write_unlock_irqrestore(&capiminor_list_lock, flags); + write_lock_irqsave(&capiminors_lock, flags); + capiminors[mp->minor] = NULL; + write_unlock_irqrestore(&capiminors_lock, flags); kfree_skb(mp->ttyskb); mp->ttyskb = NULL; @@ -279,20 +270,16 @@ static void capiminor_free(struct capiminor *mp) static struct capiminor *capiminor_find(unsigned int minor) { - struct list_head *l; - struct capiminor *p = NULL; + struct capiminor *mp; - read_lock(&capiminor_list_lock); - list_for_each(l, &capiminor_list) { - p = list_entry(l, struct capiminor, list); - if (p->minor == minor) - break; - } - read_unlock(&capiminor_list_lock); - if (l == &capiminor_list) + if (minor >= capi_ttyminors) return NULL; - return p; + read_lock(&capiminors_lock); + mp = capiminors[minor]; + read_unlock(&capiminors_lock); + + return mp; } /* -------- struct capincci ----------------------------------------- */ @@ -1329,10 +1316,16 @@ static int capinc_tty_init(void) if (capi_ttyminors <= 0) capi_ttyminors = CAPINC_NR_PORTS; - drv = alloc_tty_driver(capi_ttyminors); - if (!drv) + capiminors = kzalloc(sizeof(struct capi_minor *) * capi_ttyminors, + GFP_KERNEL); + if (!capiminors) return -ENOMEM; + drv = alloc_tty_driver(capi_ttyminors); + if (!drv) { + kfree(capiminors); + return -ENOMEM; + } drv->owner = THIS_MODULE; drv->driver_name = "capi_nc"; drv->name = "capi"; @@ -1349,6 +1342,7 @@ static int capinc_tty_init(void) tty_set_operations(drv, &capinc_ops); if (tty_register_driver(drv)) { put_tty_driver(drv); + kfree(capiminors); printk(KERN_ERR "Couldn't register capi_nc driver\n"); return -1; } @@ -1363,6 +1357,7 @@ static void capinc_tty_exit(void) if ((retval = tty_unregister_driver(drv))) printk(KERN_ERR "capi: failed to unregister capi_nc driver (%d)\n", retval); put_tty_driver(drv); + kfree(capiminors); } #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ -- cgit v1.2.3 From e76b1544074b5fc7983a21fb1f51a7faf03d3179 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:24 +0000 Subject: CAPI: Clean up capinc_tty_init/exit Return proper error code if tty_register_driver fails. In contrast, tty_unregister_driver cannot practically fail, so drop that error handling. Finally, mark capinc_tty_init/exit with __init/__exit. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 46f85ae85f5f..c22b34976c24 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -1307,10 +1307,11 @@ static const struct tty_operations capinc_ops = { .send_xchar = capinc_tty_send_xchar, }; -static int capinc_tty_init(void) +static int __init capinc_tty_init(void) { struct tty_driver *drv; - + int err; + if (capi_ttyminors > CAPINC_MAX_PORTS) capi_ttyminors = CAPINC_MAX_PORTS; if (capi_ttyminors <= 0) @@ -1340,23 +1341,22 @@ static int capinc_tty_init(void) drv->init_termios.c_lflag = 0; drv->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_RESET_TERMIOS; tty_set_operations(drv, &capinc_ops); - if (tty_register_driver(drv)) { + + err = tty_register_driver(drv); + if (err) { put_tty_driver(drv); kfree(capiminors); printk(KERN_ERR "Couldn't register capi_nc driver\n"); - return -1; + return err; } capinc_tty_driver = drv; return 0; } -static void capinc_tty_exit(void) +static void __exit capinc_tty_exit(void) { - struct tty_driver *drv = capinc_tty_driver; - int retval; - if ((retval = tty_unregister_driver(drv))) - printk(KERN_ERR "capi: failed to unregister capi_nc driver (%d)\n", retval); - put_tty_driver(drv); + tty_unregister_driver(capinc_tty_driver); + put_tty_driver(capinc_tty_driver); kfree(capiminors); } -- cgit v1.2.3 From 40fb2d0da77df5d39f1ba8878502725ebb806554 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:25 +0000 Subject: CAPI: Dynamically register minor devices Register capiminors dynamically with the TTY core so that udev can make them show up as the NCCIs appear or disappear. This removes the need to check if the capiminor requested in capinc_tty_open actually exists. And this completely obsoletes capifs which will be scheduled for removal in a later patch. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index c22b34976c24..901b79bc3b56 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -153,6 +153,8 @@ static LIST_HEAD(capidev_list); static DEFINE_RWLOCK(capiminors_lock); static struct capiminor **capiminors; +static struct tty_driver *capinc_tty_driver; + /* -------- datahandles --------------------------------------------- */ static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) @@ -213,6 +215,7 @@ static void capiminor_del_all_ack(struct capiminor *mp) static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) { struct capiminor *mp; + struct device *dev; unsigned int minor; unsigned long flags; @@ -243,19 +246,33 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) if (minor == capi_ttyminors) { printk(KERN_NOTICE "capi: out of minors\n"); - kfree(mp); - return NULL; + goto err_out1; } mp->minor = minor; + dev = tty_register_device(capinc_tty_driver, minor, NULL); + if (IS_ERR(dev)) + goto err_out2; + return mp; + +err_out2: + write_lock_irqsave(&capiminors_lock, flags); + capiminors[minor] = NULL; + write_unlock_irqrestore(&capiminors_lock, flags); + +err_out1: + kfree(mp); + return NULL; } static void capiminor_free(struct capiminor *mp) { unsigned long flags; + tty_unregister_device(capinc_tty_driver, mp->minor); + write_lock_irqsave(&capiminors_lock, flags); capiminors[mp->minor] = NULL; write_unlock_irqrestore(&capiminors_lock, flags); @@ -268,13 +285,10 @@ static void capiminor_free(struct capiminor *mp) kfree(mp); } -static struct capiminor *capiminor_find(unsigned int minor) +static struct capiminor *capiminor_get(unsigned int minor) { struct capiminor *mp; - if (minor >= capi_ttyminors) - return NULL; - read_lock(&capiminors_lock); mp = capiminors[minor]; read_unlock(&capiminors_lock); @@ -981,8 +995,7 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file) struct capiminor *mp; unsigned long flags; - if ((mp = capiminor_find(iminor(file->f_path.dentry->d_inode))) == NULL) - return -ENXIO; + mp = capiminor_get(iminor(file->f_path.dentry->d_inode)); if (mp->nccip == NULL) return -ENXIO; @@ -1284,8 +1297,6 @@ static void capinc_tty_send_xchar(struct tty_struct *tty, char ch) #endif } -static struct tty_driver *capinc_tty_driver; - static const struct tty_operations capinc_ops = { .open = capinc_tty_open, .close = capinc_tty_close, @@ -1339,7 +1350,9 @@ static int __init capinc_tty_init(void) drv->init_termios.c_oflag = OPOST | ONLCR; drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; drv->init_termios.c_lflag = 0; - drv->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_RESET_TERMIOS; + drv->flags = + TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS | + TTY_DRIVER_DYNAMIC_DEV; tty_set_operations(drv, &capinc_ops); err = tty_register_driver(drv); -- cgit v1.2.3 From e95ac143868752ad30d93068a6fc0b39cf3a1bf4 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:26 +0000 Subject: CAPI: Use dynamic major for NCCI TTYs by default No need to allocate a fixed major for this TTY, both capifs and udev make this transparent to the user. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 901b79bc3b56..b1de0cbea69e 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -60,10 +60,8 @@ module_param_named(major, capi_major, uint, 0); #define CAPINC_NR_PORTS 32 #define CAPINC_MAX_PORTS 256 -static int capi_ttymajor = 191; static int capi_ttyminors = CAPINC_NR_PORTS; -module_param_named(ttymajor, capi_ttymajor, uint, 0); module_param_named(ttyminors, capi_ttyminors, uint, 0); #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ @@ -301,6 +299,7 @@ static struct capiminor *capiminor_get(unsigned int minor) static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) { struct capiminor *mp; + dev_t device; if (!(cdev->userflags & CAPIFLAG_HIGHJACKING)) return; @@ -311,9 +310,8 @@ static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "set mp->nccip\n"); #endif - mp->capifs_dentry = - capifs_new_ncci(mp->minor, - MKDEV(capi_ttymajor, mp->minor)); + device = MKDEV(capinc_tty_driver->major, mp->minor); + mp->capifs_dentry = capifs_new_ncci(mp->minor, device); } } @@ -1341,7 +1339,7 @@ static int __init capinc_tty_init(void) drv->owner = THIS_MODULE; drv->driver_name = "capi_nc"; drv->name = "capi"; - drv->major = capi_ttymajor; + drv->major = 0; drv->minor_start = 0; drv->type = TTY_DRIVER_TYPE_SERIAL; drv->subtype = SERIAL_TYPE_NORMAL; -- cgit v1.2.3 From 0159d5491fef4acadd116a989b671e1cd350382f Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:27 +0000 Subject: CAPI: Use kref on capiminor Install a reference counter for capiminor objects. Acquire it when obtaining a capiminor from the array during capinc_tty_open, drop it when closing the tty again. Another reference is held for the hook-up with capincci. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index b1de0cbea69e..732cdb585b2d 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -83,6 +83,8 @@ struct datahandle_queue { }; struct capiminor { + struct kref kref; + struct capincci *nccip; unsigned int minor; struct dentry *capifs_dentry; @@ -223,6 +225,8 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) return NULL; } + kref_init(&mp->kref); + mp->ap = ap; mp->ncci = ncci; mp->msgid = 0; @@ -265,18 +269,11 @@ err_out1: return NULL; } -static void capiminor_free(struct capiminor *mp) +static void capiminor_destroy(struct kref *kref) { - unsigned long flags; - - tty_unregister_device(capinc_tty_driver, mp->minor); - - write_lock_irqsave(&capiminors_lock, flags); - capiminors[mp->minor] = NULL; - write_unlock_irqrestore(&capiminors_lock, flags); + struct capiminor *mp = container_of(kref, struct capiminor, kref); kfree_skb(mp->ttyskb); - mp->ttyskb = NULL; skb_queue_purge(&mp->inqueue); skb_queue_purge(&mp->outqueue); capiminor_del_all_ack(mp); @@ -289,11 +286,31 @@ static struct capiminor *capiminor_get(unsigned int minor) read_lock(&capiminors_lock); mp = capiminors[minor]; + if (mp) + kref_get(&mp->kref); read_unlock(&capiminors_lock); return mp; } +static inline void capiminor_put(struct capiminor *mp) +{ + kref_put(&mp->kref, capiminor_destroy); +} + +static void capiminor_free(struct capiminor *mp) +{ + unsigned long flags; + + tty_unregister_device(capinc_tty_driver, mp->minor); + + write_lock_irqsave(&capiminors_lock, flags); + capiminors[mp->minor] = NULL; + write_unlock_irqrestore(&capiminors_lock, flags); + + capiminor_put(mp); +} + /* -------- struct capincci ----------------------------------------- */ static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) @@ -1029,6 +1046,8 @@ static void capinc_tty_close(struct tty_struct * tty, struct file * file) #endif if (mp->nccip == NULL) capiminor_free(mp); + + capiminor_put(mp); } #ifdef _DEBUG_REFCOUNT -- cgit v1.2.3 From 46324511809251adbedb874cc08692e247f7ed68 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:28 +0000 Subject: CAPI: Establish install/cleanup handlers for capiminor TTYs Properly associate/disassociate a capiminor object with its TTY via the install/cleanup handlers instead of trying to guess first open and last close. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 732cdb585b2d..3e4997ac67ae 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -1005,16 +1005,34 @@ static const struct file_operations capi_fops = #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE /* -------- tty_operations for capincci ----------------------------- */ -static int capinc_tty_open(struct tty_struct * tty, struct file * file) +static int +capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty) { - struct capiminor *mp; - unsigned long flags; + int idx = tty->index; + struct capiminor *mp = capiminor_get(idx); + int ret = tty_init_termios(tty); + + if (ret == 0) { + tty_driver_kref_get(driver); + tty->count++; + tty->driver_data = mp; + driver->ttys[idx] = tty; + } else + capiminor_put(mp); + return ret; +} - mp = capiminor_get(iminor(file->f_path.dentry->d_inode)); - if (mp->nccip == NULL) - return -ENXIO; +static void capinc_tty_cleanup(struct tty_struct *tty) +{ + struct capiminor *mp = tty->driver_data; + tty->driver_data = NULL; + capiminor_put(mp); +} - tty->driver_data = (void *)mp; +static int capinc_tty_open(struct tty_struct * tty, struct file * file) +{ + struct capiminor *mp = tty->driver_data; + unsigned long flags; spin_lock_irqsave(&workaround_lock, flags); if (atomic_read(&mp->ttyopencount) == 0) @@ -1030,15 +1048,12 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file) static void capinc_tty_close(struct tty_struct * tty, struct file * file) { - struct capiminor *mp; + struct capiminor *mp = tty->driver_data; - mp = (struct capiminor *)tty->driver_data; - if (mp) { if (atomic_dec_and_test(&mp->ttyopencount)) { #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "capinc_tty_close lastclose\n"); #endif - tty->driver_data = NULL; mp->tty = NULL; } #ifdef _DEBUG_REFCOUNT @@ -1047,9 +1062,6 @@ static void capinc_tty_close(struct tty_struct * tty, struct file * file) if (mp->nccip == NULL) capiminor_free(mp); - capiminor_put(mp); - } - #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "capinc_tty_close\n"); #endif @@ -1333,6 +1345,8 @@ static const struct tty_operations capinc_ops = { .flush_buffer = capinc_tty_flush_buffer, .set_ldisc = capinc_tty_set_ldisc, .send_xchar = capinc_tty_send_xchar, + .install = capinc_tty_install, + .cleanup = capinc_tty_cleanup, }; static int __init capinc_tty_init(void) -- cgit v1.2.3 From fb4b4881ef951f6ed8fb8564ca1821dea10778c4 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:29 +0000 Subject: CAPI: Use tty_port to keep track of capiminor's tty Use the reference management features of tty_port to look up and drop again the tty_struct associated with a capiminor. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 94 +++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 32 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 3e4997ac67ae..e164a8fb9693 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -94,7 +94,7 @@ struct capiminor { u16 datahandle; u16 msgid; - struct tty_struct *tty; + struct tty_port port; int ttyinstop; int ttyoutstop; struct sk_buff *ttyskb; @@ -212,6 +212,8 @@ static void capiminor_del_all_ack(struct capiminor *mp) /* -------- struct capiminor ---------------------------------------- */ +static const struct tty_port_operations capiminor_port_ops; /* we have none */ + static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) { struct capiminor *mp; @@ -237,6 +239,9 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) skb_queue_head_init(&mp->inqueue); skb_queue_head_init(&mp->outqueue); + tty_port_init(&mp->port); + mp->port.ops = &capiminor_port_ops; + /* Allocate the least unused minor number. */ write_lock_irqsave(&capiminors_lock, flags); for (minor = 0; minor < capi_ttyminors; minor++) @@ -335,18 +340,22 @@ static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) static void capincci_free_minor(struct capincci *np) { struct capiminor *mp = np->minorp; + struct tty_struct *tty; if (mp) { capifs_free_ncci(mp->capifs_dentry); - if (mp->tty) { + + tty = tty_port_tty_get(&mp->port); + if (tty) { mp->nccip = NULL; #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "reset mp->nccip\n"); #endif - tty_hangup(mp->tty); - } else { - capiminor_free(mp); + tty_hangup(tty); + tty_kref_put(tty); } + + capiminor_free(mp); } } @@ -433,44 +442,48 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb) static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb) { + struct tty_struct *tty; struct sk_buff *nskb; int datalen; u16 errcode, datahandle; struct tty_ldisc *ld; - + int ret = -1; + datalen = skb->len - CAPIMSG_LEN(skb->data); - if (mp->tty == NULL) - { + + tty = tty_port_tty_get(&mp->port); + if (!tty) { #ifdef _DEBUG_DATAFLOW printk(KERN_DEBUG "capi: currently no receiver\n"); #endif return -1; } - ld = tty_ldisc_ref(mp->tty); - if (ld == NULL) - return -1; + ld = tty_ldisc_ref(tty); + if (!ld) + goto out1; + if (ld->ops->receive_buf == NULL) { #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) printk(KERN_DEBUG "capi: ldisc has no receive_buf function\n"); #endif - goto bad; + goto out2; } if (mp->ttyinstop) { #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) printk(KERN_DEBUG "capi: recv tty throttled\n"); #endif - goto bad; + goto out2; } - if (mp->tty->receive_room < datalen) { + if (tty->receive_room < datalen) { #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) printk(KERN_DEBUG "capi: no room in tty\n"); #endif - goto bad; + goto out2; } if ((nskb = gen_data_b3_resp_for(mp, skb)) == NULL) { printk(KERN_ERR "capi: gen_data_b3_resp failed\n"); - goto bad; + goto out2; } datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4); errcode = capi20_put_message(mp->ap, nskb); @@ -478,20 +491,21 @@ static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb) printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n", errcode); kfree_skb(nskb); - goto bad; + goto out2; } (void)skb_pull(skb, CAPIMSG_LEN(skb->data)); #ifdef _DEBUG_DATAFLOW printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => ldisc\n", datahandle, skb->len); #endif - ld->ops->receive_buf(mp->tty, skb->data, NULL, skb->len); + ld->ops->receive_buf(tty, skb->data, NULL, skb->len); kfree_skb(skb); + ret = 0; +out2: tty_ldisc_deref(ld); - return 0; -bad: - tty_ldisc_deref(ld); - return -1; +out1: + tty_kref_put(tty); + return ret; } static void handle_minor_recv(struct capiminor *mp) @@ -510,16 +524,22 @@ static void handle_minor_recv(struct capiminor *mp) static int handle_minor_send(struct capiminor *mp) { + struct tty_struct *tty; struct sk_buff *skb; u16 len; int count = 0; u16 errcode; u16 datahandle; - if (mp->tty && mp->ttyoutstop) { + tty = tty_port_tty_get(&mp->port); + if (!tty) + return 0; + + if (mp->ttyoutstop) { #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) printk(KERN_DEBUG "capi: send: tty stopped\n"); #endif + tty_kref_put(tty); return 0; } @@ -542,6 +562,7 @@ static int handle_minor_send(struct capiminor *mp) if (capiminor_add_ack(mp, datahandle) < 0) { skb_pull(skb, CAPI_DATA_B3_REQ_LEN); skb_queue_head(&mp->outqueue, skb); + tty_kref_put(tty); return count; } errcode = capi20_put_message(mp->ap, skb); @@ -568,6 +589,7 @@ static int handle_minor_send(struct capiminor *mp) mp->outbytes -= len; kfree_skb(skb); } + tty_kref_put(tty); return count; } @@ -578,6 +600,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) { struct capidev *cdev = ap->private; #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE + struct tty_struct *tty; struct capiminor *mp; u16 datahandle; #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ @@ -641,8 +664,11 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) #endif kfree_skb(skb); (void)capiminor_del_ack(mp, datahandle); - if (mp->tty) - tty_wakeup(mp->tty); + tty = tty_port_tty_get(&mp->port); + if (tty) { + tty_wakeup(tty); + tty_kref_put(tty); + } (void)handle_minor_send(mp); } else { @@ -1029,14 +1055,17 @@ static void capinc_tty_cleanup(struct tty_struct *tty) capiminor_put(mp); } -static int capinc_tty_open(struct tty_struct * tty, struct file * file) +static int capinc_tty_open(struct tty_struct *tty, struct file *filp) { struct capiminor *mp = tty->driver_data; unsigned long flags; + int err; + + err = tty_port_open(&mp->port, tty, filp); + if (err) + return err; spin_lock_irqsave(&workaround_lock, flags); - if (atomic_read(&mp->ttyopencount) == 0) - mp->tty = tty; atomic_inc(&mp->ttyopencount); #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "capinc_tty_open ocount=%d\n", atomic_read(&mp->ttyopencount)); @@ -1046,7 +1075,7 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file) return 0; } -static void capinc_tty_close(struct tty_struct * tty, struct file * file) +static void capinc_tty_close(struct tty_struct *tty, struct file *filp) { struct capiminor *mp = tty->driver_data; @@ -1054,17 +1083,15 @@ static void capinc_tty_close(struct tty_struct * tty, struct file * file) #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "capinc_tty_close lastclose\n"); #endif - mp->tty = NULL; } #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "capinc_tty_close ocount=%d\n", atomic_read(&mp->ttyopencount)); #endif - if (mp->nccip == NULL) - capiminor_free(mp); #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "capinc_tty_close\n"); #endif + tty_port_close(&mp->port, tty, filp); } static int capinc_tty_write(struct tty_struct * tty, @@ -1292,9 +1319,12 @@ static void capinc_tty_start(struct tty_struct *tty) static void capinc_tty_hangup(struct tty_struct *tty) { + struct capiminor *mp = tty->driver_data; + #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_hangup\n"); #endif + tty_port_hangup(&mp->port); } static int capinc_tty_break_ctl(struct tty_struct *tty, int state) -- cgit v1.2.3 From 2c8df72259d550ed6dc0b391feb5c2fc13892fb6 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:30 +0000 Subject: CAPI: Drop remaining NULL checks on tty->driver_data tty_struct's driver_data cannot be NULL, no need to test for it. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 64 +++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index e164a8fb9693..acc811bfe8e0 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -1097,7 +1097,7 @@ static void capinc_tty_close(struct tty_struct *tty, struct file *filp) static int capinc_tty_write(struct tty_struct * tty, const unsigned char *buf, int count) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; + struct capiminor *mp = tty->driver_data; struct sk_buff *skb; unsigned long flags; @@ -1105,7 +1105,7 @@ static int capinc_tty_write(struct tty_struct * tty, printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count); #endif - if (!mp || !mp->nccip) { + if (!mp->nccip) { #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_write: mp or mp->ncci NULL\n"); #endif @@ -1140,7 +1140,7 @@ static int capinc_tty_write(struct tty_struct * tty, static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; + struct capiminor *mp = tty->driver_data; struct sk_buff *skb; unsigned long flags; int ret = 1; @@ -1149,7 +1149,7 @@ static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch) printk(KERN_DEBUG "capinc_put_char(%u)\n", ch); #endif - if (!mp || !mp->nccip) { + if (!mp->nccip) { #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_put_char: mp or mp->ncci NULL\n"); #endif @@ -1184,7 +1184,7 @@ static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch) static void capinc_tty_flush_chars(struct tty_struct *tty) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; + struct capiminor *mp = tty->driver_data; struct sk_buff *skb; unsigned long flags; @@ -1192,7 +1192,7 @@ static void capinc_tty_flush_chars(struct tty_struct *tty) printk(KERN_DEBUG "capinc_tty_flush_chars\n"); #endif - if (!mp || !mp->nccip) { + if (!mp->nccip) { #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_flush_chars: mp or mp->ncci NULL\n"); #endif @@ -1213,9 +1213,10 @@ static void capinc_tty_flush_chars(struct tty_struct *tty) static int capinc_tty_write_room(struct tty_struct *tty) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; + struct capiminor *mp = tty->driver_data; int room; - if (!mp || !mp->nccip) { + + if (!mp->nccip) { #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_write_room: mp or mp->ncci NULL\n"); #endif @@ -1231,8 +1232,9 @@ static int capinc_tty_write_room(struct tty_struct *tty) static int capinc_tty_chars_in_buffer(struct tty_struct *tty) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; - if (!mp || !mp->nccip) { + struct capiminor *mp = tty->driver_data; + + if (!mp->nccip) { #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_chars_in_buffer: mp or mp->ncci NULL\n"); #endif @@ -1266,55 +1268,51 @@ static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios * old #endif } -static void capinc_tty_throttle(struct tty_struct * tty) +static void capinc_tty_throttle(struct tty_struct *tty) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; + struct capiminor *mp = tty->driver_data; #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_throttle\n"); #endif - if (mp) - mp->ttyinstop = 1; + mp->ttyinstop = 1; } -static void capinc_tty_unthrottle(struct tty_struct * tty) +static void capinc_tty_unthrottle(struct tty_struct *tty) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; + struct capiminor *mp = tty->driver_data; unsigned long flags; + #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_unthrottle\n"); #endif - if (mp) { - spin_lock_irqsave(&workaround_lock, flags); - mp->ttyinstop = 0; - handle_minor_recv(mp); - spin_unlock_irqrestore(&workaround_lock, flags); - } + spin_lock_irqsave(&workaround_lock, flags); + mp->ttyinstop = 0; + handle_minor_recv(mp); + spin_unlock_irqrestore(&workaround_lock, flags); } static void capinc_tty_stop(struct tty_struct *tty) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; + struct capiminor *mp = tty->driver_data; + #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_stop\n"); #endif - if (mp) { - mp->ttyoutstop = 1; - } + mp->ttyoutstop = 1; } static void capinc_tty_start(struct tty_struct *tty) { - struct capiminor *mp = (struct capiminor *)tty->driver_data; + struct capiminor *mp = tty->driver_data; unsigned long flags; + #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_start\n"); #endif - if (mp) { - spin_lock_irqsave(&workaround_lock, flags); - mp->ttyoutstop = 0; - (void)handle_minor_send(mp); - spin_unlock_irqrestore(&workaround_lock, flags); - } + spin_lock_irqsave(&workaround_lock, flags); + mp->ttyoutstop = 0; + (void)handle_minor_send(mp); + spin_unlock_irqrestore(&workaround_lock, flags); } static void capinc_tty_hangup(struct tty_struct *tty) -- cgit v1.2.3 From 30bced91d93f7523bf23432d71d882d6b5d6cff6 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:31 +0000 Subject: CAPI: Issue synchronous hangup on capincci_free_minor capincci_free and, thus, capincci_free_minor runs in process context, so we can issue the hangup of the associated TTY synchronously. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index acc811bfe8e0..b382edeeee18 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -351,7 +351,7 @@ static void capincci_free_minor(struct capincci *np) #ifdef _DEBUG_REFCOUNT printk(KERN_DEBUG "reset mp->nccip\n"); #endif - tty_hangup(tty); + tty_vhangup(tty); tty_kref_put(tty); } -- cgit v1.2.3 From 6576c2891adacad81ea0b24f0704ecac9fc727cb Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:32 +0000 Subject: CAPI: Drop obsolete nccip from capiminor struct The nccip in capiminor used to serve as an indicator that the NCCI was close. But we don't need this, we issue a hangup on capincci_free_minor. So drop this legacy. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index b382edeeee18..cf5e996ac448 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -85,7 +85,6 @@ struct datahandle_queue { struct capiminor { struct kref kref; - struct capincci *nccip; unsigned int minor; struct dentry *capifs_dentry; @@ -328,10 +327,6 @@ static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) mp = np->minorp = capiminor_alloc(&cdev->ap, np->ncci); if (mp) { - mp->nccip = np; -#ifdef _DEBUG_REFCOUNT - printk(KERN_DEBUG "set mp->nccip\n"); -#endif device = MKDEV(capinc_tty_driver->major, mp->minor); mp->capifs_dentry = capifs_new_ncci(mp->minor, device); } @@ -347,10 +342,6 @@ static void capincci_free_minor(struct capincci *np) tty = tty_port_tty_get(&mp->port); if (tty) { - mp->nccip = NULL; -#ifdef _DEBUG_REFCOUNT - printk(KERN_DEBUG "reset mp->nccip\n"); -#endif tty_vhangup(tty); tty_kref_put(tty); } @@ -1094,7 +1085,7 @@ static void capinc_tty_close(struct tty_struct *tty, struct file *filp) tty_port_close(&mp->port, tty, filp); } -static int capinc_tty_write(struct tty_struct * tty, +static int capinc_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) { struct capiminor *mp = tty->driver_data; @@ -1105,13 +1096,6 @@ static int capinc_tty_write(struct tty_struct * tty, printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count); #endif - if (!mp->nccip) { -#ifdef _DEBUG_TTYFUNCS - printk(KERN_DEBUG "capinc_tty_write: mp or mp->ncci NULL\n"); -#endif - return 0; - } - spin_lock_irqsave(&workaround_lock, flags); skb = mp->ttyskb; if (skb) { @@ -1149,13 +1133,6 @@ static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch) printk(KERN_DEBUG "capinc_put_char(%u)\n", ch); #endif - if (!mp->nccip) { -#ifdef _DEBUG_TTYFUNCS - printk(KERN_DEBUG "capinc_tty_put_char: mp or mp->ncci NULL\n"); -#endif - return 0; - } - spin_lock_irqsave(&workaround_lock, flags); skb = mp->ttyskb; if (skb) { @@ -1192,13 +1169,6 @@ static void capinc_tty_flush_chars(struct tty_struct *tty) printk(KERN_DEBUG "capinc_tty_flush_chars\n"); #endif - if (!mp->nccip) { -#ifdef _DEBUG_TTYFUNCS - printk(KERN_DEBUG "capinc_tty_flush_chars: mp or mp->ncci NULL\n"); -#endif - return; - } - spin_lock_irqsave(&workaround_lock, flags); skb = mp->ttyskb; if (skb) { @@ -1216,12 +1186,6 @@ static int capinc_tty_write_room(struct tty_struct *tty) struct capiminor *mp = tty->driver_data; int room; - if (!mp->nccip) { -#ifdef _DEBUG_TTYFUNCS - printk(KERN_DEBUG "capinc_tty_write_room: mp or mp->ncci NULL\n"); -#endif - return 0; - } room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue); room *= CAPI_MAX_BLKSIZE; #ifdef _DEBUG_TTYFUNCS @@ -1234,12 +1198,6 @@ static int capinc_tty_chars_in_buffer(struct tty_struct *tty) { struct capiminor *mp = tty->driver_data; - if (!mp->nccip) { -#ifdef _DEBUG_TTYFUNCS - printk(KERN_DEBUG "capinc_tty_chars_in_buffer: mp or mp->ncci NULL\n"); -#endif - return 0; - } #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_chars_in_buffer = %d nack=%d sq=%d rq=%d\n", mp->outbytes, mp->nack, -- cgit v1.2.3 From 3d5d30fe7a6aa4c9d63dc4fe6b6da6abac423bc2 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:33 +0000 Subject: CAPI: Clean up capiminors_lock Use a plain spin lock for capiminors_lock, drop inconsistent irqsafe acquisitions (it's only used in process context anyway). Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index cf5e996ac448..0b264b4565c8 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -149,7 +149,7 @@ static LIST_HEAD(capidev_list); #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE -static DEFINE_RWLOCK(capiminors_lock); +static DEFINE_SPINLOCK(capiminors_lock); static struct capiminor **capiminors; static struct tty_driver *capinc_tty_driver; @@ -218,7 +218,6 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) struct capiminor *mp; struct device *dev; unsigned int minor; - unsigned long flags; mp = kzalloc(sizeof(*mp), GFP_KERNEL); if (!mp) { @@ -242,13 +241,13 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) mp->port.ops = &capiminor_port_ops; /* Allocate the least unused minor number. */ - write_lock_irqsave(&capiminors_lock, flags); + spin_lock(&capiminors_lock); for (minor = 0; minor < capi_ttyminors; minor++) if (!capiminors[minor]) { capiminors[minor] = mp; break; } - write_unlock_irqrestore(&capiminors_lock, flags); + spin_unlock(&capiminors_lock); if (minor == capi_ttyminors) { printk(KERN_NOTICE "capi: out of minors\n"); @@ -264,9 +263,9 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) return mp; err_out2: - write_lock_irqsave(&capiminors_lock, flags); + spin_lock(&capiminors_lock); capiminors[minor] = NULL; - write_unlock_irqrestore(&capiminors_lock, flags); + spin_unlock(&capiminors_lock); err_out1: kfree(mp); @@ -288,11 +287,11 @@ static struct capiminor *capiminor_get(unsigned int minor) { struct capiminor *mp; - read_lock(&capiminors_lock); + spin_lock(&capiminors_lock); mp = capiminors[minor]; if (mp) kref_get(&mp->kref); - read_unlock(&capiminors_lock); + spin_unlock(&capiminors_lock); return mp; } @@ -304,13 +303,11 @@ static inline void capiminor_put(struct capiminor *mp) static void capiminor_free(struct capiminor *mp) { - unsigned long flags; - tty_unregister_device(capinc_tty_driver, mp->minor); - write_lock_irqsave(&capiminors_lock, flags); + spin_lock(&capiminors_lock); capiminors[mp->minor] = NULL; - write_unlock_irqrestore(&capiminors_lock, flags); + spin_unlock(&capiminors_lock); capiminor_put(mp); } -- cgit v1.2.3 From a84fdf41b25ad4c2b83e7c8ca87268fdbe6207d1 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:34 +0000 Subject: CAPI: Drop atomic ttyopencount Not needed, tty->count keeps track of this information. At this chance, drop traces of ancient attempts to debug this logic via _DEBUG_REFCOUNT. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 0b264b4565c8..867589a5916a 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -45,7 +45,6 @@ MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface"); MODULE_AUTHOR("Carsten Paeth"); MODULE_LICENSE("GPL"); -#undef _DEBUG_REFCOUNT /* alloc/free and open/close debug */ #undef _DEBUG_TTYFUNCS /* call to tty_driver */ #undef _DEBUG_DATAFLOW /* data flow */ @@ -97,7 +96,6 @@ struct capiminor { int ttyinstop; int ttyoutstop; struct sk_buff *ttyskb; - atomic_t ttyopencount; struct sk_buff_head inqueue; int inbytes; @@ -230,7 +228,6 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) mp->ap = ap; mp->ncci = ncci; mp->msgid = 0; - atomic_set(&mp->ttyopencount,0); INIT_LIST_HEAD(&mp->ackqueue); spin_lock_init(&mp->ackqlock); @@ -350,8 +347,17 @@ static void capincci_free_minor(struct capincci *np) static inline unsigned int capincci_minor_opencount(struct capincci *np) { struct capiminor *mp = np->minorp; + unsigned int count = 0; + struct tty_struct *tty; - return mp ? atomic_read(&mp->ttyopencount) : 0; + if (mp) { + tty = tty_port_tty_get(&mp->port); + if (tty) { + count = tty->count; + tty_kref_put(tty); + } + } + return count; } #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ @@ -1054,10 +1060,6 @@ static int capinc_tty_open(struct tty_struct *tty, struct file *filp) return err; spin_lock_irqsave(&workaround_lock, flags); - atomic_inc(&mp->ttyopencount); -#ifdef _DEBUG_REFCOUNT - printk(KERN_DEBUG "capinc_tty_open ocount=%d\n", atomic_read(&mp->ttyopencount)); -#endif handle_minor_recv(mp); spin_unlock_irqrestore(&workaround_lock, flags); return 0; @@ -1067,18 +1069,6 @@ static void capinc_tty_close(struct tty_struct *tty, struct file *filp) { struct capiminor *mp = tty->driver_data; - if (atomic_dec_and_test(&mp->ttyopencount)) { -#ifdef _DEBUG_REFCOUNT - printk(KERN_DEBUG "capinc_tty_close lastclose\n"); -#endif - } -#ifdef _DEBUG_REFCOUNT - printk(KERN_DEBUG "capinc_tty_close ocount=%d\n", atomic_read(&mp->ttyopencount)); -#endif - -#ifdef _DEBUG_REFCOUNT - printk(KERN_DEBUG "capinc_tty_close\n"); -#endif tty_port_close(&mp->port, tty, filp); } -- cgit v1.2.3 From b75b2eedcbf6458c68713c772c2ade83ab7a55f0 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:35 +0000 Subject: CAPI: Drop handle_minor_recv from capinc_tty_write Sending a message down the CAPI stack may trigger the reception of an answer, but this will go through capi_recv_message and call handle_minor_recv from there. There is no need to walk the receive queue on capinc_tty_write. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 867589a5916a..554fa1b36d13 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -1104,7 +1104,6 @@ static int capinc_tty_write(struct tty_struct *tty, skb_queue_tail(&mp->outqueue, skb); mp->outbytes += skb->len; (void)handle_minor_send(mp); - (void)handle_minor_recv(mp); spin_unlock_irqrestore(&workaround_lock, flags); return count; } -- cgit v1.2.3 From a11ef7be8e982426e9fbbfc84fa0c01d23ce05c3 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:36 +0000 Subject: CAPI: Rework capiminor RX handler Avoid re-queuing skbs unless the error detected in handle_recv_skb is expected to be recoverable such as lacking memory, a full CAPI queue, a full TTY input buffer, or a not yet existing TTY. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 60 ++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 554fa1b36d13..c5c54fab50eb 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -436,15 +436,13 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb) static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb) { + unsigned int datalen = skb->len - CAPIMSG_LEN(skb->data); struct tty_struct *tty; struct sk_buff *nskb; - int datalen; u16 errcode, datahandle; struct tty_ldisc *ld; int ret = -1; - datalen = skb->len - CAPIMSG_LEN(skb->data); - tty = tty_port_tty_get(&mp->port); if (!tty) { #ifdef _DEBUG_DATAFLOW @@ -454,50 +452,68 @@ static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb) } ld = tty_ldisc_ref(tty); - if (!ld) - goto out1; + if (!ld) { + /* fatal error, do not requeue */ + ret = 0; + kfree_skb(skb); + goto deref_tty; + } if (ld->ops->receive_buf == NULL) { #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) printk(KERN_DEBUG "capi: ldisc has no receive_buf function\n"); #endif - goto out2; + /* fatal error, do not requeue */ + goto free_skb; } if (mp->ttyinstop) { #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) printk(KERN_DEBUG "capi: recv tty throttled\n"); #endif - goto out2; + goto deref_ldisc; } + if (tty->receive_room < datalen) { #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) printk(KERN_DEBUG "capi: no room in tty\n"); #endif - goto out2; + goto deref_ldisc; } - if ((nskb = gen_data_b3_resp_for(mp, skb)) == NULL) { + + nskb = gen_data_b3_resp_for(mp, skb); + if (!nskb) { printk(KERN_ERR "capi: gen_data_b3_resp failed\n"); - goto out2; + goto deref_ldisc; } - datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4); + + datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN + 4); + errcode = capi20_put_message(mp->ap, nskb); - if (errcode != CAPI_NOERROR) { + + if (errcode == CAPI_NOERROR) { + skb_pull(skb, CAPIMSG_LEN(skb->data)); +#ifdef _DEBUG_DATAFLOW + printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => ldisc\n", + datahandle, skb->len); +#endif + ld->ops->receive_buf(tty, skb->data, NULL, skb->len); + } else { printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n", errcode); kfree_skb(nskb); - goto out2; + + if (errcode == CAPI_SENDQUEUEFULL) + goto deref_ldisc; } - (void)skb_pull(skb, CAPIMSG_LEN(skb->data)); -#ifdef _DEBUG_DATAFLOW - printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => ldisc\n", - datahandle, skb->len); -#endif - ld->ops->receive_buf(tty, skb->data, NULL, skb->len); - kfree_skb(skb); + +free_skb: ret = 0; -out2: + kfree_skb(skb); + +deref_ldisc: tty_ldisc_deref(ld); -out1: + +deref_tty: tty_kref_put(tty); return ret; } -- cgit v1.2.3 From 42651b5c1aabf5eb60fbe98375ba127f4f6eb943 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:37 +0000 Subject: CAPI: Rename datahandle_queue -> ackqueue_entry This struct is describing a queue entry, not the queue itself. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index c5c54fab50eb..9d4750a0aece 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -76,7 +76,7 @@ struct capidev; struct capincci; struct capiminor; -struct datahandle_queue { +struct ackqueue_entry { struct list_head list; u16 datahandle; }; @@ -156,7 +156,7 @@ static struct tty_driver *capinc_tty_driver; static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) { - struct datahandle_queue *n; + struct ackqueue_entry *n; unsigned long flags; n = kmalloc(sizeof(*n), GFP_ATOMIC); @@ -175,7 +175,7 @@ static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) static int capiminor_del_ack(struct capiminor *mp, u16 datahandle) { - struct datahandle_queue *p, *tmp; + struct ackqueue_entry *p, *tmp; unsigned long flags; spin_lock_irqsave(&mp->ackqlock, flags); @@ -194,7 +194,7 @@ static int capiminor_del_ack(struct capiminor *mp, u16 datahandle) static void capiminor_del_all_ack(struct capiminor *mp) { - struct datahandle_queue *p, *tmp; + struct ackqueue_entry *p, *tmp; unsigned long flags; spin_lock_irqsave(&mp->ackqlock, flags); -- cgit v1.2.3 From 42792713f7f2664cf07501e1244d6da33a73ffc1 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:38 +0000 Subject: CAPI: Use atomics for capiminor's datahandle and msgid The capiminor members datahandle and msgid are incremented outside any lock, so better do this atomically. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 9d4750a0aece..08d5a8aa2fec 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -87,10 +87,10 @@ struct capiminor { unsigned int minor; struct dentry *capifs_dentry; - struct capi20_appl *ap; - u32 ncci; - u16 datahandle; - u16 msgid; + struct capi20_appl *ap; + u32 ncci; + atomic_t datahandle; + atomic_t msgid; struct tty_port port; int ttyinstop; @@ -227,7 +227,6 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) mp->ap = ap; mp->ncci = ncci; - mp->msgid = 0; INIT_LIST_HEAD(&mp->ackqueue); spin_lock_init(&mp->ackqlock); @@ -427,7 +426,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb) capimsg_setu16(s, 2, mp->ap->applid); capimsg_setu8 (s, 4, CAPI_DATA_B3); capimsg_setu8 (s, 5, CAPI_RESP); - capimsg_setu16(s, 6, mp->msgid++); + capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid)); capimsg_setu32(s, 8, mp->ncci); capimsg_setu16(s, 12, datahandle); } @@ -554,7 +553,7 @@ static int handle_minor_send(struct capiminor *mp) } while ((skb = skb_dequeue(&mp->outqueue)) != NULL) { - datahandle = mp->datahandle; + datahandle = atomic_inc_return(&mp->datahandle); len = (u16)skb->len; skb_push(skb, CAPI_DATA_B3_REQ_LEN); memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN); @@ -562,7 +561,7 @@ static int handle_minor_send(struct capiminor *mp) capimsg_setu16(skb->data, 2, mp->ap->applid); capimsg_setu8 (skb->data, 4, CAPI_DATA_B3); capimsg_setu8 (skb->data, 5, CAPI_REQ); - capimsg_setu16(skb->data, 6, mp->msgid++); + capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid)); capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */ capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */ capimsg_setu16(skb->data, 16, len); /* Data length */ @@ -577,7 +576,6 @@ static int handle_minor_send(struct capiminor *mp) } errcode = capi20_put_message(mp->ap, skb); if (errcode == CAPI_NOERROR) { - mp->datahandle++; count++; mp->outbytes -= len; #ifdef _DEBUG_DATAFLOW -- cgit v1.2.3 From 68d7347b280b4c1f8253c0676a520fb754f213c7 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:39 +0000 Subject: CAPI: Drop capiminor's unused inbytes counter The inbytes counter was only updated but never read. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 08d5a8aa2fec..be85c8c1e8b4 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -98,7 +98,6 @@ struct capiminor { struct sk_buff *ttyskb; struct sk_buff_head inqueue; - int inbytes; struct sk_buff_head outqueue; int outbytes; @@ -520,15 +519,12 @@ deref_tty: static void handle_minor_recv(struct capiminor *mp) { struct sk_buff *skb; - while ((skb = skb_dequeue(&mp->inqueue)) != NULL) { - unsigned int len = skb->len; - mp->inbytes -= len; + + while ((skb = skb_dequeue(&mp->inqueue)) != NULL) if (handle_recv_skb(mp, skb) < 0) { skb_queue_head(&mp->inqueue, skb); - mp->inbytes += len; return; } - } } static int handle_minor_send(struct capiminor *mp) @@ -659,7 +655,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) datahandle, skb->len-CAPIMSG_LEN(skb->data)); #endif skb_queue_tail(&mp->inqueue, skb); - mp->inbytes += skb->len; + handle_minor_recv(mp); } else if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_CONF) { -- cgit v1.2.3 From dfbb84ffe94e75e2d56250fa948db40f6c62093f Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:40 +0000 Subject: CAPI: Fix locking around capiminor's output queue and drop workaround_lock Introduce outlock as a spin lock that protects capiminor's outqueue, outbytes and outskb (formerly known as ttyskb). outlock can be acquired from soft-IRQ context via capinc_write, so make it bh-safe. This finally removes the last reason for keeping the workaround lock around (which was incomplete and partly broken anyway). And as we no longer call handle_recv_skb in atomic context, gen_data_b3_resp_for can use non-atomic allocation now. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 126 +++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 59 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index be85c8c1e8b4..074496fae8da 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -95,11 +95,13 @@ struct capiminor { struct tty_port port; int ttyinstop; int ttyoutstop; - struct sk_buff *ttyskb; - struct sk_buff_head inqueue; - struct sk_buff_head outqueue; - int outbytes; + struct sk_buff_head inqueue; + + struct sk_buff_head outqueue; + int outbytes; + struct sk_buff *outskb; + spinlock_t outlock; /* transmit path */ struct list_head ackqueue; @@ -107,15 +109,6 @@ struct capiminor { spinlock_t ackqlock; }; -/* FIXME: The following lock is a sledgehammer-workaround to a - * locking issue with the capiminor (and maybe other) data structure(s). - * Access to this data is done in a racy way and crashes the machine with - * a FritzCard DSL driver; sooner or later. This is a workaround - * which trades scalability vs stability, so it doesn't crash the kernel anymore. - * The correct (and scalable) fix for the issue seems to require - * an API change to the drivers... . */ -static DEFINE_SPINLOCK(workaround_lock); - struct capincci { struct list_head list; u32 ncci; @@ -231,6 +224,7 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) skb_queue_head_init(&mp->inqueue); skb_queue_head_init(&mp->outqueue); + spin_lock_init(&mp->outlock); tty_port_init(&mp->port); mp->port.ops = &capiminor_port_ops; @@ -271,7 +265,7 @@ static void capiminor_destroy(struct kref *kref) { struct capiminor *mp = container_of(kref, struct capiminor, kref); - kfree_skb(mp->ttyskb); + kfree_skb(mp->outskb); skb_queue_purge(&mp->inqueue); skb_queue_purge(&mp->outqueue); capiminor_del_all_ack(mp); @@ -417,7 +411,7 @@ static struct sk_buff * gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb) { struct sk_buff *nskb; - nskb = alloc_skb(CAPI_DATA_B3_RESP_LEN, GFP_ATOMIC); + nskb = alloc_skb(CAPI_DATA_B3_RESP_LEN, GFP_KERNEL); if (nskb) { u16 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4+4+2); unsigned char *s = skb_put(nskb, CAPI_DATA_B3_RESP_LEN); @@ -548,9 +542,18 @@ static int handle_minor_send(struct capiminor *mp) return 0; } - while ((skb = skb_dequeue(&mp->outqueue)) != NULL) { - datahandle = atomic_inc_return(&mp->datahandle); + while (1) { + spin_lock_bh(&mp->outlock); + skb = __skb_dequeue(&mp->outqueue); + if (!skb) { + spin_unlock_bh(&mp->outlock); + break; + } len = (u16)skb->len; + mp->outbytes -= len; + spin_unlock_bh(&mp->outlock); + + datahandle = atomic_inc_return(&mp->datahandle); skb_push(skb, CAPI_DATA_B3_REQ_LEN); memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN); capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN); @@ -566,14 +569,18 @@ static int handle_minor_send(struct capiminor *mp) if (capiminor_add_ack(mp, datahandle) < 0) { skb_pull(skb, CAPI_DATA_B3_REQ_LEN); - skb_queue_head(&mp->outqueue, skb); + + spin_lock_bh(&mp->outlock); + __skb_queue_head(&mp->outqueue, skb); + mp->outbytes += len; + spin_unlock_bh(&mp->outlock); + tty_kref_put(tty); return count; } errcode = capi20_put_message(mp->ap, skb); if (errcode == CAPI_NOERROR) { count++; - mp->outbytes -= len; #ifdef _DEBUG_DATAFLOW printk(KERN_DEBUG "capi: DATA_B3_REQ %u len=%u\n", datahandle, len); @@ -584,13 +591,17 @@ static int handle_minor_send(struct capiminor *mp) if (errcode == CAPI_SENDQUEUEFULL) { skb_pull(skb, CAPI_DATA_B3_REQ_LEN); - skb_queue_head(&mp->outqueue, skb); + + spin_lock_bh(&mp->outlock); + __skb_queue_head(&mp->outqueue, skb); + mp->outbytes += len; + spin_unlock_bh(&mp->outlock); + break; } /* ups, drop packet */ printk(KERN_ERR "capi: put_message = %x\n", errcode); - mp->outbytes -= len; kfree_skb(skb); } tty_kref_put(tty); @@ -609,7 +620,6 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) u16 datahandle; #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ struct capincci *np; - unsigned long flags; mutex_lock(&cdev->lock); @@ -621,7 +631,6 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); - spin_lock_irqsave(&workaround_lock, flags); if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) { skb_queue_tail(&cdev->recvqueue, skb); wake_up_interruptible(&cdev->recvwait); @@ -683,7 +692,6 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ unlock_out: - spin_unlock_irqrestore(&workaround_lock, flags); mutex_unlock(&cdev->lock); } @@ -1062,16 +1070,13 @@ static void capinc_tty_cleanup(struct tty_struct *tty) static int capinc_tty_open(struct tty_struct *tty, struct file *filp) { struct capiminor *mp = tty->driver_data; - unsigned long flags; int err; err = tty_port_open(&mp->port, tty, filp); if (err) return err; - spin_lock_irqsave(&workaround_lock, flags); handle_minor_recv(mp); - spin_unlock_irqrestore(&workaround_lock, flags); return 0; } @@ -1087,71 +1092,78 @@ static int capinc_tty_write(struct tty_struct *tty, { struct capiminor *mp = tty->driver_data; struct sk_buff *skb; - unsigned long flags; #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count); #endif - spin_lock_irqsave(&workaround_lock, flags); - skb = mp->ttyskb; + spin_lock_bh(&mp->outlock); + skb = mp->outskb; if (skb) { - mp->ttyskb = NULL; - skb_queue_tail(&mp->outqueue, skb); + mp->outskb = NULL; + __skb_queue_tail(&mp->outqueue, skb); mp->outbytes += skb->len; } skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC); if (!skb) { printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n"); - spin_unlock_irqrestore(&workaround_lock, flags); + spin_unlock_bh(&mp->outlock); return -ENOMEM; } skb_reserve(skb, CAPI_DATA_B3_REQ_LEN); memcpy(skb_put(skb, count), buf, count); - skb_queue_tail(&mp->outqueue, skb); + __skb_queue_tail(&mp->outqueue, skb); mp->outbytes += skb->len; + spin_unlock_bh(&mp->outlock); + (void)handle_minor_send(mp); - spin_unlock_irqrestore(&workaround_lock, flags); + return count; } static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch) { struct capiminor *mp = tty->driver_data; + bool invoke_send = false; struct sk_buff *skb; - unsigned long flags; int ret = 1; #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_put_char(%u)\n", ch); #endif - spin_lock_irqsave(&workaround_lock, flags); - skb = mp->ttyskb; + spin_lock_bh(&mp->outlock); + skb = mp->outskb; if (skb) { if (skb_tailroom(skb) > 0) { *(skb_put(skb, 1)) = ch; - spin_unlock_irqrestore(&workaround_lock, flags); - return 1; + goto unlock_out; } - mp->ttyskb = NULL; - skb_queue_tail(&mp->outqueue, skb); + mp->outskb = NULL; + __skb_queue_tail(&mp->outqueue, skb); mp->outbytes += skb->len; - (void)handle_minor_send(mp); + invoke_send = true; } + skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+CAPI_MAX_BLKSIZE, GFP_ATOMIC); if (skb) { skb_reserve(skb, CAPI_DATA_B3_REQ_LEN); *(skb_put(skb, 1)) = ch; - mp->ttyskb = skb; + mp->outskb = skb; } else { printk(KERN_ERR "capinc_put_char: char %u lost\n", ch); ret = 0; } - spin_unlock_irqrestore(&workaround_lock, flags); + +unlock_out: + spin_unlock_bh(&mp->outlock); + + if (invoke_send) + (void)handle_minor_send(mp); + return ret; } @@ -1159,22 +1171,24 @@ static void capinc_tty_flush_chars(struct tty_struct *tty) { struct capiminor *mp = tty->driver_data; struct sk_buff *skb; - unsigned long flags; #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_flush_chars\n"); #endif - spin_lock_irqsave(&workaround_lock, flags); - skb = mp->ttyskb; + spin_lock_bh(&mp->outlock); + skb = mp->outskb; if (skb) { - mp->ttyskb = NULL; - skb_queue_tail(&mp->outqueue, skb); + mp->outskb = NULL; + __skb_queue_tail(&mp->outqueue, skb); mp->outbytes += skb->len; + spin_unlock_bh(&mp->outlock); + (void)handle_minor_send(mp); - } - (void)handle_minor_recv(mp); - spin_unlock_irqrestore(&workaround_lock, flags); + } else + spin_unlock_bh(&mp->outlock); + + handle_minor_recv(mp); } static int capinc_tty_write_room(struct tty_struct *tty) @@ -1234,15 +1248,12 @@ static void capinc_tty_throttle(struct tty_struct *tty) static void capinc_tty_unthrottle(struct tty_struct *tty) { struct capiminor *mp = tty->driver_data; - unsigned long flags; #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_unthrottle\n"); #endif - spin_lock_irqsave(&workaround_lock, flags); mp->ttyinstop = 0; handle_minor_recv(mp); - spin_unlock_irqrestore(&workaround_lock, flags); } static void capinc_tty_stop(struct tty_struct *tty) @@ -1258,15 +1269,12 @@ static void capinc_tty_stop(struct tty_struct *tty) static void capinc_tty_start(struct tty_struct *tty) { struct capiminor *mp = tty->driver_data; - unsigned long flags; #ifdef _DEBUG_TTYFUNCS printk(KERN_DEBUG "capinc_tty_start\n"); #endif - spin_lock_irqsave(&workaround_lock, flags); mp->ttyoutstop = 0; (void)handle_minor_send(mp); - spin_unlock_irqrestore(&workaround_lock, flags); } static void capinc_tty_hangup(struct tty_struct *tty) -- cgit v1.2.3 From 2b72b5bd65f00bce786ca080aca27e91e90af6df Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:41 +0000 Subject: CAPI: Clean up capiminor_*_ack No need for irqsave acquisition of acklock, bh-safe is sufficient. Moverover, move kfree out of the lock and do not take acklock at all in capiminor_del_all_ack as we are the last user of the list here. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 074496fae8da..40b81b460e81 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -149,7 +149,6 @@ static struct tty_driver *capinc_tty_driver; static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) { struct ackqueue_entry *n; - unsigned long flags; n = kmalloc(sizeof(*n), GFP_ATOMIC); if (unlikely(!n)) { @@ -158,44 +157,40 @@ static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) } n->datahandle = datahandle; INIT_LIST_HEAD(&n->list); - spin_lock_irqsave(&mp->ackqlock, flags); + spin_lock_bh(&mp->ackqlock); list_add_tail(&n->list, &mp->ackqueue); mp->nack++; - spin_unlock_irqrestore(&mp->ackqlock, flags); + spin_unlock_bh(&mp->ackqlock); return 0; } static int capiminor_del_ack(struct capiminor *mp, u16 datahandle) { struct ackqueue_entry *p, *tmp; - unsigned long flags; - spin_lock_irqsave(&mp->ackqlock, flags); + spin_lock_bh(&mp->ackqlock); list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) { if (p->datahandle == datahandle) { list_del(&p->list); - kfree(p); mp->nack--; - spin_unlock_irqrestore(&mp->ackqlock, flags); + spin_unlock_bh(&mp->ackqlock); + kfree(p); return 0; } } - spin_unlock_irqrestore(&mp->ackqlock, flags); + spin_unlock_bh(&mp->ackqlock); return -1; } static void capiminor_del_all_ack(struct capiminor *mp) { struct ackqueue_entry *p, *tmp; - unsigned long flags; - spin_lock_irqsave(&mp->ackqlock, flags); list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) { list_del(&p->list); kfree(p); mp->nack--; } - spin_unlock_irqrestore(&mp->ackqlock, flags); } @@ -676,7 +671,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+2)); #endif kfree_skb(skb); - (void)capiminor_del_ack(mp, datahandle); + capiminor_del_ack(mp, datahandle); tty = tty_port_tty_get(&mp->port); if (tty) { tty_wakeup(tty); -- cgit v1.2.3 From eef0ced02840cdbc9045b24e73378401aae04d4c Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:42 +0000 Subject: CAPI: Drop return value of handle_minor_send We did not evaluate handle_minor_send's return value, just (void)'ed it away. Time for a cleanup. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/capi.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c index 40b81b460e81..ee5837522f5a 100644 --- a/drivers/isdn/capi/capi.c +++ b/drivers/isdn/capi/capi.c @@ -516,25 +516,24 @@ static void handle_minor_recv(struct capiminor *mp) } } -static int handle_minor_send(struct capiminor *mp) +static void handle_minor_send(struct capiminor *mp) { struct tty_struct *tty; struct sk_buff *skb; u16 len; - int count = 0; u16 errcode; u16 datahandle; tty = tty_port_tty_get(&mp->port); if (!tty) - return 0; + return; if (mp->ttyoutstop) { #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) printk(KERN_DEBUG "capi: send: tty stopped\n"); #endif tty_kref_put(tty); - return 0; + return; } while (1) { @@ -570,12 +569,10 @@ static int handle_minor_send(struct capiminor *mp) mp->outbytes += len; spin_unlock_bh(&mp->outlock); - tty_kref_put(tty); - return count; + break; } errcode = capi20_put_message(mp->ap, skb); if (errcode == CAPI_NOERROR) { - count++; #ifdef _DEBUG_DATAFLOW printk(KERN_DEBUG "capi: DATA_B3_REQ %u len=%u\n", datahandle, len); @@ -600,7 +597,6 @@ static int handle_minor_send(struct capiminor *mp) kfree_skb(skb); } tty_kref_put(tty); - return count; } #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ @@ -677,7 +673,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) tty_wakeup(tty); tty_kref_put(tty); } - (void)handle_minor_send(mp); + handle_minor_send(mp); } else { /* ups, let capi application handle it :-) */ @@ -1114,7 +1110,7 @@ static int capinc_tty_write(struct tty_struct *tty, mp->outbytes += skb->len; spin_unlock_bh(&mp->outlock); - (void)handle_minor_send(mp); + handle_minor_send(mp); return count; } @@ -1157,7 +1153,7 @@ unlock_out: spin_unlock_bh(&mp->outlock); if (invoke_send) - (void)handle_minor_send(mp); + handle_minor_send(mp); return ret; } @@ -1179,7 +1175,7 @@ static void capinc_tty_flush_chars(struct tty_struct *tty) mp->outbytes += skb->len; spin_unlock_bh(&mp->outlock); - (void)handle_minor_send(mp); + handle_minor_send(mp); } else spin_unlock_bh(&mp->outlock); @@ -1269,7 +1265,7 @@ static void capinc_tty_start(struct tty_struct *tty) printk(KERN_DEBUG "capinc_tty_start\n"); #endif mp->ttyoutstop = 0; - (void)handle_minor_send(mp); + handle_minor_send(mp); } static void capinc_tty_hangup(struct tty_struct *tty) -- cgit v1.2.3 From c6af0437941c92179eeb51579f19423eacc5516c Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:43 +0000 Subject: CAPI: Drop special controller lookup from capi20_put_message This strange special rule to fall back to controller 1 cannot be derived from the CAPI specs and looks a lot like it was once dedicated to some out-of-tree driver, probably AVM's broken fcdsl2 (FRITZ!Card DSL v2.0). I found no in-tree user that needs this check, and I'm now taking care of the fcdsl2. So drop these bits from our stack. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/kcapi.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c index 0b4c8a7396bc..ce9b05b9e93a 100644 --- a/drivers/isdn/capi/kcapi.c +++ b/drivers/isdn/capi/kcapi.c @@ -777,11 +777,8 @@ u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb) * synchronizes this service with capi20_release. */ ctr = get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb->data)); - if (!ctr || ctr->state != CAPI_CTR_RUNNING) { - ctr = get_capi_ctr_by_nr(1); /* XXX why? */ - if (!ctr || ctr->state != CAPI_CTR_RUNNING) - return CAPI_REGNOTINSTALLED; - } + if (!ctr || ctr->state != CAPI_CTR_RUNNING) + return CAPI_REGNOTINSTALLED; if (ctr->blocked) return CAPI_SENDQUEUEFULL; -- cgit v1.2.3 From 79e95f4717767e9ddc4dbec5d778f0c9970eed34 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:44 +0000 Subject: CAPI: Schedule capifs for removal With dynamic TTY nodes and the help of udev, we no longer need this special filesystem. Schedule it for removal in one year from now. As a last duty to this feature, move its help to right option so that users can read the rationale. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/Kconfig | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/Kconfig b/drivers/isdn/capi/Kconfig index b2a04755c96a..d607d465786e 100644 --- a/drivers/isdn/capi/Kconfig +++ b/drivers/isdn/capi/Kconfig @@ -35,18 +35,19 @@ config ISDN_CAPI_CAPI20 Y/M here. config ISDN_CAPI_CAPIFS_BOOL - bool "CAPI2.0 filesystem support" + bool "CAPI2.0 filesystem support (DEPRECATED)" depends on ISDN_CAPI_MIDDLEWARE && ISDN_CAPI_CAPI20 + help + This option provides a special file system, similar to /dev/pts with + device nodes for the special ttys established by using the + middleware extension above. + You no longer need this, udev fully replaces it. This feature is + scheduled for removal. config ISDN_CAPI_CAPIFS tristate depends on ISDN_CAPI_CAPIFS_BOOL default ISDN_CAPI_CAPI20 - help - This option provides a special file system, similar to /dev/pts with - device nodes for the special ttys established by using the - middleware extension above. If you want to use pppd with - pppdcapiplugin to dial up to your ISP, say Y here. config ISDN_CAPI_CAPIDRV tristate "CAPI2.0 capidrv interface support" -- cgit v1.2.3 From 771f4c87be909ad9feb6af26424485b02deed244 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 8 Feb 2010 10:12:45 +0000 Subject: CAPI: Remove experimental tag from middleware feature Despite all its bugs, the middleware support of our CAPI stack was already in use for many, many moons. And after going through its code, fixing all issues I found, I feel it deserves to officially become a non-experimental feature. Signed-off-by: Jan Kiszka Signed-off-by: David S. Miller --- drivers/isdn/capi/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/capi/Kconfig b/drivers/isdn/capi/Kconfig index d607d465786e..a168e8a891be 100644 --- a/drivers/isdn/capi/Kconfig +++ b/drivers/isdn/capi/Kconfig @@ -17,8 +17,7 @@ config CAPI_TRACE If unsure, say Y. config ISDN_CAPI_MIDDLEWARE - bool "CAPI2.0 Middleware support (EXPERIMENTAL)" - depends on EXPERIMENTAL + bool "CAPI2.0 Middleware support" help This option will enhance the capabilities of the /dev/capi20 interface. It will provide a means of moving a data connection, -- cgit v1.2.3 From e5f8d9ac46e0291594abaa76bf467a08367bcccf Mon Sep 17 00:00:00 2001 From: Tilman Schmidt Date: Mon, 22 Feb 2010 11:09:38 +0000 Subject: isdn: fix a few Kconfig imperfections 1. Rewrite the outdated help texts for config options ISDN and ISDN_CAPI. 2. The MISDN config option appeared between ISDN_I4L and the I4L hardware driver options; move it to a less irritating place. 3. HYSDN is not in fact an I4L driver, and needn't depend on ISDN_I4L, so move it from the I4L section to the general section. 4. ISDN_HDLC is now also used by drivers outside I4L. Move it from the I4L section to the general section, too. Signed-off-by: Tilman Schmidt Signed-off-by: David S. Miller --- drivers/isdn/Kconfig | 43 ++++++++++++++++++++++++++++--------------- drivers/isdn/i4l/Kconfig | 7 ------- 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/Kconfig b/drivers/isdn/Kconfig index 022a19452953..4fb601670de3 100644 --- a/drivers/isdn/Kconfig +++ b/drivers/isdn/Kconfig @@ -7,15 +7,14 @@ menuconfig ISDN depends on NET depends on !S390 ---help--- - ISDN ("Integrated Services Digital Networks", called RNIS in France) - is a special type of fully digital telephone service; it's mostly - used to connect to your Internet service provider (with SLIP or - PPP). The main advantage is that the speed is higher than ordinary - modem/telephone connections, and that you can have voice - conversations while downloading stuff. It only works if your - computer is equipped with an ISDN card and both you and your service - provider purchased an ISDN line from the phone company. For - details, read on the WWW. + ISDN ("Integrated Services Digital Network", called RNIS in France) + is a fully digital telephone service that can be used for voice and + data connections. If your computer is equipped with an ISDN + adapter you can use it to connect to your Internet service provider + (with SLIP or PPP) faster than via a conventional telephone modem + (though still much slower than with DSL) or to make and accept + voice calls (eg. turning your PC into a software answering machine + or PABX). Select this option if you want your kernel to support ISDN. @@ -39,17 +38,22 @@ menuconfig ISDN_I4L It is still available, though, for use with adapters that are not supported by the new CAPI subsystem yet. -source "drivers/isdn/mISDN/Kconfig" - source "drivers/isdn/i4l/Kconfig" menuconfig ISDN_CAPI tristate "CAPI 2.0 subsystem" help - This provides the CAPI (Common ISDN Application Programming - Interface, a standard making it easy for programs to access ISDN - hardware, see . This is needed for AVM's set - of active ISDN controllers like B1, T1, M1. + This provides CAPI (the Common ISDN Application Programming + Interface) Version 2.0, a standard making it easy for programs to + access ISDN hardware in a device independent way. (For details see + .) CAPI supports making and accepting voice + and data connections, controlling call options and protocols, + as well as ISDN supplementary services like call forwarding or + three-party conferences (if supported by the specific hardware + driver). + + Select this option and the appropriate hardware driver below if + you have an ISDN adapter supported by the CAPI subsystem. if ISDN_CAPI @@ -61,4 +65,13 @@ endif # ISDN_CAPI source "drivers/isdn/gigaset/Kconfig" +source "drivers/isdn/hysdn/Kconfig" + +source "drivers/isdn/mISDN/Kconfig" + +config ISDN_HDLC + tristate + select CRC_CCITT + select BITREVERSE + endif # ISDN diff --git a/drivers/isdn/i4l/Kconfig b/drivers/isdn/i4l/Kconfig index 07c4e49f9e77..9c6650ea848e 100644 --- a/drivers/isdn/i4l/Kconfig +++ b/drivers/isdn/i4l/Kconfig @@ -134,14 +134,7 @@ source "drivers/isdn/sc/Kconfig" source "drivers/isdn/act2000/Kconfig" -source "drivers/isdn/hysdn/Kconfig" - endmenu # end ISDN_I4L endif -config ISDN_HDLC - tristate - select CRC_CCITT - select BITREVERSE - -- cgit v1.2.3 From 41a68a748bbc61f5bcea999e33ba72926dfbe6f7 Mon Sep 17 00:00:00 2001 From: Tilman Schmidt Date: Mon, 18 Jan 2010 17:24:10 +0100 Subject: PCI: push deprecated pci_find_device() function to last user The ISDN4Linux HiSax driver family contains the last remaining users of the deprecated pci_find_device() function. This patch creates a private copy of that function in HiSax, and removes the now unused global function together with its controlling configuration option, CONFIG_PCI_LEGACY. Signed-off-by: Tilman Schmidt Signed-off-by: Jesse Barnes --- drivers/isdn/hisax/Kconfig | 18 +++++++++--------- drivers/isdn/hisax/avm_pci.c | 6 +++--- drivers/isdn/hisax/bkm_a4t.c | 2 +- drivers/isdn/hisax/bkm_a8.c | 2 +- drivers/isdn/hisax/diva.c | 14 +++++++------- drivers/isdn/hisax/elsa.c | 8 ++++---- drivers/isdn/hisax/enternow_pci.c | 2 +- drivers/isdn/hisax/gazel.c | 8 ++++---- drivers/isdn/hisax/hfc_pci.c | 2 +- drivers/isdn/hisax/hisax.h | 23 +++++++++++++++++++++++ drivers/isdn/hisax/niccy.c | 6 +++--- drivers/isdn/hisax/nj_s.c | 2 +- drivers/isdn/hisax/nj_u.c | 2 +- drivers/isdn/hisax/sedlbauer.c | 6 +++--- drivers/isdn/hisax/telespci.c | 2 +- drivers/isdn/hisax/w6692.c | 2 +- 16 files changed, 64 insertions(+), 41 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/hisax/Kconfig b/drivers/isdn/hisax/Kconfig index 3464ebc4cdbc..452fde9edf86 100644 --- a/drivers/isdn/hisax/Kconfig +++ b/drivers/isdn/hisax/Kconfig @@ -109,7 +109,7 @@ config HISAX_16_3 config HISAX_TELESPCI bool "Teles PCI" - depends on PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) + depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) help This enables HiSax support for the Teles PCI. See on how to configure it. @@ -237,7 +237,7 @@ config HISAX_MIC config HISAX_NETJET bool "NETjet card" - depends on PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) + depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) help This enables HiSax support for the NetJet from Traverse Technologies. @@ -248,7 +248,7 @@ config HISAX_NETJET config HISAX_NETJET_U bool "NETspider U card" - depends on PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) + depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) help This enables HiSax support for the Netspider U interface ISDN card from Traverse Technologies. @@ -287,7 +287,7 @@ config HISAX_HSTSAPHIR config HISAX_BKM_A4T bool "Telekom A4T card" - depends on PCI && PCI_LEGACY + depends on PCI help This enables HiSax support for the Telekom A4T card. @@ -297,7 +297,7 @@ config HISAX_BKM_A4T config HISAX_SCT_QUADRO bool "Scitel Quadro card" - depends on PCI && PCI_LEGACY + depends on PCI help This enables HiSax support for the Scitel Quadro card. @@ -316,7 +316,7 @@ config HISAX_GAZEL config HISAX_HFC_PCI bool "HFC PCI-Bus cards" - depends on PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) + depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) help This enables HiSax support for the HFC-S PCI 2BDS0 based cards. @@ -325,7 +325,7 @@ config HISAX_HFC_PCI config HISAX_W6692 bool "Winbond W6692 based cards" - depends on PCI && PCI_LEGACY + depends on PCI help This enables HiSax support for Winbond W6692 based PCI ISDN cards. @@ -341,7 +341,7 @@ config HISAX_HFC_SX config HISAX_ENTERNOW_PCI bool "Formula-n enter:now PCI card" - depends on HISAX_NETJET && PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) + depends on HISAX_NETJET && PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) help This enables HiSax support for the Formula-n enter:now PCI ISDN card. @@ -412,7 +412,7 @@ config HISAX_HFC4S8S config HISAX_FRITZ_PCIPNP tristate "AVM Fritz!Card PCI/PCIv2/PnP support (EXPERIMENTAL)" - depends on PCI && PCI_LEGACY && EXPERIMENTAL + depends on PCI && EXPERIMENTAL help This enables the driver for the AVM Fritz!Card PCI, Fritz!Card PCI v2 and Fritz!Card PnP. diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c index 7cabc5a19492..14295a155e71 100644 --- a/drivers/isdn/hisax/avm_pci.c +++ b/drivers/isdn/hisax/avm_pci.c @@ -822,7 +822,7 @@ static int __devinit avm_pnp_setup(struct IsdnCardState *cs) #endif /* __ISAPNP__ */ -#ifndef CONFIG_PCI_LEGACY +#ifndef CONFIG_PCI static int __devinit avm_pci_setup(struct IsdnCardState *cs) { @@ -835,7 +835,7 @@ static struct pci_dev *dev_avm __devinitdata = NULL; static int __devinit avm_pci_setup(struct IsdnCardState *cs) { - if ((dev_avm = pci_find_device(PCI_VENDOR_ID_AVM, + if ((dev_avm = hisax_find_pci_device(PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_A1, dev_avm))) { if (pci_enable_device(dev_avm)) @@ -864,7 +864,7 @@ static int __devinit avm_pci_setup(struct IsdnCardState *cs) return (1); } -#endif /* CONFIG_PCI_LEGACY */ +#endif /* CONFIG_PCI */ int __devinit setup_avm_pcipnp(struct IsdnCard *card) diff --git a/drivers/isdn/hisax/bkm_a4t.c b/drivers/isdn/hisax/bkm_a4t.c index 9ca2ee54cc94..9f2009c0b69c 100644 --- a/drivers/isdn/hisax/bkm_a4t.c +++ b/drivers/isdn/hisax/bkm_a4t.c @@ -340,7 +340,7 @@ setup_bkm_a4t(struct IsdnCard *card) } else return (0); - while ((dev_a4t = pci_find_device(PCI_VENDOR_ID_ZORAN, + while ((dev_a4t = hisax_find_pci_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36120, dev_a4t))) { ret = a4t_pci_probe(dev_a4t, cs, &found, &pci_memaddr); if (!ret) diff --git a/drivers/isdn/hisax/bkm_a8.c b/drivers/isdn/hisax/bkm_a8.c index e1ff4717a8a6..e775706c60e3 100644 --- a/drivers/isdn/hisax/bkm_a8.c +++ b/drivers/isdn/hisax/bkm_a8.c @@ -301,7 +301,7 @@ setup_sct_quadro(struct IsdnCard *card) (sub_vendor_id != PCI_VENDOR_ID_BERKOM))) return (0); if (cs->subtyp == SCT_1) { - while ((dev_a8 = pci_find_device(PCI_VENDOR_ID_PLX, + while ((dev_a8 = hisax_find_pci_device(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, dev_a8))) { sub_vendor_id = dev_a8->subsystem_vendor; diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c index 0b0c2e5d806b..780da9bda915 100644 --- a/drivers/isdn/hisax/diva.c +++ b/drivers/isdn/hisax/diva.c @@ -1148,7 +1148,7 @@ static int __devinit setup_diva_isapnp(struct IsdnCard *card) #endif /* ISAPNP */ -#ifdef CONFIG_PCI_LEGACY +#ifdef CONFIG_PCI static struct pci_dev *dev_diva __devinitdata = NULL; static struct pci_dev *dev_diva_u __devinitdata = NULL; static struct pci_dev *dev_diva201 __devinitdata = NULL; @@ -1159,21 +1159,21 @@ static int __devinit setup_diva_pci(struct IsdnCard *card) struct IsdnCardState *cs = card->cs; cs->subtyp = 0; - if ((dev_diva = pci_find_device(PCI_VENDOR_ID_EICON, + if ((dev_diva = hisax_find_pci_device(PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_DIVA20, dev_diva))) { if (pci_enable_device(dev_diva)) return(0); cs->subtyp = DIVA_PCI; cs->irq = dev_diva->irq; cs->hw.diva.cfg_reg = pci_resource_start(dev_diva, 2); - } else if ((dev_diva_u = pci_find_device(PCI_VENDOR_ID_EICON, + } else if ((dev_diva_u = hisax_find_pci_device(PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_DIVA20_U, dev_diva_u))) { if (pci_enable_device(dev_diva_u)) return(0); cs->subtyp = DIVA_PCI; cs->irq = dev_diva_u->irq; cs->hw.diva.cfg_reg = pci_resource_start(dev_diva_u, 2); - } else if ((dev_diva201 = pci_find_device(PCI_VENDOR_ID_EICON, + } else if ((dev_diva201 = hisax_find_pci_device(PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_DIVA201, dev_diva201))) { if (pci_enable_device(dev_diva201)) return(0); @@ -1183,7 +1183,7 @@ static int __devinit setup_diva_pci(struct IsdnCard *card) (ulong) ioremap(pci_resource_start(dev_diva201, 0), 4096); cs->hw.diva.cfg_reg = (ulong) ioremap(pci_resource_start(dev_diva201, 1), 4096); - } else if ((dev_diva202 = pci_find_device(PCI_VENDOR_ID_EICON, + } else if ((dev_diva202 = hisax_find_pci_device(PCI_VENDOR_ID_EICON, PCI_DEVICE_ID_EICON_DIVA202, dev_diva202))) { if (pci_enable_device(dev_diva202)) return(0); @@ -1229,14 +1229,14 @@ static int __devinit setup_diva_pci(struct IsdnCard *card) return (1); /* card found */ } -#else /* if !CONFIG_PCI_LEGACY */ +#else /* if !CONFIG_PCI */ static int __devinit setup_diva_pci(struct IsdnCard *card) { return (-1); /* card not found; continue search */ } -#endif /* CONFIG_PCI_LEGACY */ +#endif /* CONFIG_PCI */ int __devinit setup_diva(struct IsdnCard *card) diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c index aa29d1cf16af..23c41fcd864e 100644 --- a/drivers/isdn/hisax/elsa.c +++ b/drivers/isdn/hisax/elsa.c @@ -1025,7 +1025,7 @@ setup_elsa_pcmcia(struct IsdnCard *card) cs->irq); } -#ifdef CONFIG_PCI_LEGACY +#ifdef CONFIG_PCI static struct pci_dev *dev_qs1000 __devinitdata = NULL; static struct pci_dev *dev_qs3000 __devinitdata = NULL; @@ -1035,7 +1035,7 @@ setup_elsa_pci(struct IsdnCard *card) struct IsdnCardState *cs = card->cs; cs->subtyp = 0; - if ((dev_qs1000 = pci_find_device(PCI_VENDOR_ID_ELSA, + if ((dev_qs1000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA, PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) { if (pci_enable_device(dev_qs1000)) return(0); @@ -1043,7 +1043,7 @@ setup_elsa_pci(struct IsdnCard *card) cs->irq = dev_qs1000->irq; cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1); cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3); - } else if ((dev_qs3000 = pci_find_device(PCI_VENDOR_ID_ELSA, + } else if ((dev_qs3000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA, PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) { if (pci_enable_device(dev_qs3000)) return(0); @@ -1093,7 +1093,7 @@ setup_elsa_pci(struct IsdnCard *card) { return (1); } -#endif /* CONFIG_PCI_LEGACY */ +#endif /* CONFIG_PCI */ static int __devinit setup_elsa_common(struct IsdnCard *card) diff --git a/drivers/isdn/hisax/enternow_pci.c b/drivers/isdn/hisax/enternow_pci.c index 39f421ed8de8..26264abf1f58 100644 --- a/drivers/isdn/hisax/enternow_pci.c +++ b/drivers/isdn/hisax/enternow_pci.c @@ -406,7 +406,7 @@ setup_enternow_pci(struct IsdnCard *card) for ( ;; ) { - if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET, + if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) { ret = en_pci_probe(dev_netjet, cs); if (!ret) diff --git a/drivers/isdn/hisax/gazel.c b/drivers/isdn/hisax/gazel.c index 0ea3b4607680..353982fc1436 100644 --- a/drivers/isdn/hisax/gazel.c +++ b/drivers/isdn/hisax/gazel.c @@ -531,7 +531,7 @@ setup_gazelisa(struct IsdnCard *card, struct IsdnCardState *cs) return (0); } -#ifdef CONFIG_PCI_LEGACY +#ifdef CONFIG_PCI static struct pci_dev *dev_tel __devinitdata = NULL; static int __devinit @@ -546,7 +546,7 @@ setup_gazelpci(struct IsdnCardState *cs) found = 0; seekcard = PCI_DEVICE_ID_PLX_R685; for (nbseek = 0; nbseek < 4; nbseek++) { - if ((dev_tel = pci_find_device(PCI_VENDOR_ID_PLX, + if ((dev_tel = hisax_find_pci_device(PCI_VENDOR_ID_PLX, seekcard, dev_tel))) { if (pci_enable_device(dev_tel)) return 1; @@ -620,7 +620,7 @@ setup_gazelpci(struct IsdnCardState *cs) return (0); } -#endif /* CONFIG_PCI_LEGACY */ +#endif /* CONFIG_PCI */ int __devinit setup_gazel(struct IsdnCard *card) @@ -640,7 +640,7 @@ setup_gazel(struct IsdnCard *card) return (0); } else { -#ifdef CONFIG_PCI_LEGACY +#ifdef CONFIG_PCI if (setup_gazelpci(cs)) return (0); #else diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c index 10914731b304..917cc84065bd 100644 --- a/drivers/isdn/hisax/hfc_pci.c +++ b/drivers/isdn/hisax/hfc_pci.c @@ -1658,7 +1658,7 @@ setup_hfcpci(struct IsdnCard *card) i = 0; while (id_list[i].vendor_id) { - tmp_hfcpci = pci_find_device(id_list[i].vendor_id, + tmp_hfcpci = hisax_find_pci_device(id_list[i].vendor_id, id_list[i].device_id, dev_hfcpci); i++; diff --git a/drivers/isdn/hisax/hisax.h b/drivers/isdn/hisax/hisax.h index 0685c1946969..832a87855ffb 100644 --- a/drivers/isdn/hisax/hisax.h +++ b/drivers/isdn/hisax/hisax.h @@ -1323,3 +1323,26 @@ void release_tei(struct IsdnCardState *cs); char *HiSax_getrev(const char *revision); int TeiNew(void); void TeiFree(void); + +#ifdef CONFIG_PCI + +#include + +/* adaptation wrapper for old usage + * WARNING! This is unfit for use in a PCI hotplug environment, + * as the returned PCI device can disappear at any moment in time. + * Callers should be converted to use pci_get_device() instead. + */ +static inline struct pci_dev *hisax_find_pci_device(unsigned int vendor, + unsigned int device, + struct pci_dev *from) +{ + struct pci_dev *pdev; + + pci_dev_get(from); + pdev = pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from); + pci_dev_put(pdev); + return pdev; +} + +#endif diff --git a/drivers/isdn/hisax/niccy.c b/drivers/isdn/hisax/niccy.c index ef00633e1d2a..ccaa6e13310f 100644 --- a/drivers/isdn/hisax/niccy.c +++ b/drivers/isdn/hisax/niccy.c @@ -297,12 +297,12 @@ int __devinit setup_niccy(struct IsdnCard *card) return 0; } } else { -#ifdef CONFIG_PCI_LEGACY +#ifdef CONFIG_PCI static struct pci_dev *niccy_dev __devinitdata; u_int pci_ioaddr; cs->subtyp = 0; - if ((niccy_dev = pci_find_device(PCI_VENDOR_ID_SATSAGEM, + if ((niccy_dev = hisax_find_pci_device(PCI_VENDOR_ID_SATSAGEM, PCI_DEVICE_ID_SATSAGEM_NICCY, niccy_dev))) { if (pci_enable_device(niccy_dev)) @@ -354,7 +354,7 @@ int __devinit setup_niccy(struct IsdnCard *card) printk(KERN_WARNING "Niccy: io0 0 and NO_PCI_BIOS\n"); printk(KERN_WARNING "Niccy: unable to config NICCY PCI\n"); return 0; -#endif /* CONFIG_PCI_LEGACY */ +#endif /* CONFIG_PCI */ } printk(KERN_INFO "HiSax: NICCY %s config irq:%d data:0x%X ale:0x%X\n", (cs->subtyp == 1) ? "PnP" : "PCI", diff --git a/drivers/isdn/hisax/nj_s.c b/drivers/isdn/hisax/nj_s.c index 8d36ccc87d81..2344e7b33448 100644 --- a/drivers/isdn/hisax/nj_s.c +++ b/drivers/isdn/hisax/nj_s.c @@ -276,7 +276,7 @@ setup_netjet_s(struct IsdnCard *card) for ( ;; ) { - if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET, + if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) { ret = njs_pci_probe(dev_netjet, cs); if (!ret) diff --git a/drivers/isdn/hisax/nj_u.c b/drivers/isdn/hisax/nj_u.c index d306c946ffba..095e974aed80 100644 --- a/drivers/isdn/hisax/nj_u.c +++ b/drivers/isdn/hisax/nj_u.c @@ -240,7 +240,7 @@ setup_netjet_u(struct IsdnCard *card) for ( ;; ) { - if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET, + if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) { ret = nju_pci_probe(dev_netjet, cs); if (!ret) diff --git a/drivers/isdn/hisax/sedlbauer.c b/drivers/isdn/hisax/sedlbauer.c index 5569a522e2a1..69dfc8d29017 100644 --- a/drivers/isdn/hisax/sedlbauer.c +++ b/drivers/isdn/hisax/sedlbauer.c @@ -598,7 +598,7 @@ setup_sedlbauer_isapnp(struct IsdnCard *card, int *bytecnt) } #endif /* __ISAPNP__ */ -#ifdef CONFIG_PCI_LEGACY +#ifdef CONFIG_PCI static struct pci_dev *dev_sedl __devinitdata = NULL; static int __devinit @@ -607,7 +607,7 @@ setup_sedlbauer_pci(struct IsdnCard *card) struct IsdnCardState *cs = card->cs; u16 sub_vendor_id, sub_id; - if ((dev_sedl = pci_find_device(PCI_VENDOR_ID_TIGERJET, + if ((dev_sedl = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_100, dev_sedl))) { if (pci_enable_device(dev_sedl)) return(0); @@ -673,7 +673,7 @@ setup_sedlbauer_pci(struct IsdnCard *card) return (1); } -#endif /* CONFIG_PCI_LEGACY */ +#endif /* CONFIG_PCI */ int __devinit setup_sedlbauer(struct IsdnCard *card) diff --git a/drivers/isdn/hisax/telespci.c b/drivers/isdn/hisax/telespci.c index 28b08de4673d..b85ceb3746ce 100644 --- a/drivers/isdn/hisax/telespci.c +++ b/drivers/isdn/hisax/telespci.c @@ -300,7 +300,7 @@ setup_telespci(struct IsdnCard *card) if (cs->typ != ISDN_CTYPE_TELESPCI) return (0); - if ((dev_tel = pci_find_device (PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36120, dev_tel))) { + if ((dev_tel = hisax_find_pci_device (PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36120, dev_tel))) { if (pci_enable_device(dev_tel)) return(0); cs->irq = dev_tel->irq; diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c index c4d862c11a60..9d6e864023fe 100644 --- a/drivers/isdn/hisax/w6692.c +++ b/drivers/isdn/hisax/w6692.c @@ -1007,7 +1007,7 @@ setup_w6692(struct IsdnCard *card) return (0); while (id_list[id_idx].vendor_id) { - dev_w6692 = pci_find_device(id_list[id_idx].vendor_id, + dev_w6692 = hisax_find_pci_device(id_list[id_idx].vendor_id, id_list[id_idx].device_id, dev_w6692); if (dev_w6692) { -- cgit v1.2.3 From 63e055d1c6e3a5f6d370cc841d621d5fa4d5d834 Mon Sep 17 00:00:00 2001 From: Tilman Schmidt Date: Mon, 22 Feb 2010 13:09:22 +0000 Subject: bas_gigaset: collapse CR/LF at end of AT response Copy the mechanism from ser_/usb_gigaset to avoid producing spurious empty responses for CR/LF sequences from the device. Add a comment in all drivers documenting that behaviour. Correct an off by one error that might result in a one byte buffer overflow when receiving an unexpectedly long reply. Impact: minor bugfix Signed-off-by: Tilman Schmidt Signed-off-by: David S. Miller --- drivers/isdn/gigaset/asyncdata.c | 2 ++ drivers/isdn/gigaset/gigaset.h | 4 ++-- drivers/isdn/gigaset/isocdata.c | 44 ++++++++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 15 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c index ccb2a7b7c41d..e913beb63f24 100644 --- a/drivers/isdn/gigaset/asyncdata.c +++ b/drivers/isdn/gigaset/asyncdata.c @@ -40,6 +40,8 @@ static inline int muststuff(unsigned char c) * Append received bytes to the command response buffer and forward them * line by line to the response handler. Exit whenever a mode/state change * might have occurred. + * Note: Received lines may be terminated by CR, LF, or CR LF, which will be + * removed before passing the line to the response handler. * Return value: * number of processed bytes */ diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h index e963a6c2e86d..c9ccf7de2275 100644 --- a/drivers/isdn/gigaset/gigaset.h +++ b/drivers/isdn/gigaset/gigaset.h @@ -38,7 +38,7 @@ #define GIG_COMPAT {0, 4, 0, 0} #define MAX_REC_PARAMS 10 /* Max. number of params in response string */ -#define MAX_RESP_SIZE 512 /* Max. size of a response string */ +#define MAX_RESP_SIZE 511 /* Max. size of a response string */ #define MAX_EVENTS 64 /* size of event queue */ @@ -498,7 +498,7 @@ struct cardstate { spinlock_t ev_lock; /* current modem response */ - unsigned char respdata[MAX_RESP_SIZE]; + unsigned char respdata[MAX_RESP_SIZE+1]; unsigned cbytes; /* private data of hardware drivers */ diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c index 85394a6ebae8..16fd3bd48883 100644 --- a/drivers/isdn/gigaset/isocdata.c +++ b/drivers/isdn/gigaset/isocdata.c @@ -905,29 +905,49 @@ void gigaset_isoc_receive(unsigned char *src, unsigned count, /* == data input =========================================================== */ +/* process a block of received bytes in command mode (mstate != MS_LOCKED) + * Append received bytes to the command response buffer and forward them + * line by line to the response handler. + * Note: Received lines may be terminated by CR, LF, or CR LF, which will be + * removed before passing the line to the response handler. + */ static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf) { struct cardstate *cs = inbuf->cs; unsigned cbytes = cs->cbytes; + unsigned char c; while (numbytes--) { - /* copy next character, check for end of line */ - switch (cs->respdata[cbytes] = *src++) { - case '\r': + c = *src++; + switch (c) { case '\n': - /* end of line */ - gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)", - __func__, cbytes); - if (cbytes >= MAX_RESP_SIZE - 1) - dev_warn(cs->dev, "response too large\n"); + if (cbytes == 0 && cs->respdata[0] == '\r') { + /* collapse LF with preceding CR */ + cs->respdata[0] = 0; + break; + } + /* --v-- fall through --v-- */ + case '\r': + /* end of message line, pass to response handler */ + if (cbytes >= MAX_RESP_SIZE) { + dev_warn(cs->dev, "response too large (%d)\n", + cbytes); + cbytes = MAX_RESP_SIZE; + } cs->cbytes = cbytes; + gigaset_dbg_buffer(DEBUG_TRANSCMD, "received response", + cbytes, cs->respdata); gigaset_handle_modem_response(cs); cbytes = 0; + + /* store EOL byte for CRLF collapsing */ + cs->respdata[0] = c; break; default: - /* advance in line buffer, checking for overflow */ - if (cbytes < MAX_RESP_SIZE - 1) - cbytes++; + /* append to line buffer if possible */ + if (cbytes < MAX_RESP_SIZE) + cs->respdata[cbytes] = c; + cbytes++; } } @@ -958,8 +978,6 @@ void gigaset_isoc_input(struct inbuf_t *inbuf) numbytes, src); gigaset_if_receive(inbuf->cs, src, numbytes); } else { - gigaset_dbg_buffer(DEBUG_CMD, "received response", - numbytes, src); cmd_loop(src, numbytes, inbuf); } -- cgit v1.2.3 From 1528b18f7ec2b907711f37667c68e10d9296c882 Mon Sep 17 00:00:00 2001 From: Tilman Schmidt Date: Mon, 22 Feb 2010 13:09:52 +0000 Subject: gigaset: reduce syslog clutter Improve readability of the Gigaset driver's kernel messages by removing a few unnecessary messages and limiting the emission of some debug messages more narrowly. Impact: logging Signed-off-by: Tilman Schmidt Signed-off-by: David S. Miller --- drivers/isdn/gigaset/asyncdata.c | 4 +-- drivers/isdn/gigaset/bas-gigaset.c | 18 ++++------- drivers/isdn/gigaset/capi.c | 15 +++------ drivers/isdn/gigaset/common.c | 49 ++++++++++++----------------- drivers/isdn/gigaset/ev-layer.c | 63 +++++++++++++++++++------------------- drivers/isdn/gigaset/gigaset.h | 7 ++--- drivers/isdn/gigaset/i4l.c | 52 ++++--------------------------- drivers/isdn/gigaset/interface.c | 12 +++----- drivers/isdn/gigaset/proc.c | 2 -- drivers/isdn/gigaset/usb-gigaset.c | 2 +- 10 files changed, 77 insertions(+), 147 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c index e913beb63f24..c5016bd2d94f 100644 --- a/drivers/isdn/gigaset/asyncdata.c +++ b/drivers/isdn/gigaset/asyncdata.c @@ -67,14 +67,14 @@ static unsigned cmd_loop(unsigned numbytes, struct inbuf_t *inbuf) /* --v-- fall through --v-- */ case '\r': /* end of message line, pass to response handler */ - gig_dbg(DEBUG_TRANSCMD, "%s: End of Message (%d Bytes)", - __func__, cbytes); if (cbytes >= MAX_RESP_SIZE) { dev_warn(cs->dev, "response too large (%d)\n", cbytes); cbytes = MAX_RESP_SIZE; } cs->cbytes = cbytes; + gigaset_dbg_buffer(DEBUG_TRANSCMD, "received response", + cbytes, cs->respdata); gigaset_handle_modem_response(cs); cbytes = 0; diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c index 95ebc5129895..0be15c70c16d 100644 --- a/drivers/isdn/gigaset/bas-gigaset.c +++ b/drivers/isdn/gigaset/bas-gigaset.c @@ -347,12 +347,7 @@ static inline void error_hangup(struct bc_state *bcs) { struct cardstate *cs = bcs->cs; - gig_dbg(DEBUG_ANY, "%s: scheduling HUP for channel %d", - __func__, bcs->channel); - - if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) - dev_err(cs->dev, "event queue full\n"); - + gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL); gigaset_schedule_event(cs); } @@ -1706,8 +1701,7 @@ static void complete_cb(struct cardstate *cs) /* unqueue completed buffer */ cs->cmdbytes -= cs->curlen; - gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, - "write_command: sent %u bytes, %u left", + gig_dbg(DEBUG_OUTPUT, "write_command: sent %u bytes, %u left", cs->curlen, cs->cmdbytes); if (cb->next != NULL) { cs->cmdbuf = cb->next; @@ -1881,13 +1875,13 @@ static int start_cbsend(struct cardstate *cs) /* check if suspend requested */ if (ucs->basstate & BS_SUSPEND) { - gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "suspending"); + gig_dbg(DEBUG_OUTPUT, "suspending"); return -EHOSTUNREACH; } /* check if AT channel is open */ if (!(ucs->basstate & BS_ATOPEN)) { - gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "AT channel not open"); + gig_dbg(DEBUG_OUTPUT, "AT channel not open"); rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT); if (rc < 0) { /* flush command queue */ @@ -2251,7 +2245,7 @@ static int gigaset_probe(struct usb_interface *interface, int i, j; int rc; - gig_dbg(DEBUG_ANY, + gig_dbg(DEBUG_INIT, "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)", __func__, le16_to_cpu(udev->descriptor.idVendor), le16_to_cpu(udev->descriptor.idProduct)); @@ -2259,7 +2253,7 @@ static int gigaset_probe(struct usb_interface *interface, /* set required alternate setting */ hostif = interface->cur_altsetting; if (hostif->desc.bAlternateSetting != 3) { - gig_dbg(DEBUG_ANY, + gig_dbg(DEBUG_INIT, "%s: wrong alternate setting %d - trying to switch", __func__, hostif->desc.bAlternateSetting); if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c index 6f0ae32906bf..20ebcee9b0c0 100644 --- a/drivers/isdn/gigaset/capi.c +++ b/drivers/isdn/gigaset/capi.c @@ -1427,9 +1427,10 @@ static void do_connect_req(struct gigaset_capi_ctr *iif, /* queue & schedule EV_DIAL event */ if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands, - bcs->at_state.seq_index, NULL)) - goto oom; - gig_dbg(DEBUG_CMD, "scheduling DIAL"); + bcs->at_state.seq_index, NULL)) { + info = CAPI_MSGOSRESOURCEERR; + goto error; + } gigaset_schedule_event(cs); ap->connected = APCONN_SETUP; send_conf(iif, ap, skb, CapiSuccess); @@ -1543,7 +1544,6 @@ static void do_connect_resp(struct gigaset_capi_ctr *iif, if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state, EV_ACCEPT, NULL, 0, NULL)) return; - gig_dbg(DEBUG_CMD, "scheduling ACCEPT"); gigaset_schedule_event(cs); return; @@ -1584,7 +1584,6 @@ static void do_connect_resp(struct gigaset_capi_ctr *iif, if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state, EV_HUP, NULL, 0, NULL)) return; - gig_dbg(DEBUG_CMD, "scheduling HUP"); gigaset_schedule_event(cs); return; } @@ -1667,11 +1666,9 @@ static void do_connect_b3_resp(struct gigaset_capi_ctr *iif, /* trigger hangup, causing eventual DISCONNECT_IND */ if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) { - dev_err(cs->dev, "%s: out of memory\n", __func__); dev_kfree_skb_any(skb); return; } - gig_dbg(DEBUG_CMD, "scheduling HUP"); gigaset_schedule_event(cs); /* emit DISCONNECT_B3_IND */ @@ -1770,11 +1767,9 @@ static void do_disconnect_req(struct gigaset_capi_ctr *iif, /* trigger hangup, causing eventual DISCONNECT_IND */ if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) { - dev_err(cs->dev, "%s: out of memory\n", __func__); send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR); return; } - gig_dbg(DEBUG_CMD, "scheduling HUP"); gigaset_schedule_event(cs); /* emit reply */ @@ -1817,11 +1812,9 @@ static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif, /* trigger hangup, causing eventual DISCONNECT_B3_IND */ if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state, EV_HUP, NULL, 0, NULL)) { - dev_err(cs->dev, "%s: out of memory\n", __func__); send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR); return; } - gig_dbg(DEBUG_CMD, "scheduling HUP"); gigaset_schedule_event(cs); /* NCPI parameter: not applicable for B3 Transparent */ diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c index 664b0c519c3e..85de3399a2f2 100644 --- a/drivers/isdn/gigaset/common.c +++ b/drivers/isdn/gigaset/common.c @@ -149,10 +149,8 @@ static int test_timeout(struct at_state_t *at_state) return 0; } - if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL, - at_state->timer_index, NULL)) - dev_err(at_state->cs->dev, "%s: out of memory\n", - __func__); + gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL, + at_state->timer_index, NULL); return 1; } @@ -180,7 +178,7 @@ static void timer_tick(unsigned long data) if (cs->running) { mod_timer(&cs->timer, jiffies + msecs_to_jiffies(GIG_TICK)); if (timeout) { - gig_dbg(DEBUG_CMD, "scheduling timeout"); + gig_dbg(DEBUG_EVENT, "scheduling timeout"); tasklet_schedule(&cs->event_tasklet); } } @@ -194,14 +192,14 @@ int gigaset_get_channel(struct bc_state *bcs) spin_lock_irqsave(&bcs->cs->lock, flags); if (bcs->use_count || !try_module_get(bcs->cs->driver->owner)) { - gig_dbg(DEBUG_ANY, "could not allocate channel %d", + gig_dbg(DEBUG_CHANNEL, "could not allocate channel %d", bcs->channel); spin_unlock_irqrestore(&bcs->cs->lock, flags); return 0; } ++bcs->use_count; bcs->busy = 1; - gig_dbg(DEBUG_ANY, "allocated channel %d", bcs->channel); + gig_dbg(DEBUG_CHANNEL, "allocated channel %d", bcs->channel); spin_unlock_irqrestore(&bcs->cs->lock, flags); return 1; } @@ -213,7 +211,7 @@ struct bc_state *gigaset_get_free_channel(struct cardstate *cs) spin_lock_irqsave(&cs->lock, flags); if (!try_module_get(cs->driver->owner)) { - gig_dbg(DEBUG_ANY, + gig_dbg(DEBUG_CHANNEL, "could not get module for allocating channel"); spin_unlock_irqrestore(&cs->lock, flags); return NULL; @@ -223,12 +221,12 @@ struct bc_state *gigaset_get_free_channel(struct cardstate *cs) ++cs->bcs[i].use_count; cs->bcs[i].busy = 1; spin_unlock_irqrestore(&cs->lock, flags); - gig_dbg(DEBUG_ANY, "allocated channel %d", i); + gig_dbg(DEBUG_CHANNEL, "allocated channel %d", i); return cs->bcs + i; } module_put(cs->driver->owner); spin_unlock_irqrestore(&cs->lock, flags); - gig_dbg(DEBUG_ANY, "no free channel"); + gig_dbg(DEBUG_CHANNEL, "no free channel"); return NULL; } @@ -238,14 +236,15 @@ void gigaset_free_channel(struct bc_state *bcs) spin_lock_irqsave(&bcs->cs->lock, flags); if (!bcs->busy) { - gig_dbg(DEBUG_ANY, "could not free channel %d", bcs->channel); + gig_dbg(DEBUG_CHANNEL, "could not free channel %d", + bcs->channel); spin_unlock_irqrestore(&bcs->cs->lock, flags); return; } --bcs->use_count; bcs->busy = 0; module_put(bcs->cs->driver->owner); - gig_dbg(DEBUG_ANY, "freed channel %d", bcs->channel); + gig_dbg(DEBUG_CHANNEL, "freed channel %d", bcs->channel); spin_unlock_irqrestore(&bcs->cs->lock, flags); } @@ -258,14 +257,15 @@ int gigaset_get_channels(struct cardstate *cs) for (i = 0; i < cs->channels; ++i) if (cs->bcs[i].use_count) { spin_unlock_irqrestore(&cs->lock, flags); - gig_dbg(DEBUG_ANY, "could not allocate all channels"); + gig_dbg(DEBUG_CHANNEL, + "could not allocate all channels"); return 0; } for (i = 0; i < cs->channels; ++i) ++cs->bcs[i].use_count; spin_unlock_irqrestore(&cs->lock, flags); - gig_dbg(DEBUG_ANY, "allocated all channels"); + gig_dbg(DEBUG_CHANNEL, "allocated all channels"); return 1; } @@ -275,7 +275,7 @@ void gigaset_free_channels(struct cardstate *cs) unsigned long flags; int i; - gig_dbg(DEBUG_ANY, "unblocking all channels"); + gig_dbg(DEBUG_CHANNEL, "unblocking all channels"); spin_lock_irqsave(&cs->lock, flags); for (i = 0; i < cs->channels; ++i) --cs->bcs[i].use_count; @@ -287,7 +287,7 @@ void gigaset_block_channels(struct cardstate *cs) unsigned long flags; int i; - gig_dbg(DEBUG_ANY, "blocking all channels"); + gig_dbg(DEBUG_CHANNEL, "blocking all channels"); spin_lock_irqsave(&cs->lock, flags); for (i = 0; i < cs->channels; ++i) ++cs->bcs[i].use_count; @@ -338,6 +338,8 @@ struct event_t *gigaset_add_event(struct cardstate *cs, unsigned next, tail; struct event_t *event = NULL; + gig_dbg(DEBUG_EVENT, "queueing event %d", type); + spin_lock_irqsave(&cs->ev_lock, flags); tail = cs->ev_tail; @@ -934,11 +936,8 @@ int gigaset_start(struct cardstate *cs) if (!gigaset_add_event(cs, &cs->at_state, EV_START, NULL, 0, NULL)) { cs->waiting = 0; - dev_err(cs->dev, "%s: out of memory\n", __func__); goto error; } - - gig_dbg(DEBUG_CMD, "scheduling START"); gigaset_schedule_event(cs); wait_event(cs->waitqueue, !cs->waiting); @@ -973,12 +972,8 @@ int gigaset_shutdown(struct cardstate *cs) cs->waiting = 1; - if (!gigaset_add_event(cs, &cs->at_state, EV_SHUTDOWN, NULL, 0, NULL)) { - dev_err(cs->dev, "%s: out of memory\n", __func__); + if (!gigaset_add_event(cs, &cs->at_state, EV_SHUTDOWN, NULL, 0, NULL)) goto exit; - } - - gig_dbg(DEBUG_CMD, "scheduling SHUTDOWN"); gigaset_schedule_event(cs); wait_event(cs->waitqueue, !cs->waiting); @@ -1004,12 +999,8 @@ void gigaset_stop(struct cardstate *cs) cs->waiting = 1; - if (!gigaset_add_event(cs, &cs->at_state, EV_STOP, NULL, 0, NULL)) { - dev_err(cs->dev, "%s: out of memory\n", __func__); + if (!gigaset_add_event(cs, &cs->at_state, EV_STOP, NULL, 0, NULL)) goto exit; - } - - gig_dbg(DEBUG_CMD, "scheduling STOP"); gigaset_schedule_event(cs); wait_event(cs->waitqueue, !cs->waiting); diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c index ddeb0456d202..c8f89b78b233 100644 --- a/drivers/isdn/gigaset/ev-layer.c +++ b/drivers/isdn/gigaset/ev-layer.c @@ -427,7 +427,7 @@ static int isdn_getnum(char *p) { int v = -1; - gig_dbg(DEBUG_TRANSCMD, "string: %s", p); + gig_dbg(DEBUG_EVENT, "string: %s", p); while (*p >= '0' && *p <= '9') v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0'); @@ -444,7 +444,7 @@ static int isdn_gethex(char *p) int v = 0; int c; - gig_dbg(DEBUG_TRANSCMD, "string: %s", p); + gig_dbg(DEBUG_EVENT, "string: %s", p); if (!*p) return -1; @@ -517,7 +517,6 @@ void gigaset_handle_modem_response(struct cardstate *cs) return; } cs->respdata[len] = 0; - gig_dbg(DEBUG_TRANSCMD, "raw string: '%s'", cs->respdata); argv[0] = cs->respdata; params = 1; if (cs->at_state.getstring) { @@ -552,14 +551,14 @@ void gigaset_handle_modem_response(struct cardstate *cs) for (j = 1; j < params; ++j) argv[j][-1] = 0; - gig_dbg(DEBUG_TRANSCMD, "CMD received: %s", argv[0]); + gig_dbg(DEBUG_EVENT, "CMD received: %s", argv[0]); if (cid) { --params; - gig_dbg(DEBUG_TRANSCMD, "CID: %s", argv[params]); + gig_dbg(DEBUG_EVENT, "CID: %s", argv[params]); } - gig_dbg(DEBUG_TRANSCMD, "available params: %d", params - 1); + gig_dbg(DEBUG_EVENT, "available params: %d", params - 1); for (j = 1; j < params; j++) - gig_dbg(DEBUG_TRANSCMD, "param %d: %s", j, argv[j]); + gig_dbg(DEBUG_EVENT, "param %d: %s", j, argv[j]); } spin_lock_irqsave(&cs->ev_lock, flags); @@ -642,7 +641,7 @@ void gigaset_handle_modem_response(struct cardstate *cs) dev_err(cs->dev, "out of memory\n"); ++curarg; } - gig_dbg(DEBUG_CMD, "string==%s", + gig_dbg(DEBUG_EVENT, "string==%s", event->ptr ? (char *) event->ptr : "NULL"); break; case RT_ZCAU: @@ -669,7 +668,7 @@ void gigaset_handle_modem_response(struct cardstate *cs) ++curarg; } else event->parameter = -1; - gig_dbg(DEBUG_CMD, "parameter==%d", event->parameter); + gig_dbg(DEBUG_EVENT, "parameter==%d", event->parameter); break; } @@ -684,7 +683,7 @@ void gigaset_handle_modem_response(struct cardstate *cs) spin_unlock_irqrestore(&cs->ev_lock, flags); if (curarg != params) - gig_dbg(DEBUG_ANY, + gig_dbg(DEBUG_EVENT, "invalid number of processed parameters: %d/%d", curarg, params); } @@ -705,8 +704,8 @@ static void disconnect(struct at_state_t **at_state_p) /* revert to selected idle mode */ if (!cs->cidmode) { cs->at_state.pending_commands |= PC_UMMODE; + gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE"); cs->commands_pending = 1; - gig_dbg(DEBUG_CMD, "Scheduling PC_UMMODE"); } spin_unlock_irqrestore(&cs->lock, flags); @@ -784,15 +783,15 @@ static void init_failed(struct cardstate *cs, int mode) static void schedule_init(struct cardstate *cs, int state) { if (cs->at_state.pending_commands & PC_INIT) { - gig_dbg(DEBUG_CMD, "not scheduling PC_INIT again"); + gig_dbg(DEBUG_EVENT, "not scheduling PC_INIT again"); return; } cs->mstate = state; cs->mode = M_UNKNOWN; gigaset_block_channels(cs); cs->at_state.pending_commands |= PC_INIT; + gig_dbg(DEBUG_EVENT, "Scheduling PC_INIT"); cs->commands_pending = 1; - gig_dbg(DEBUG_CMD, "Scheduling PC_INIT"); } /* Add "AT" to a command, add the cid, dle encode it, send the result to the @@ -923,7 +922,7 @@ static void start_dial(struct at_state_t *at_state, void *data, } at_state->pending_commands |= PC_CID; - gig_dbg(DEBUG_CMD, "Scheduling PC_CID"); + gig_dbg(DEBUG_EVENT, "Scheduling PC_CID"); cs->commands_pending = 1; return; @@ -933,7 +932,7 @@ error: commands[i] = NULL; } at_state->pending_commands |= PC_NOCID; - gig_dbg(DEBUG_CMD, "Scheduling PC_NOCID"); + gig_dbg(DEBUG_EVENT, "Scheduling PC_NOCID"); cs->commands_pending = 1; return; } @@ -955,7 +954,7 @@ static void start_accept(struct at_state_t *at_state) dev_err(at_state->cs->dev, "out of memory\n"); /* error reset */ at_state->pending_commands |= PC_HUP; - gig_dbg(DEBUG_CMD, "Scheduling PC_HUP"); + gig_dbg(DEBUG_EVENT, "Scheduling PC_HUP"); cs->commands_pending = 1; return; } @@ -964,7 +963,7 @@ static void start_accept(struct at_state_t *at_state) snprintf(bcs->commands[AT_ISO], 9, "^SISO=%u\r", bcs->channel + 1); at_state->pending_commands |= PC_ACCEPT; - gig_dbg(DEBUG_CMD, "Scheduling PC_ACCEPT"); + gig_dbg(DEBUG_EVENT, "Scheduling PC_ACCEPT"); cs->commands_pending = 1; } @@ -1009,8 +1008,8 @@ static void do_shutdown(struct cardstate *cs) if (cs->mstate == MS_READY) { cs->mstate = MS_SHUTDOWN; cs->at_state.pending_commands |= PC_SHUTDOWN; + gig_dbg(DEBUG_EVENT, "Scheduling PC_SHUTDOWN"); cs->commands_pending = 1; - gig_dbg(DEBUG_CMD, "Scheduling PC_SHUTDOWN"); } else finish_shutdown(cs); } @@ -1191,8 +1190,8 @@ static void do_action(int action, struct cardstate *cs, } spin_unlock_irqrestore(&cs->lock, flags); cs->at_state.pending_commands |= PC_CIDMODE; + gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); cs->commands_pending = 1; - gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); break; case ACT_FAILINIT: dev_warn(cs->dev, "Could not initialize the device.\n"); @@ -1443,7 +1442,7 @@ static void do_action(int action, struct cardstate *cs, case ACT_GOTVER: if (cs->gotfwver == 0) { cs->gotfwver = 1; - gig_dbg(DEBUG_ANY, + gig_dbg(DEBUG_EVENT, "firmware version %02d.%03d.%02d.%02d", cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]); @@ -1481,8 +1480,8 @@ static void do_action(int action, struct cardstate *cs, break; case ACT_HUP: at_state->pending_commands |= PC_HUP; + gig_dbg(DEBUG_EVENT, "Scheduling PC_HUP"); cs->commands_pending = 1; - gig_dbg(DEBUG_CMD, "Scheduling PC_HUP"); break; /* hotplug events */ @@ -1519,10 +1518,10 @@ static void do_action(int action, struct cardstate *cs, cs->cidmode = ev->parameter; if (ev->parameter) { cs->at_state.pending_commands |= PC_CIDMODE; - gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); + gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); } else { cs->at_state.pending_commands |= PC_UMMODE; - gig_dbg(DEBUG_CMD, "Scheduling PC_UMMODE"); + gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE"); } cs->commands_pending = 1; } @@ -1573,6 +1572,8 @@ static void process_event(struct cardstate *cs, struct event_t *ev) if (ev->cid >= 0) { at_state = at_state_from_cid(cs, ev->cid); if (!at_state) { + gig_dbg(DEBUG_EVENT, "event %d for invalid cid %d", + ev->type, ev->cid); gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID, NULL, 0, NULL); return; @@ -1580,13 +1581,13 @@ static void process_event(struct cardstate *cs, struct event_t *ev) } else { at_state = ev->at_state; if (at_state_invalid(cs, at_state)) { - gig_dbg(DEBUG_ANY, "event for invalid at_state %p", + gig_dbg(DEBUG_EVENT, "event for invalid at_state %p", at_state); return; } } - gig_dbg(DEBUG_CMD, "connection state %d, event %d", + gig_dbg(DEBUG_EVENT, "connection state %d, event %d", at_state->ConState, ev->type); bcs = at_state->bcs; @@ -1600,11 +1601,11 @@ static void process_event(struct cardstate *cs, struct event_t *ev) if (ev->parameter != at_state->timer_index || !at_state->timer_active) { ev->type = RSP_NONE; /* old timeout */ - gig_dbg(DEBUG_ANY, "old timeout"); + gig_dbg(DEBUG_EVENT, "old timeout"); } else if (!at_state->waiting) - gig_dbg(DEBUG_ANY, "timeout occurred"); + gig_dbg(DEBUG_EVENT, "timeout occurred"); else - gig_dbg(DEBUG_ANY, "stopped waiting"); + gig_dbg(DEBUG_EVENT, "stopped waiting"); } spin_unlock_irqrestore(&cs->lock, flags); @@ -1712,11 +1713,11 @@ static void process_command_flags(struct cardstate *cs) cs->commands_pending = 0; if (cs->cur_at_seq) { - gig_dbg(DEBUG_CMD, "not searching scheduled commands: busy"); + gig_dbg(DEBUG_EVENT, "not searching scheduled commands: busy"); return; } - gig_dbg(DEBUG_CMD, "searching scheduled commands"); + gig_dbg(DEBUG_EVENT, "searching scheduled commands"); sequence = SEQ_NONE; @@ -1857,7 +1858,7 @@ static void process_command_flags(struct cardstate *cs) switch (cs->mode) { case M_UNIMODEM: cs->at_state.pending_commands |= PC_CIDMODE; - gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); + gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); cs->commands_pending = 1; return; #ifdef GIG_MAYINITONDIAL diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h index c9ccf7de2275..1875ab80b335 100644 --- a/drivers/isdn/gigaset/gigaset.h +++ b/drivers/isdn/gigaset/gigaset.h @@ -78,9 +78,10 @@ enum debuglevel { DEBUG_STREAM = 0x00040, /* application data stream I/O events */ DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */ DEBUG_LLDATA = 0x00100, /* sent/received LL data */ + DEBUG_EVENT = 0x00200, /* event processing */ DEBUG_DRIVER = 0x00400, /* driver structure */ DEBUG_HDLC = 0x00800, /* M10x HDLC processing */ - DEBUG_WRITE = 0x01000, /* M105 data write */ + DEBUG_CHANNEL = 0x01000, /* channel allocation/deallocation */ DEBUG_TRANSCMD = 0x02000, /* AT-COMMANDS+RESPONSES */ DEBUG_MCMD = 0x04000, /* COMMANDS THAT ARE SENT VERY OFTEN */ DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data @@ -785,8 +786,6 @@ static inline void gigaset_schedule_event(struct cardstate *cs) static inline void gigaset_bchannel_down(struct bc_state *bcs) { gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL); - - gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED"); gigaset_schedule_event(bcs->cs); } @@ -795,8 +794,6 @@ static inline void gigaset_bchannel_down(struct bc_state *bcs) static inline void gigaset_bchannel_up(struct bc_state *bcs) { gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL); - - gig_dbg(DEBUG_CMD, "scheduling BC_OPEN"); gigaset_schedule_event(bcs->cs); } diff --git a/drivers/isdn/gigaset/i4l.c b/drivers/isdn/gigaset/i4l.c index c129ee47a8fb..f0acb9dc9e33 100644 --- a/drivers/isdn/gigaset/i4l.c +++ b/drivers/isdn/gigaset/i4l.c @@ -216,7 +216,7 @@ static int command_from_LL(isdn_ctrl *cntrl) return -EINVAL; case ISDN_CMD_DIAL: - gig_dbg(DEBUG_ANY, + gig_dbg(DEBUG_CMD, "ISDN_CMD_DIAL (phone: %s, msn: %s, si1: %d, si2: %d)", cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn, cntrl->parm.setup.si1, cntrl->parm.setup.si2); @@ -304,11 +304,10 @@ static int command_from_LL(isdn_ctrl *cntrl) gigaset_free_channel(bcs); return -ENOMEM; } - - gig_dbg(DEBUG_CMD, "scheduling DIAL"); gigaset_schedule_event(cs); break; case ISDN_CMD_ACCEPTD: + gig_dbg(DEBUG_CMD, "ISDN_CMD_ACCEPTD"); if (ch >= cs->channels) { dev_err(cs->dev, "ISDN_CMD_ACCEPTD: invalid channel (%d)\n", ch); @@ -318,14 +317,11 @@ static int command_from_LL(isdn_ctrl *cntrl) if (!gigaset_add_event(cs, &bcs->at_state, EV_ACCEPT, NULL, 0, NULL)) return -ENOMEM; - - gig_dbg(DEBUG_CMD, "scheduling ACCEPT"); gigaset_schedule_event(cs); - break; - case ISDN_CMD_ACCEPTB: break; case ISDN_CMD_HANGUP: + gig_dbg(DEBUG_CMD, "ISDN_CMD_HANGUP"); if (ch >= cs->channels) { dev_err(cs->dev, "ISDN_CMD_HANGUP: invalid channel (%d)\n", ch); @@ -335,8 +331,6 @@ static int command_from_LL(isdn_ctrl *cntrl) if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) return -ENOMEM; - - gig_dbg(DEBUG_CMD, "scheduling HUP"); gigaset_schedule_event(cs); break; @@ -376,6 +370,7 @@ static int command_from_LL(isdn_ctrl *cntrl) } break; case ISDN_CMD_SETL3: /* Set L3 to given protocol */ + gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL3"); if (ch >= cs->channels) { dev_err(cs->dev, "ISDN_CMD_SETL3: invalid channel (%d)\n", ch); @@ -390,44 +385,9 @@ static int command_from_LL(isdn_ctrl *cntrl) } break; - case ISDN_CMD_PROCEED: - gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); - break; - case ISDN_CMD_ALERT: - gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); - if (cntrl->arg >= cs->channels) { - dev_err(cs->dev, - "ISDN_CMD_ALERT: invalid channel (%d)\n", - (int) cntrl->arg); - return -EINVAL; - } - break; - case ISDN_CMD_REDIR: - gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); - break; - case ISDN_CMD_PROT_IO: - gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO"); - break; - case ISDN_CMD_FAXCMD: - gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD"); - break; - case ISDN_CMD_GETL2: - gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2"); - break; - case ISDN_CMD_GETL3: - gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3"); - break; - case ISDN_CMD_GETEAZ: - gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ"); - break; - case ISDN_CMD_SETSIL: - gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL"); - break; - case ISDN_CMD_GETSIL: - gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL"); - break; + default: - dev_err(cs->dev, "unknown command %d from LL\n", + gig_dbg(DEBUG_CMD, "unknown command %d from LL", cntrl->command); return -EINVAL; } diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c index d2260b0055fc..a1bcbc21ff71 100644 --- a/drivers/isdn/gigaset/interface.c +++ b/drivers/isdn/gigaset/interface.c @@ -45,8 +45,6 @@ static int if_lock(struct cardstate *cs, int *arg) cs->waiting = 0; return -ENOMEM; } - - gig_dbg(DEBUG_CMD, "scheduling IF_LOCK"); gigaset_schedule_event(cs); wait_event(cs->waitqueue, !cs->waiting); @@ -81,8 +79,6 @@ static int if_version(struct cardstate *cs, unsigned arg[4]) cs->waiting = 0; return -ENOMEM; } - - gig_dbg(DEBUG_CMD, "scheduling IF_VER"); gigaset_schedule_event(cs); wait_event(cs->waitqueue, !cs->waiting); @@ -274,7 +270,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file, ? -EFAULT : 0; break; default: - gig_dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x", + gig_dbg(DEBUG_IF, "%s: arg not supported - 0x%04x", __func__, cmd); retval = -ENOIOCTLCMD; } @@ -455,7 +451,7 @@ static void if_throttle(struct tty_struct *tty) else if (!cs->open_count) dev_warn(cs->dev, "%s: device not opened\n", __func__); else - gig_dbg(DEBUG_ANY, "%s: not implemented\n", __func__); + gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); mutex_unlock(&cs->mutex); } @@ -479,7 +475,7 @@ static void if_unthrottle(struct tty_struct *tty) else if (!cs->open_count) dev_warn(cs->dev, "%s: device not opened\n", __func__); else - gig_dbg(DEBUG_ANY, "%s: not implemented\n", __func__); + gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__); mutex_unlock(&cs->mutex); } @@ -630,7 +626,7 @@ void gigaset_if_receive(struct cardstate *cs, spin_lock_irqsave(&cs->lock, flags); tty = cs->tty; if (tty == NULL) - gig_dbg(DEBUG_ANY, "receive on closed device"); + gig_dbg(DEBUG_IF, "receive on closed device"); else { tty_buffer_request_room(tty, len); tty_insert_flip_string(tty, buffer, len); diff --git a/drivers/isdn/gigaset/proc.c b/drivers/isdn/gigaset/proc.c index 758a00c1d2e2..b69f73a0668f 100644 --- a/drivers/isdn/gigaset/proc.c +++ b/drivers/isdn/gigaset/proc.c @@ -48,8 +48,6 @@ static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, mutex_unlock(&cs->mutex); return -ENOMEM; } - - gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE"); gigaset_schedule_event(cs); wait_event(cs->waitqueue, !cs->waiting); diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c index 3ab1daeb276b..9430a2bbb523 100644 --- a/drivers/isdn/gigaset/usb-gigaset.c +++ b/drivers/isdn/gigaset/usb-gigaset.c @@ -628,7 +628,7 @@ static int write_modem(struct cardstate *cs) struct usb_cardstate *ucs = cs->hw.usb; unsigned long flags; - gig_dbg(DEBUG_WRITE, "len: %d...", bcs->tx_skb->len); + gig_dbg(DEBUG_OUTPUT, "len: %d...", bcs->tx_skb->len); if (!bcs->tx_skb->len) { dev_kfree_skb_any(bcs->tx_skb); -- cgit v1.2.3 From 003bdb279bb6b212f25ea4e60e0164b6109d3704 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 22 Feb 2010 13:10:22 +0000 Subject: isdn: remove ishexdigit() in regard to isxdigit() Samll cleanup in drivers/isdn/gigaset/capi.c where own implementation of isxdigit() has been changed to kernel native one. Signed-off-by: Andy Shevchenko Acked-by: Tilman Schmidt Signed-off-by: David S. Miller --- drivers/isdn/gigaset/capi.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'drivers/isdn') diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c index 20ebcee9b0c0..6643d6533ccb 100644 --- a/drivers/isdn/gigaset/capi.c +++ b/drivers/isdn/gigaset/capi.c @@ -170,20 +170,6 @@ static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param, msgname, paramname); } -/* - * check for legal hex digit - */ -static inline int ishexdigit(char c) -{ - if (c >= '0' && c <= '9') - return 1; - if (c >= 'A' && c <= 'F') - return 1; - if (c >= 'a' && c <= 'f') - return 1; - return 0; -} - /* * convert hex to binary */ @@ -204,7 +190,7 @@ static int encode_ie(char *in, u8 *out, int maxlen) { int l = 0; while (*in) { - if (!ishexdigit(in[0]) || !ishexdigit(in[1]) || l >= maxlen) + if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen) return -1; out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]); in += 2; -- cgit v1.2.3