Commit 3944ad6848e7ae15a3402372a2df4ae805008321
Committed by
David S. Miller
1 parent
735c65ce4a
Exists in
master
and in
39 other branches
drivers: isdn: remove custom strtoul()
In this case we safe to use strict_strtoul(). Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com> Cc: Karsten Keil <isdn@linux-pingi.de> Cc: netdev@vger.kernel.org Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 6 additions and 28 deletions Inline Diff
drivers/isdn/hysdn/hysdn_proclog.c
1 | /* $Id: hysdn_proclog.c,v 1.9.6.3 2001/09/23 22:24:54 kai Exp $ | 1 | /* $Id: hysdn_proclog.c,v 1.9.6.3 2001/09/23 22:24:54 kai Exp $ |
2 | * | 2 | * |
3 | * Linux driver for HYSDN cards, /proc/net filesystem log functions. | 3 | * Linux driver for HYSDN cards, /proc/net filesystem log functions. |
4 | * | 4 | * |
5 | * Author Werner Cornelius (werner@titro.de) for Hypercope GmbH | 5 | * Author Werner Cornelius (werner@titro.de) for Hypercope GmbH |
6 | * Copyright 1999 by Werner Cornelius (werner@titro.de) | 6 | * Copyright 1999 by Werner Cornelius (werner@titro.de) |
7 | * | 7 | * |
8 | * This software may be used and distributed according to the terms | 8 | * This software may be used and distributed according to the terms |
9 | * of the GNU General Public License, incorporated herein by reference. | 9 | * of the GNU General Public License, incorporated herein by reference. |
10 | * | 10 | * |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/poll.h> | 14 | #include <linux/poll.h> |
15 | #include <linux/proc_fs.h> | 15 | #include <linux/proc_fs.h> |
16 | #include <linux/sched.h> | 16 | #include <linux/sched.h> |
17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
18 | #include <linux/mutex.h> | 18 | #include <linux/mutex.h> |
19 | #include <linux/kernel.h> | ||
19 | 20 | ||
20 | #include "hysdn_defs.h" | 21 | #include "hysdn_defs.h" |
21 | 22 | ||
22 | /* the proc subdir for the interface is defined in the procconf module */ | 23 | /* the proc subdir for the interface is defined in the procconf module */ |
23 | extern struct proc_dir_entry *hysdn_proc_entry; | 24 | extern struct proc_dir_entry *hysdn_proc_entry; |
24 | 25 | ||
25 | static DEFINE_MUTEX(hysdn_log_mutex); | 26 | static DEFINE_MUTEX(hysdn_log_mutex); |
26 | static void put_log_buffer(hysdn_card * card, char *cp); | 27 | static void put_log_buffer(hysdn_card * card, char *cp); |
27 | 28 | ||
28 | /*************************************************/ | 29 | /*************************************************/ |
29 | /* structure keeping ascii log for device output */ | 30 | /* structure keeping ascii log for device output */ |
30 | /*************************************************/ | 31 | /*************************************************/ |
31 | struct log_data { | 32 | struct log_data { |
32 | struct log_data *next; | 33 | struct log_data *next; |
33 | unsigned long usage_cnt;/* number of files still to work */ | 34 | unsigned long usage_cnt;/* number of files still to work */ |
34 | void *proc_ctrl; /* pointer to own control procdata structure */ | 35 | void *proc_ctrl; /* pointer to own control procdata structure */ |
35 | char log_start[2]; /* log string start (final len aligned by size) */ | 36 | char log_start[2]; /* log string start (final len aligned by size) */ |
36 | }; | 37 | }; |
37 | 38 | ||
38 | /**********************************************/ | 39 | /**********************************************/ |
39 | /* structure holding proc entrys for one card */ | 40 | /* structure holding proc entrys for one card */ |
40 | /**********************************************/ | 41 | /**********************************************/ |
41 | struct procdata { | 42 | struct procdata { |
42 | struct proc_dir_entry *log; /* log entry */ | 43 | struct proc_dir_entry *log; /* log entry */ |
43 | char log_name[15]; /* log filename */ | 44 | char log_name[15]; /* log filename */ |
44 | struct log_data *log_head, *log_tail; /* head and tail for queue */ | 45 | struct log_data *log_head, *log_tail; /* head and tail for queue */ |
45 | int if_used; /* open count for interface */ | 46 | int if_used; /* open count for interface */ |
46 | int volatile del_lock; /* lock for delete operations */ | 47 | int volatile del_lock; /* lock for delete operations */ |
47 | unsigned char logtmp[LOG_MAX_LINELEN]; | 48 | unsigned char logtmp[LOG_MAX_LINELEN]; |
48 | wait_queue_head_t rd_queue; | 49 | wait_queue_head_t rd_queue; |
49 | }; | 50 | }; |
50 | 51 | ||
51 | 52 | ||
52 | /**********************************************/ | 53 | /**********************************************/ |
53 | /* log function for cards error log interface */ | 54 | /* log function for cards error log interface */ |
54 | /**********************************************/ | 55 | /**********************************************/ |
55 | void | 56 | void |
56 | hysdn_card_errlog(hysdn_card * card, tErrLogEntry * logp, int maxsize) | 57 | hysdn_card_errlog(hysdn_card * card, tErrLogEntry * logp, int maxsize) |
57 | { | 58 | { |
58 | char buf[ERRLOG_TEXT_SIZE + 40]; | 59 | char buf[ERRLOG_TEXT_SIZE + 40]; |
59 | 60 | ||
60 | sprintf(buf, "LOG 0x%08lX 0x%08lX : %s\n", logp->ulErrType, logp->ulErrSubtype, logp->ucText); | 61 | sprintf(buf, "LOG 0x%08lX 0x%08lX : %s\n", logp->ulErrType, logp->ulErrSubtype, logp->ucText); |
61 | put_log_buffer(card, buf); /* output the string */ | 62 | put_log_buffer(card, buf); /* output the string */ |
62 | } /* hysdn_card_errlog */ | 63 | } /* hysdn_card_errlog */ |
63 | 64 | ||
64 | /***************************************************/ | 65 | /***************************************************/ |
65 | /* Log function using format specifiers for output */ | 66 | /* Log function using format specifiers for output */ |
66 | /***************************************************/ | 67 | /***************************************************/ |
67 | void | 68 | void |
68 | hysdn_addlog(hysdn_card * card, char *fmt,...) | 69 | hysdn_addlog(hysdn_card * card, char *fmt,...) |
69 | { | 70 | { |
70 | struct procdata *pd = card->proclog; | 71 | struct procdata *pd = card->proclog; |
71 | char *cp; | 72 | char *cp; |
72 | va_list args; | 73 | va_list args; |
73 | 74 | ||
74 | if (!pd) | 75 | if (!pd) |
75 | return; /* log structure non existent */ | 76 | return; /* log structure non existent */ |
76 | 77 | ||
77 | cp = pd->logtmp; | 78 | cp = pd->logtmp; |
78 | cp += sprintf(cp, "HYSDN: card %d ", card->myid); | 79 | cp += sprintf(cp, "HYSDN: card %d ", card->myid); |
79 | 80 | ||
80 | va_start(args, fmt); | 81 | va_start(args, fmt); |
81 | cp += vsprintf(cp, fmt, args); | 82 | cp += vsprintf(cp, fmt, args); |
82 | va_end(args); | 83 | va_end(args); |
83 | *cp++ = '\n'; | 84 | *cp++ = '\n'; |
84 | *cp = 0; | 85 | *cp = 0; |
85 | 86 | ||
86 | if (card->debug_flags & DEB_OUT_SYSLOG) | 87 | if (card->debug_flags & DEB_OUT_SYSLOG) |
87 | printk(KERN_INFO "%s", pd->logtmp); | 88 | printk(KERN_INFO "%s", pd->logtmp); |
88 | else | 89 | else |
89 | put_log_buffer(card, pd->logtmp); | 90 | put_log_buffer(card, pd->logtmp); |
90 | 91 | ||
91 | } /* hysdn_addlog */ | 92 | } /* hysdn_addlog */ |
92 | 93 | ||
93 | /********************************************/ | 94 | /********************************************/ |
94 | /* put an log buffer into the log queue. */ | 95 | /* put an log buffer into the log queue. */ |
95 | /* This buffer will be kept until all files */ | 96 | /* This buffer will be kept until all files */ |
96 | /* opened for read got the contents. */ | 97 | /* opened for read got the contents. */ |
97 | /* Flushes buffers not longer in use. */ | 98 | /* Flushes buffers not longer in use. */ |
98 | /********************************************/ | 99 | /********************************************/ |
99 | static void | 100 | static void |
100 | put_log_buffer(hysdn_card * card, char *cp) | 101 | put_log_buffer(hysdn_card * card, char *cp) |
101 | { | 102 | { |
102 | struct log_data *ib; | 103 | struct log_data *ib; |
103 | struct procdata *pd = card->proclog; | 104 | struct procdata *pd = card->proclog; |
104 | int i; | 105 | int i; |
105 | unsigned long flags; | 106 | unsigned long flags; |
106 | 107 | ||
107 | if (!pd) | 108 | if (!pd) |
108 | return; | 109 | return; |
109 | if (!cp) | 110 | if (!cp) |
110 | return; | 111 | return; |
111 | if (!*cp) | 112 | if (!*cp) |
112 | return; | 113 | return; |
113 | if (pd->if_used <= 0) | 114 | if (pd->if_used <= 0) |
114 | return; /* no open file for read */ | 115 | return; /* no open file for read */ |
115 | 116 | ||
116 | if (!(ib = kmalloc(sizeof(struct log_data) + strlen(cp), GFP_ATOMIC))) | 117 | if (!(ib = kmalloc(sizeof(struct log_data) + strlen(cp), GFP_ATOMIC))) |
117 | return; /* no memory */ | 118 | return; /* no memory */ |
118 | strcpy(ib->log_start, cp); /* set output string */ | 119 | strcpy(ib->log_start, cp); /* set output string */ |
119 | ib->next = NULL; | 120 | ib->next = NULL; |
120 | ib->proc_ctrl = pd; /* point to own control structure */ | 121 | ib->proc_ctrl = pd; /* point to own control structure */ |
121 | spin_lock_irqsave(&card->hysdn_lock, flags); | 122 | spin_lock_irqsave(&card->hysdn_lock, flags); |
122 | ib->usage_cnt = pd->if_used; | 123 | ib->usage_cnt = pd->if_used; |
123 | if (!pd->log_head) | 124 | if (!pd->log_head) |
124 | pd->log_head = ib; /* new head */ | 125 | pd->log_head = ib; /* new head */ |
125 | else | 126 | else |
126 | pd->log_tail->next = ib; /* follows existing messages */ | 127 | pd->log_tail->next = ib; /* follows existing messages */ |
127 | pd->log_tail = ib; /* new tail */ | 128 | pd->log_tail = ib; /* new tail */ |
128 | i = pd->del_lock++; /* get lock state */ | 129 | i = pd->del_lock++; /* get lock state */ |
129 | spin_unlock_irqrestore(&card->hysdn_lock, flags); | 130 | spin_unlock_irqrestore(&card->hysdn_lock, flags); |
130 | 131 | ||
131 | /* delete old entrys */ | 132 | /* delete old entrys */ |
132 | if (!i) | 133 | if (!i) |
133 | while (pd->log_head->next) { | 134 | while (pd->log_head->next) { |
134 | if ((pd->log_head->usage_cnt <= 0) && | 135 | if ((pd->log_head->usage_cnt <= 0) && |
135 | (pd->log_head->next->usage_cnt <= 0)) { | 136 | (pd->log_head->next->usage_cnt <= 0)) { |
136 | ib = pd->log_head; | 137 | ib = pd->log_head; |
137 | pd->log_head = pd->log_head->next; | 138 | pd->log_head = pd->log_head->next; |
138 | kfree(ib); | 139 | kfree(ib); |
139 | } else | 140 | } else |
140 | break; | 141 | break; |
141 | } /* pd->log_head->next */ | 142 | } /* pd->log_head->next */ |
142 | pd->del_lock--; /* release lock level */ | 143 | pd->del_lock--; /* release lock level */ |
143 | wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */ | 144 | wake_up_interruptible(&(pd->rd_queue)); /* announce new entry */ |
144 | } /* put_log_buffer */ | 145 | } /* put_log_buffer */ |
145 | 146 | ||
146 | 147 | ||
147 | /******************************/ | 148 | /******************************/ |
148 | /* file operations and tables */ | 149 | /* file operations and tables */ |
149 | /******************************/ | 150 | /******************************/ |
150 | 151 | ||
151 | /****************************************/ | 152 | /****************************************/ |
152 | /* write log file -> set log level bits */ | 153 | /* write log file -> set log level bits */ |
153 | /****************************************/ | 154 | /****************************************/ |
154 | static ssize_t | 155 | static ssize_t |
155 | hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t * off) | 156 | hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t * off) |
156 | { | 157 | { |
157 | unsigned long u = 0; | 158 | unsigned long u = 0; |
158 | int found = 0; | 159 | int rc; |
159 | unsigned char *cp, valbuf[128]; | 160 | unsigned char valbuf[128]; |
160 | long base = 10; | ||
161 | hysdn_card *card = file->private_data; | 161 | hysdn_card *card = file->private_data; |
162 | 162 | ||
163 | if (count > (sizeof(valbuf) - 1)) | 163 | if (count > (sizeof(valbuf) - 1)) |
164 | count = sizeof(valbuf) - 1; /* limit length */ | 164 | count = sizeof(valbuf) - 1; /* limit length */ |
165 | if (copy_from_user(valbuf, buf, count)) | 165 | if (copy_from_user(valbuf, buf, count)) |
166 | return (-EFAULT); /* copy failed */ | 166 | return (-EFAULT); /* copy failed */ |
167 | 167 | ||
168 | valbuf[count] = 0; /* terminating 0 */ | 168 | valbuf[count] = 0; /* terminating 0 */ |
169 | cp = valbuf; | ||
170 | if ((count > 2) && (valbuf[0] == '0') && (valbuf[1] == 'x')) { | ||
171 | cp += 2; /* pointer after hex modifier */ | ||
172 | base = 16; | ||
173 | } | ||
174 | /* scan the input for debug flags */ | ||
175 | while (*cp) { | ||
176 | if ((*cp >= '0') && (*cp <= '9')) { | ||
177 | found = 1; | ||
178 | u *= base; /* adjust to next digit */ | ||
179 | u += *cp++ - '0'; | ||
180 | continue; | ||
181 | } | ||
182 | if (base != 16) | ||
183 | break; /* end of number */ | ||
184 | 169 | ||
185 | if ((*cp >= 'a') && (*cp <= 'f')) { | 170 | rc = strict_strtoul(valbuf, 0, &u); |
186 | found = 1; | ||
187 | u *= base; /* adjust to next digit */ | ||
188 | u += *cp++ - 'a' + 10; | ||
189 | continue; | ||
190 | } | ||
191 | break; /* terminated */ | ||
192 | } | ||
193 | 171 | ||
194 | if (found) { | 172 | if (rc == 0) { |
195 | card->debug_flags = u; /* remember debug flags */ | 173 | card->debug_flags = u; /* remember debug flags */ |
196 | hysdn_addlog(card, "debug set to 0x%lx", card->debug_flags); | 174 | hysdn_addlog(card, "debug set to 0x%lx", card->debug_flags); |
197 | } | 175 | } |
198 | return (count); | 176 | return (count); |
199 | } /* hysdn_log_write */ | 177 | } /* hysdn_log_write */ |
200 | 178 | ||
201 | /******************/ | 179 | /******************/ |
202 | /* read log file */ | 180 | /* read log file */ |
203 | /******************/ | 181 | /******************/ |
204 | static ssize_t | 182 | static ssize_t |
205 | hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t * off) | 183 | hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t * off) |
206 | { | 184 | { |
207 | struct log_data *inf; | 185 | struct log_data *inf; |
208 | int len; | 186 | int len; |
209 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); | 187 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
210 | struct procdata *pd = NULL; | 188 | struct procdata *pd = NULL; |
211 | hysdn_card *card; | 189 | hysdn_card *card; |
212 | 190 | ||
213 | if (!*((struct log_data **) file->private_data)) { | 191 | if (!*((struct log_data **) file->private_data)) { |
214 | if (file->f_flags & O_NONBLOCK) | 192 | if (file->f_flags & O_NONBLOCK) |
215 | return (-EAGAIN); | 193 | return (-EAGAIN); |
216 | 194 | ||
217 | /* sorry, but we need to search the card */ | 195 | /* sorry, but we need to search the card */ |
218 | card = card_root; | 196 | card = card_root; |
219 | while (card) { | 197 | while (card) { |
220 | pd = card->proclog; | 198 | pd = card->proclog; |
221 | if (pd->log == pde) | 199 | if (pd->log == pde) |
222 | break; | 200 | break; |
223 | card = card->next; /* search next entry */ | 201 | card = card->next; /* search next entry */ |
224 | } | 202 | } |
225 | if (card) | 203 | if (card) |
226 | interruptible_sleep_on(&(pd->rd_queue)); | 204 | interruptible_sleep_on(&(pd->rd_queue)); |
227 | else | 205 | else |
228 | return (-EAGAIN); | 206 | return (-EAGAIN); |
229 | 207 | ||
230 | } | 208 | } |
231 | if (!(inf = *((struct log_data **) file->private_data))) | 209 | if (!(inf = *((struct log_data **) file->private_data))) |
232 | return (0); | 210 | return (0); |
233 | 211 | ||
234 | inf->usage_cnt--; /* new usage count */ | 212 | inf->usage_cnt--; /* new usage count */ |
235 | file->private_data = &inf->next; /* next structure */ | 213 | file->private_data = &inf->next; /* next structure */ |
236 | if ((len = strlen(inf->log_start)) <= count) { | 214 | if ((len = strlen(inf->log_start)) <= count) { |
237 | if (copy_to_user(buf, inf->log_start, len)) | 215 | if (copy_to_user(buf, inf->log_start, len)) |
238 | return -EFAULT; | 216 | return -EFAULT; |
239 | *off += len; | 217 | *off += len; |
240 | return (len); | 218 | return (len); |
241 | } | 219 | } |
242 | return (0); | 220 | return (0); |
243 | } /* hysdn_log_read */ | 221 | } /* hysdn_log_read */ |
244 | 222 | ||
245 | /******************/ | 223 | /******************/ |
246 | /* open log file */ | 224 | /* open log file */ |
247 | /******************/ | 225 | /******************/ |
248 | static int | 226 | static int |
249 | hysdn_log_open(struct inode *ino, struct file *filep) | 227 | hysdn_log_open(struct inode *ino, struct file *filep) |
250 | { | 228 | { |
251 | hysdn_card *card; | 229 | hysdn_card *card; |
252 | struct procdata *pd = NULL; | 230 | struct procdata *pd = NULL; |
253 | unsigned long flags; | 231 | unsigned long flags; |
254 | 232 | ||
255 | mutex_lock(&hysdn_log_mutex); | 233 | mutex_lock(&hysdn_log_mutex); |
256 | card = card_root; | 234 | card = card_root; |
257 | while (card) { | 235 | while (card) { |
258 | pd = card->proclog; | 236 | pd = card->proclog; |
259 | if (pd->log == PDE(ino)) | 237 | if (pd->log == PDE(ino)) |
260 | break; | 238 | break; |
261 | card = card->next; /* search next entry */ | 239 | card = card->next; /* search next entry */ |
262 | } | 240 | } |
263 | if (!card) { | 241 | if (!card) { |
264 | mutex_unlock(&hysdn_log_mutex); | 242 | mutex_unlock(&hysdn_log_mutex); |
265 | return (-ENODEV); /* device is unknown/invalid */ | 243 | return (-ENODEV); /* device is unknown/invalid */ |
266 | } | 244 | } |
267 | filep->private_data = card; /* remember our own card */ | 245 | filep->private_data = card; /* remember our own card */ |
268 | 246 | ||
269 | if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { | 247 | if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { |
270 | /* write only access -> write log level only */ | 248 | /* write only access -> write log level only */ |
271 | } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { | 249 | } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { |
272 | 250 | ||
273 | /* read access -> log/debug read */ | 251 | /* read access -> log/debug read */ |
274 | spin_lock_irqsave(&card->hysdn_lock, flags); | 252 | spin_lock_irqsave(&card->hysdn_lock, flags); |
275 | pd->if_used++; | 253 | pd->if_used++; |
276 | if (pd->log_head) | 254 | if (pd->log_head) |
277 | filep->private_data = &pd->log_tail->next; | 255 | filep->private_data = &pd->log_tail->next; |
278 | else | 256 | else |
279 | filep->private_data = &pd->log_head; | 257 | filep->private_data = &pd->log_head; |
280 | spin_unlock_irqrestore(&card->hysdn_lock, flags); | 258 | spin_unlock_irqrestore(&card->hysdn_lock, flags); |
281 | } else { /* simultaneous read/write access forbidden ! */ | 259 | } else { /* simultaneous read/write access forbidden ! */ |
282 | mutex_unlock(&hysdn_log_mutex); | 260 | mutex_unlock(&hysdn_log_mutex); |
283 | return (-EPERM); /* no permission this time */ | 261 | return (-EPERM); /* no permission this time */ |
284 | } | 262 | } |
285 | mutex_unlock(&hysdn_log_mutex); | 263 | mutex_unlock(&hysdn_log_mutex); |
286 | return nonseekable_open(ino, filep); | 264 | return nonseekable_open(ino, filep); |
287 | } /* hysdn_log_open */ | 265 | } /* hysdn_log_open */ |
288 | 266 | ||
289 | /*******************************************************************************/ | 267 | /*******************************************************************************/ |
290 | /* close a cardlog file. If the file has been opened for exclusive write it is */ | 268 | /* close a cardlog file. If the file has been opened for exclusive write it is */ |
291 | /* assumed as pof data input and the pof loader is noticed about. */ | 269 | /* assumed as pof data input and the pof loader is noticed about. */ |
292 | /* Otherwise file is handled as log output. In this case the interface usage */ | 270 | /* Otherwise file is handled as log output. In this case the interface usage */ |
293 | /* count is decremented and all buffers are noticed of closing. If this file */ | 271 | /* count is decremented and all buffers are noticed of closing. If this file */ |
294 | /* was the last one to be closed, all buffers are freed. */ | 272 | /* was the last one to be closed, all buffers are freed. */ |
295 | /*******************************************************************************/ | 273 | /*******************************************************************************/ |
296 | static int | 274 | static int |
297 | hysdn_log_close(struct inode *ino, struct file *filep) | 275 | hysdn_log_close(struct inode *ino, struct file *filep) |
298 | { | 276 | { |
299 | struct log_data *inf; | 277 | struct log_data *inf; |
300 | struct procdata *pd; | 278 | struct procdata *pd; |
301 | hysdn_card *card; | 279 | hysdn_card *card; |
302 | int retval = 0; | 280 | int retval = 0; |
303 | 281 | ||
304 | mutex_lock(&hysdn_log_mutex); | 282 | mutex_lock(&hysdn_log_mutex); |
305 | if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { | 283 | if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { |
306 | /* write only access -> write debug level written */ | 284 | /* write only access -> write debug level written */ |
307 | retval = 0; /* success */ | 285 | retval = 0; /* success */ |
308 | } else { | 286 | } else { |
309 | /* read access -> log/debug read, mark one further file as closed */ | 287 | /* read access -> log/debug read, mark one further file as closed */ |
310 | 288 | ||
311 | pd = NULL; | 289 | pd = NULL; |
312 | inf = *((struct log_data **) filep->private_data); /* get first log entry */ | 290 | inf = *((struct log_data **) filep->private_data); /* get first log entry */ |
313 | if (inf) | 291 | if (inf) |
314 | pd = (struct procdata *) inf->proc_ctrl; /* still entries there */ | 292 | pd = (struct procdata *) inf->proc_ctrl; /* still entries there */ |
315 | else { | 293 | else { |
316 | /* no info available -> search card */ | 294 | /* no info available -> search card */ |
317 | card = card_root; | 295 | card = card_root; |
318 | while (card) { | 296 | while (card) { |
319 | pd = card->proclog; | 297 | pd = card->proclog; |
320 | if (pd->log == PDE(ino)) | 298 | if (pd->log == PDE(ino)) |
321 | break; | 299 | break; |
322 | card = card->next; /* search next entry */ | 300 | card = card->next; /* search next entry */ |
323 | } | 301 | } |
324 | if (card) | 302 | if (card) |
325 | pd = card->proclog; /* pointer to procfs log */ | 303 | pd = card->proclog; /* pointer to procfs log */ |
326 | } | 304 | } |
327 | if (pd) | 305 | if (pd) |
328 | pd->if_used--; /* decrement interface usage count by one */ | 306 | pd->if_used--; /* decrement interface usage count by one */ |
329 | 307 | ||
330 | while (inf) { | 308 | while (inf) { |
331 | inf->usage_cnt--; /* decrement usage count for buffers */ | 309 | inf->usage_cnt--; /* decrement usage count for buffers */ |
332 | inf = inf->next; | 310 | inf = inf->next; |
333 | } | 311 | } |
334 | 312 | ||
335 | if (pd) | 313 | if (pd) |
336 | if (pd->if_used <= 0) /* delete buffers if last file closed */ | 314 | if (pd->if_used <= 0) /* delete buffers if last file closed */ |
337 | while (pd->log_head) { | 315 | while (pd->log_head) { |
338 | inf = pd->log_head; | 316 | inf = pd->log_head; |
339 | pd->log_head = pd->log_head->next; | 317 | pd->log_head = pd->log_head->next; |
340 | kfree(inf); | 318 | kfree(inf); |
341 | } | 319 | } |
342 | } /* read access */ | 320 | } /* read access */ |
343 | mutex_unlock(&hysdn_log_mutex); | 321 | mutex_unlock(&hysdn_log_mutex); |
344 | 322 | ||
345 | return (retval); | 323 | return (retval); |
346 | } /* hysdn_log_close */ | 324 | } /* hysdn_log_close */ |
347 | 325 | ||
348 | /*************************************************/ | 326 | /*************************************************/ |
349 | /* select/poll routine to be able using select() */ | 327 | /* select/poll routine to be able using select() */ |
350 | /*************************************************/ | 328 | /*************************************************/ |
351 | static unsigned int | 329 | static unsigned int |
352 | hysdn_log_poll(struct file *file, poll_table * wait) | 330 | hysdn_log_poll(struct file *file, poll_table * wait) |
353 | { | 331 | { |
354 | unsigned int mask = 0; | 332 | unsigned int mask = 0; |
355 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); | 333 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
356 | hysdn_card *card; | 334 | hysdn_card *card; |
357 | struct procdata *pd = NULL; | 335 | struct procdata *pd = NULL; |
358 | 336 | ||
359 | if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) | 337 | if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) |
360 | return (mask); /* no polling for write supported */ | 338 | return (mask); /* no polling for write supported */ |
361 | 339 | ||
362 | /* we need to search the card */ | 340 | /* we need to search the card */ |
363 | card = card_root; | 341 | card = card_root; |
364 | while (card) { | 342 | while (card) { |
365 | pd = card->proclog; | 343 | pd = card->proclog; |
366 | if (pd->log == pde) | 344 | if (pd->log == pde) |
367 | break; | 345 | break; |
368 | card = card->next; /* search next entry */ | 346 | card = card->next; /* search next entry */ |
369 | } | 347 | } |
370 | if (!card) | 348 | if (!card) |
371 | return (mask); /* card not found */ | 349 | return (mask); /* card not found */ |
372 | 350 | ||
373 | poll_wait(file, &(pd->rd_queue), wait); | 351 | poll_wait(file, &(pd->rd_queue), wait); |
374 | 352 | ||
375 | if (*((struct log_data **) file->private_data)) | 353 | if (*((struct log_data **) file->private_data)) |
376 | mask |= POLLIN | POLLRDNORM; | 354 | mask |= POLLIN | POLLRDNORM; |
377 | 355 | ||
378 | return mask; | 356 | return mask; |
379 | } /* hysdn_log_poll */ | 357 | } /* hysdn_log_poll */ |
380 | 358 | ||
381 | /**************************************************/ | 359 | /**************************************************/ |
382 | /* table for log filesystem functions defined above. */ | 360 | /* table for log filesystem functions defined above. */ |
383 | /**************************************************/ | 361 | /**************************************************/ |
384 | static const struct file_operations log_fops = | 362 | static const struct file_operations log_fops = |
385 | { | 363 | { |
386 | .owner = THIS_MODULE, | 364 | .owner = THIS_MODULE, |
387 | .llseek = no_llseek, | 365 | .llseek = no_llseek, |
388 | .read = hysdn_log_read, | 366 | .read = hysdn_log_read, |
389 | .write = hysdn_log_write, | 367 | .write = hysdn_log_write, |
390 | .poll = hysdn_log_poll, | 368 | .poll = hysdn_log_poll, |
391 | .open = hysdn_log_open, | 369 | .open = hysdn_log_open, |
392 | .release = hysdn_log_close, | 370 | .release = hysdn_log_close, |
393 | }; | 371 | }; |
394 | 372 | ||
395 | 373 | ||
396 | /***********************************************************************************/ | 374 | /***********************************************************************************/ |
397 | /* hysdn_proclog_init is called when the module is loaded after creating the cards */ | 375 | /* hysdn_proclog_init is called when the module is loaded after creating the cards */ |
398 | /* conf files. */ | 376 | /* conf files. */ |
399 | /***********************************************************************************/ | 377 | /***********************************************************************************/ |
400 | int | 378 | int |
401 | hysdn_proclog_init(hysdn_card * card) | 379 | hysdn_proclog_init(hysdn_card * card) |
402 | { | 380 | { |
403 | struct procdata *pd; | 381 | struct procdata *pd; |
404 | 382 | ||
405 | /* create a cardlog proc entry */ | 383 | /* create a cardlog proc entry */ |
406 | 384 | ||
407 | if ((pd = kzalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) { | 385 | if ((pd = kzalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) { |
408 | sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid); | 386 | sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid); |
409 | pd->log = proc_create(pd->log_name, | 387 | pd->log = proc_create(pd->log_name, |
410 | S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry, | 388 | S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry, |
411 | &log_fops); | 389 | &log_fops); |
412 | 390 | ||
413 | init_waitqueue_head(&(pd->rd_queue)); | 391 | init_waitqueue_head(&(pd->rd_queue)); |
414 | 392 | ||
415 | card->proclog = (void *) pd; /* remember procfs structure */ | 393 | card->proclog = (void *) pd; /* remember procfs structure */ |
416 | } | 394 | } |
417 | return (0); | 395 | return (0); |
418 | } /* hysdn_proclog_init */ | 396 | } /* hysdn_proclog_init */ |
419 | 397 | ||
420 | /************************************************************************************/ | 398 | /************************************************************************************/ |
421 | /* hysdn_proclog_release is called when the module is unloaded and before the cards */ | 399 | /* hysdn_proclog_release is called when the module is unloaded and before the cards */ |
422 | /* conf file is released */ | 400 | /* conf file is released */ |
423 | /* The module counter is assumed to be 0 ! */ | 401 | /* The module counter is assumed to be 0 ! */ |
424 | /************************************************************************************/ | 402 | /************************************************************************************/ |
425 | void | 403 | void |
426 | hysdn_proclog_release(hysdn_card * card) | 404 | hysdn_proclog_release(hysdn_card * card) |
427 | { | 405 | { |
428 | struct procdata *pd; | 406 | struct procdata *pd; |
429 | 407 | ||
430 | if ((pd = (struct procdata *) card->proclog) != NULL) { | 408 | if ((pd = (struct procdata *) card->proclog) != NULL) { |
431 | if (pd->log) | 409 | if (pd->log) |
432 | remove_proc_entry(pd->log_name, hysdn_proc_entry); | 410 | remove_proc_entry(pd->log_name, hysdn_proc_entry); |
433 | kfree(pd); /* release memory */ | 411 | kfree(pd); /* release memory */ |
434 | card->proclog = NULL; | 412 | card->proclog = NULL; |
435 | } | 413 | } |
436 | } /* hysdn_proclog_release */ | 414 | } /* hysdn_proclog_release */ |