HID: hidraw, fix a NULL pointer dereference in hidraw_ioctl
[pandora-kernel.git] / drivers / telephony / ixj_pcmcia.c
1 #include "ixj-ver.h"
2
3 #include <linux/module.h>
4
5 #include <linux/init.h>
6 #include <linux/kernel.h>       /* printk() */
7 #include <linux/fs.h>           /* everything... */
8 #include <linux/errno.h>        /* error codes */
9 #include <linux/slab.h>
10
11 #include <pcmcia/cs.h>
12 #include <pcmcia/cistpl.h>
13 #include <pcmcia/ds.h>
14
15 #include "ixj.h"
16
17 /*
18  *      PCMCIA service support for Quicknet cards
19  */
20  
21
22 typedef struct ixj_info_t {
23         int ndev;
24         struct ixj *port;
25 } ixj_info_t;
26
27 static void ixj_detach(struct pcmcia_device *p_dev);
28 static int ixj_config(struct pcmcia_device * link);
29 static void ixj_cs_release(struct pcmcia_device * link);
30
31 static int ixj_probe(struct pcmcia_device *p_dev)
32 {
33         dev_dbg(&p_dev->dev, "ixj_attach()\n");
34         /* Create new ixj device */
35         p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
36         p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
37         p_dev->conf.IntType = INT_MEMORY_AND_IO;
38         p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
39         if (!p_dev->priv) {
40                 return -ENOMEM;
41         }
42
43         return ixj_config(p_dev);
44 }
45
46 static void ixj_detach(struct pcmcia_device *link)
47 {
48         dev_dbg(&link->dev, "ixj_detach\n");
49
50         ixj_cs_release(link);
51
52         kfree(link->priv);
53 }
54
55 static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
56 {
57         char *str;
58         int i, place;
59         dev_dbg(&link->dev, "ixj_get_serial\n");
60
61         str = link->prod_id[0];
62         if (!str)
63                 goto failed;
64         printk("%s", str);
65         str = link->prod_id[1];
66         if (!str)
67                 goto failed;
68         printk(" %s", str);
69         str = link->prod_id[2];
70         if (!str)
71                 goto failed;
72         place = 1;
73         for (i = strlen(str) - 1; i >= 0; i--) {
74                 switch (str[i]) {
75                 case '0':
76                 case '1':
77                 case '2':
78                 case '3':
79                 case '4':
80                 case '5':
81                 case '6':
82                 case '7':
83                 case '8':
84                 case '9':
85                         j->serial += (str[i] - 48) * place;
86                         break;
87                 case 'A':
88                 case 'B':
89                 case 'C':
90                 case 'D':
91                 case 'E':
92                 case 'F':
93                         j->serial += (str[i] - 55) * place;
94                         break;
95                 case 'a':
96                 case 'b':
97                 case 'c':
98                 case 'd':
99                 case 'e':
100                 case 'f':
101                         j->serial += (str[i] - 87) * place;
102                         break;
103                 }
104                 place = place * 0x10;
105         }
106         str = link->prod_id[3];
107         if (!str)
108                 goto failed;
109         printk(" version %s\n", str);
110 failed:
111         return;
112 }
113
114 static int ixj_config_check(struct pcmcia_device *p_dev,
115                             cistpl_cftable_entry_t *cfg,
116                             cistpl_cftable_entry_t *dflt,
117                             unsigned int vcc,
118                             void *priv_data)
119 {
120         if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
121                 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
122                 p_dev->resource[0]->start = io->win[0].base;
123                 p_dev->resource[0]->end = io->win[0].len;
124                 p_dev->io_lines = 3;
125                 if (io->nwin == 2) {
126                         p_dev->resource[1]->start = io->win[1].base;
127                         p_dev->resource[1]->end = io->win[1].len;
128                 }
129                 if (!pcmcia_request_io(p_dev))
130                         return 0;
131         }
132         return -ENODEV;
133 }
134
135 static int ixj_config(struct pcmcia_device * link)
136 {
137         IXJ *j;
138         ixj_info_t *info;
139         cistpl_cftable_entry_t dflt = { 0 };
140
141         info = link->priv;
142         dev_dbg(&link->dev, "ixj_config\n");
143
144         if (pcmcia_loop_config(link, ixj_config_check, &dflt))
145                 goto failed;
146
147         if (pcmcia_request_configuration(link, &link->conf))
148                 goto failed;
149
150         /*
151          *      Register the card with the core.
152          */
153         j = ixj_pcmcia_probe(link->resource[0]->start,
154                              link->resource[0]->start + 0x10);
155
156         info->ndev = 1;
157         ixj_get_serial(link, j);
158         return 0;
159
160 failed:
161         ixj_cs_release(link);
162         return -ENODEV;
163 }
164
165 static void ixj_cs_release(struct pcmcia_device *link)
166 {
167         ixj_info_t *info = link->priv;
168         dev_dbg(&link->dev, "ixj_cs_release\n");
169         info->ndev = 0;
170         pcmcia_disable_device(link);
171 }
172
173 static struct pcmcia_device_id ixj_ids[] = {
174         PCMCIA_DEVICE_MANF_CARD(0x0257, 0x0600),
175         PCMCIA_DEVICE_NULL
176 };
177 MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
178
179 static struct pcmcia_driver ixj_driver = {
180         .owner          = THIS_MODULE,
181         .drv            = {
182                 .name   = "ixj_cs",
183         },
184         .probe          = ixj_probe,
185         .remove         = ixj_detach,
186         .id_table       = ixj_ids,
187 };
188
189 static int __init ixj_pcmcia_init(void)
190 {
191         return pcmcia_register_driver(&ixj_driver);
192 }
193
194 static void ixj_pcmcia_exit(void)
195 {
196         pcmcia_unregister_driver(&ixj_driver);
197 }
198
199 module_init(ixj_pcmcia_init);
200 module_exit(ixj_pcmcia_exit);
201
202 MODULE_LICENSE("GPL");