Commit ccec6e2c4a74adf76ed4e2478091a311b1806212
Committed by
Linus Torvalds
1 parent
7bae705ef2
Exists in
master
and in
7 other branches
Convert snd-page-alloc proc file to use seq_file
Use seq_file for the proc file read/write of snd-page-alloc module. This automatically fixes bugs in the old proc code. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 39 additions and 29 deletions Side-by-side Diff
sound/core/memalloc.c
... | ... | @@ -27,6 +27,7 @@ |
27 | 27 | #include <linux/pci.h> |
28 | 28 | #include <linux/slab.h> |
29 | 29 | #include <linux/mm.h> |
30 | +#include <linux/seq_file.h> | |
30 | 31 | #include <asm/uaccess.h> |
31 | 32 | #include <linux/dma-mapping.h> |
32 | 33 | #include <linux/moduleparam.h> |
33 | 34 | |
34 | 35 | |
35 | 36 | |
36 | 37 | |
37 | 38 | |
38 | 39 | |
39 | 40 | |
40 | 41 | |
41 | 42 | |
... | ... | @@ -481,53 +482,54 @@ |
481 | 482 | #define SND_MEM_PROC_FILE "driver/snd-page-alloc" |
482 | 483 | static struct proc_dir_entry *snd_mem_proc; |
483 | 484 | |
484 | -static int snd_mem_proc_read(char *page, char **start, off_t off, | |
485 | - int count, int *eof, void *data) | |
485 | +static int snd_mem_proc_read(struct seq_file *seq, void *offset) | |
486 | 486 | { |
487 | - int len = 0; | |
488 | 487 | long pages = snd_allocated_pages >> (PAGE_SHIFT-12); |
489 | 488 | struct snd_mem_list *mem; |
490 | 489 | int devno; |
491 | 490 | static char *types[] = { "UNKNOWN", "CONT", "DEV", "DEV-SG", "SBUS" }; |
492 | 491 | |
493 | 492 | mutex_lock(&list_mutex); |
494 | - len += snprintf(page + len, count - len, | |
495 | - "pages : %li bytes (%li pages per %likB)\n", | |
496 | - pages * PAGE_SIZE, pages, PAGE_SIZE / 1024); | |
493 | + seq_printf(seq, "pages : %li bytes (%li pages per %likB)\n", | |
494 | + pages * PAGE_SIZE, pages, PAGE_SIZE / 1024); | |
497 | 495 | devno = 0; |
498 | 496 | list_for_each_entry(mem, &mem_list_head, list) { |
499 | 497 | devno++; |
500 | - len += snprintf(page + len, count - len, | |
501 | - "buffer %d : ID %08x : type %s\n", | |
502 | - devno, mem->id, types[mem->buffer.dev.type]); | |
503 | - len += snprintf(page + len, count - len, | |
504 | - " addr = 0x%lx, size = %d bytes\n", | |
505 | - (unsigned long)mem->buffer.addr, (int)mem->buffer.bytes); | |
498 | + seq_printf(seq, "buffer %d : ID %08x : type %s\n", | |
499 | + devno, mem->id, types[mem->buffer.dev.type]); | |
500 | + seq_printf(seq, " addr = 0x%lx, size = %d bytes\n", | |
501 | + (unsigned long)mem->buffer.addr, | |
502 | + (int)mem->buffer.bytes); | |
506 | 503 | } |
507 | 504 | mutex_unlock(&list_mutex); |
508 | - return len; | |
505 | + return 0; | |
509 | 506 | } |
510 | 507 | |
508 | +static int snd_mem_proc_open(struct inode *inode, struct file *file) | |
509 | +{ | |
510 | + return single_open(file, snd_mem_proc_read, NULL); | |
511 | +} | |
512 | + | |
511 | 513 | /* FIXME: for pci only - other bus? */ |
512 | 514 | #ifdef CONFIG_PCI |
513 | 515 | #define gettoken(bufp) strsep(bufp, " \t\n") |
514 | 516 | |
515 | -static int snd_mem_proc_write(struct file *file, const char __user *buffer, | |
516 | - unsigned long count, void *data) | |
517 | +static ssize_t snd_mem_proc_write(struct file *file, const char __user * buffer, | |
518 | + size_t count, loff_t * ppos) | |
517 | 519 | { |
518 | 520 | char buf[128]; |
519 | 521 | char *token, *p; |
520 | 522 | |
521 | - if (count > ARRAY_SIZE(buf) - 1) | |
522 | - count = ARRAY_SIZE(buf) - 1; | |
523 | + if (count > sizeof(buf) - 1) | |
524 | + return -EINVAL; | |
523 | 525 | if (copy_from_user(buf, buffer, count)) |
524 | 526 | return -EFAULT; |
525 | - buf[ARRAY_SIZE(buf) - 1] = '] = '\0';'; | |
527 | + buf[count] = '] = '\0';'; | |
526 | 528 | |
527 | 529 | p = buf; |
528 | 530 | token = gettoken(&p); |
529 | 531 | if (! token || *token == '#') |
530 | - return (int)count; | |
532 | + return count; | |
531 | 533 | if (strcmp(token, "add") == 0) { |
532 | 534 | char *endp; |
533 | 535 | int vendor, device, size, buffers; |
... | ... | @@ -548,7 +550,7 @@ |
548 | 550 | (buffers = simple_strtol(token, NULL, 0)) <= 0 || |
549 | 551 | buffers > 4) { |
550 | 552 | printk(KERN_ERR "snd-page-alloc: invalid proc write format\n"); |
551 | - return (int)count; | |
553 | + return count; | |
552 | 554 | } |
553 | 555 | vendor &= 0xffff; |
554 | 556 | device &= 0xffff; |
... | ... | @@ -560,7 +562,7 @@ |
560 | 562 | if (pci_set_dma_mask(pci, mask) < 0 || |
561 | 563 | pci_set_consistent_dma_mask(pci, mask) < 0) { |
562 | 564 | printk(KERN_ERR "snd-page-alloc: cannot set DMA mask %lx for pci %04x:%04x\n", mask, vendor, device); |
563 | - return (int)count; | |
565 | + return count; | |
564 | 566 | } |
565 | 567 | } |
566 | 568 | for (i = 0; i < buffers; i++) { |
... | ... | @@ -570,7 +572,7 @@ |
570 | 572 | size, &dmab) < 0) { |
571 | 573 | printk(KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size); |
572 | 574 | pci_dev_put(pci); |
573 | - return (int)count; | |
575 | + return count; | |
574 | 576 | } |
575 | 577 | snd_dma_reserve_buf(&dmab, snd_dma_pci_buf_id(pci)); |
576 | 578 | } |
577 | 579 | |
... | ... | @@ -596,9 +598,21 @@ |
596 | 598 | free_all_reserved_pages(); |
597 | 599 | else |
598 | 600 | printk(KERN_ERR "snd-page-alloc: invalid proc cmd\n"); |
599 | - return (int)count; | |
601 | + return count; | |
600 | 602 | } |
601 | 603 | #endif /* CONFIG_PCI */ |
604 | + | |
605 | +static const struct file_operations snd_mem_proc_fops = { | |
606 | + .owner = THIS_MODULE, | |
607 | + .open = snd_mem_proc_open, | |
608 | + .read = seq_read, | |
609 | +#ifdef CONFIG_PCI | |
610 | + .write = snd_mem_proc_write, | |
611 | +#endif | |
612 | + .llseek = seq_lseek, | |
613 | + .release = single_release, | |
614 | +}; | |
615 | + | |
602 | 616 | #endif /* CONFIG_PROC_FS */ |
603 | 617 | |
604 | 618 | /* |
... | ... | @@ -609,12 +623,8 @@ |
609 | 623 | { |
610 | 624 | #ifdef CONFIG_PROC_FS |
611 | 625 | snd_mem_proc = create_proc_entry(SND_MEM_PROC_FILE, 0644, NULL); |
612 | - if (snd_mem_proc) { | |
613 | - snd_mem_proc->read_proc = snd_mem_proc_read; | |
614 | -#ifdef CONFIG_PCI | |
615 | - snd_mem_proc->write_proc = snd_mem_proc_write; | |
616 | -#endif | |
617 | - } | |
626 | + if (snd_mem_proc) | |
627 | + snd_mem_proc->proc_fops = &snd_mem_proc_fops; | |
618 | 628 | #endif |
619 | 629 | return 0; |
620 | 630 | } |