diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2013-03-28 18:56:21 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-04-09 14:13:04 -0400 |
commit | 4d8e8d21de89ff9d86b83182f723129533aacaa9 (patch) | |
tree | 6fbd43be309f8901fdd2c011e4b4c6a3980b340e /drivers/isdn/hysdn | |
parent | 03b642a7019a8ec28a450fd4c55f3048ce320f6b (diff) |
hysdn: stash pointer to card into proc_dir_entry->data
no need to search later - we know the card when we are
creating procfs entries
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'drivers/isdn/hysdn')
-rw-r--r-- | drivers/isdn/hysdn/hysdn_procconf.c | 32 | ||||
-rw-r--r-- | drivers/isdn/hysdn/hysdn_proclog.c | 71 |
2 files changed, 18 insertions, 85 deletions
diff --git a/drivers/isdn/hysdn/hysdn_procconf.c b/drivers/isdn/hysdn/hysdn_procconf.c index 8023d2510fba..dc88bcb25029 100644 --- a/drivers/isdn/hysdn/hysdn_procconf.c +++ b/drivers/isdn/hysdn/hysdn_procconf.c | |||
@@ -229,23 +229,12 @@ static int | |||
229 | hysdn_conf_open(struct inode *ino, struct file *filep) | 229 | hysdn_conf_open(struct inode *ino, struct file *filep) |
230 | { | 230 | { |
231 | hysdn_card *card; | 231 | hysdn_card *card; |
232 | struct proc_dir_entry *pd; | ||
233 | struct conf_writedata *cnf; | 232 | struct conf_writedata *cnf; |
234 | char *cp, *tmp; | 233 | char *cp, *tmp; |
235 | 234 | ||
236 | /* now search the addressed card */ | 235 | /* now search the addressed card */ |
237 | mutex_lock(&hysdn_conf_mutex); | 236 | mutex_lock(&hysdn_conf_mutex); |
238 | card = card_root; | 237 | card = PDE(ino)->data; |
239 | while (card) { | ||
240 | pd = card->procconf; | ||
241 | if (pd == PDE(ino)) | ||
242 | break; | ||
243 | card = card->next; /* search next entry */ | ||
244 | } | ||
245 | if (!card) { | ||
246 | mutex_unlock(&hysdn_conf_mutex); | ||
247 | return (-ENODEV); /* device is unknown/invalid */ | ||
248 | } | ||
249 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) | 238 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) |
250 | hysdn_addlog(card, "config open for uid=%d gid=%d mode=0x%x", | 239 | hysdn_addlog(card, "config open for uid=%d gid=%d mode=0x%x", |
251 | filep->f_cred->fsuid, filep->f_cred->fsgid, | 240 | filep->f_cred->fsuid, filep->f_cred->fsgid, |
@@ -317,21 +306,9 @@ hysdn_conf_close(struct inode *ino, struct file *filep) | |||
317 | hysdn_card *card; | 306 | hysdn_card *card; |
318 | struct conf_writedata *cnf; | 307 | struct conf_writedata *cnf; |
319 | int retval = 0; | 308 | int retval = 0; |
320 | struct proc_dir_entry *pd; | ||
321 | 309 | ||
322 | mutex_lock(&hysdn_conf_mutex); | 310 | mutex_lock(&hysdn_conf_mutex); |
323 | /* search the addressed card */ | 311 | card = PDE(ino)->data; |
324 | card = card_root; | ||
325 | while (card) { | ||
326 | pd = card->procconf; | ||
327 | if (pd == PDE(ino)) | ||
328 | break; | ||
329 | card = card->next; /* search next entry */ | ||
330 | } | ||
331 | if (!card) { | ||
332 | mutex_unlock(&hysdn_conf_mutex); | ||
333 | return (-ENODEV); /* device is unknown/invalid */ | ||
334 | } | ||
335 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) | 312 | if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL)) |
336 | hysdn_addlog(card, "config close for uid=%d gid=%d mode=0x%x", | 313 | hysdn_addlog(card, "config close for uid=%d gid=%d mode=0x%x", |
337 | filep->f_cred->fsuid, filep->f_cred->fsgid, | 314 | filep->f_cred->fsuid, filep->f_cred->fsgid, |
@@ -394,10 +371,11 @@ hysdn_procconf_init(void) | |||
394 | while (card) { | 371 | while (card) { |
395 | 372 | ||
396 | sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid); | 373 | sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid); |
397 | if ((card->procconf = (void *) proc_create(conf_name, | 374 | if ((card->procconf = (void *) proc_create_data(conf_name, |
398 | S_IFREG | S_IRUGO | S_IWUSR, | 375 | S_IFREG | S_IRUGO | S_IWUSR, |
399 | hysdn_proc_entry, | 376 | hysdn_proc_entry, |
400 | &conf_fops)) != NULL) { | 377 | &conf_fops, |
378 | card)) != NULL) { | ||
401 | hysdn_proclog_init(card); /* init the log file entry */ | 379 | hysdn_proclog_init(card); /* init the log file entry */ |
402 | } | 380 | } |
403 | card = card->next; /* next entry */ | 381 | card = card->next; /* next entry */ |
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c index 9a3ce93665c5..22f0e4ef1fb1 100644 --- a/drivers/isdn/hysdn/hysdn_proclog.c +++ b/drivers/isdn/hysdn/hysdn_proclog.c | |||
@@ -173,27 +173,14 @@ hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t *off) | |||
173 | { | 173 | { |
174 | struct log_data *inf; | 174 | struct log_data *inf; |
175 | int len; | 175 | int len; |
176 | struct proc_dir_entry *pde = PDE(file_inode(file)); | 176 | hysdn_card *card = PDE(file_inode(file))->data; |
177 | struct procdata *pd = NULL; | ||
178 | hysdn_card *card; | ||
179 | 177 | ||
180 | if (!*((struct log_data **) file->private_data)) { | 178 | if (!*((struct log_data **) file->private_data)) { |
179 | struct procdata *pd = card->proclog; | ||
181 | if (file->f_flags & O_NONBLOCK) | 180 | if (file->f_flags & O_NONBLOCK) |
182 | return (-EAGAIN); | 181 | return (-EAGAIN); |
183 | 182 | ||
184 | /* sorry, but we need to search the card */ | 183 | interruptible_sleep_on(&(pd->rd_queue)); |
185 | card = card_root; | ||
186 | while (card) { | ||
187 | pd = card->proclog; | ||
188 | if (pd->log == pde) | ||
189 | break; | ||
190 | card = card->next; /* search next entry */ | ||
191 | } | ||
192 | if (card) | ||
193 | interruptible_sleep_on(&(pd->rd_queue)); | ||
194 | else | ||
195 | return (-EAGAIN); | ||
196 | |||
197 | } | 184 | } |
198 | if (!(inf = *((struct log_data **) file->private_data))) | 185 | if (!(inf = *((struct log_data **) file->private_data))) |
199 | return (0); | 186 | return (0); |
@@ -215,27 +202,15 @@ hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t *off) | |||
215 | static int | 202 | static int |
216 | hysdn_log_open(struct inode *ino, struct file *filep) | 203 | hysdn_log_open(struct inode *ino, struct file *filep) |
217 | { | 204 | { |
218 | hysdn_card *card; | 205 | hysdn_card *card = PDE(ino)->data; |
219 | struct procdata *pd = NULL; | ||
220 | unsigned long flags; | ||
221 | 206 | ||
222 | mutex_lock(&hysdn_log_mutex); | 207 | mutex_lock(&hysdn_log_mutex); |
223 | card = card_root; | ||
224 | while (card) { | ||
225 | pd = card->proclog; | ||
226 | if (pd->log == PDE(ino)) | ||
227 | break; | ||
228 | card = card->next; /* search next entry */ | ||
229 | } | ||
230 | if (!card) { | ||
231 | mutex_unlock(&hysdn_log_mutex); | ||
232 | return (-ENODEV); /* device is unknown/invalid */ | ||
233 | } | ||
234 | filep->private_data = card; /* remember our own card */ | ||
235 | |||
236 | if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { | 208 | if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { |
237 | /* write only access -> write log level only */ | 209 | /* write only access -> write log level only */ |
210 | filep->private_data = card; /* remember our own card */ | ||
238 | } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { | 211 | } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) { |
212 | struct procdata *pd = card->proclog; | ||
213 | unsigned long flags; | ||
239 | 214 | ||
240 | /* read access -> log/debug read */ | 215 | /* read access -> log/debug read */ |
241 | spin_lock_irqsave(&card->hysdn_lock, flags); | 216 | spin_lock_irqsave(&card->hysdn_lock, flags); |
@@ -275,21 +250,13 @@ hysdn_log_close(struct inode *ino, struct file *filep) | |||
275 | } else { | 250 | } else { |
276 | /* read access -> log/debug read, mark one further file as closed */ | 251 | /* read access -> log/debug read, mark one further file as closed */ |
277 | 252 | ||
278 | pd = NULL; | ||
279 | inf = *((struct log_data **) filep->private_data); /* get first log entry */ | 253 | inf = *((struct log_data **) filep->private_data); /* get first log entry */ |
280 | if (inf) | 254 | if (inf) |
281 | pd = (struct procdata *) inf->proc_ctrl; /* still entries there */ | 255 | pd = (struct procdata *) inf->proc_ctrl; /* still entries there */ |
282 | else { | 256 | else { |
283 | /* no info available -> search card */ | 257 | /* no info available -> search card */ |
284 | card = card_root; | 258 | card = PDE(file_inode(filep))->data; |
285 | while (card) { | 259 | pd = card->proclog; /* pointer to procfs log */ |
286 | pd = card->proclog; | ||
287 | if (pd->log == PDE(ino)) | ||
288 | break; | ||
289 | card = card->next; /* search next entry */ | ||
290 | } | ||
291 | if (card) | ||
292 | pd = card->proclog; /* pointer to procfs log */ | ||
293 | } | 260 | } |
294 | if (pd) | 261 | if (pd) |
295 | pd->if_used--; /* decrement interface usage count by one */ | 262 | pd->if_used--; /* decrement interface usage count by one */ |
@@ -319,24 +286,12 @@ static unsigned int | |||
319 | hysdn_log_poll(struct file *file, poll_table *wait) | 286 | hysdn_log_poll(struct file *file, poll_table *wait) |
320 | { | 287 | { |
321 | unsigned int mask = 0; | 288 | unsigned int mask = 0; |
322 | struct proc_dir_entry *pde = PDE(file_inode(file)); | 289 | hysdn_card *card = PDE(file_inode(file))->data; |
323 | hysdn_card *card; | 290 | struct procdata *pd = card->proclog; |
324 | struct procdata *pd = NULL; | ||
325 | 291 | ||
326 | if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) | 292 | if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) |
327 | return (mask); /* no polling for write supported */ | 293 | return (mask); /* no polling for write supported */ |
328 | 294 | ||
329 | /* we need to search the card */ | ||
330 | card = card_root; | ||
331 | while (card) { | ||
332 | pd = card->proclog; | ||
333 | if (pd->log == pde) | ||
334 | break; | ||
335 | card = card->next; /* search next entry */ | ||
336 | } | ||
337 | if (!card) | ||
338 | return (mask); /* card not found */ | ||
339 | |||
340 | poll_wait(file, &(pd->rd_queue), wait); | 295 | poll_wait(file, &(pd->rd_queue), wait); |
341 | 296 | ||
342 | if (*((struct log_data **) file->private_data)) | 297 | if (*((struct log_data **) file->private_data)) |
@@ -373,9 +328,9 @@ hysdn_proclog_init(hysdn_card *card) | |||
373 | 328 | ||
374 | if ((pd = kzalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) { | 329 | if ((pd = kzalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) { |
375 | sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid); | 330 | sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid); |
376 | pd->log = proc_create(pd->log_name, | 331 | pd->log = proc_create_data(pd->log_name, |
377 | S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry, | 332 | S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry, |
378 | &log_fops); | 333 | &log_fops, card); |
379 | 334 | ||
380 | init_waitqueue_head(&(pd->rd_queue)); | 335 | init_waitqueue_head(&(pd->rd_queue)); |
381 | 336 | ||