aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2007-09-17 15:55:10 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-09-24 11:20:52 -0400
commitccec6e2c4a74adf76ed4e2478091a311b1806212 (patch)
tree682fdb5527d02b28400ab4141552845d7df37d87 /sound
parent7bae705ef2c2daac1993de03e5be93b5c300fc5e (diff)
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>
Diffstat (limited to 'sound')
-rw-r--r--sound/core/memalloc.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index f057430db0d0..9b5656d8bcca 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -27,6 +27,7 @@
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/seq_file.h>
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
31#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
32#include <linux/moduleparam.h> 33#include <linux/moduleparam.h>
@@ -481,53 +482,54 @@ static void free_all_reserved_pages(void)
481#define SND_MEM_PROC_FILE "driver/snd-page-alloc" 482#define SND_MEM_PROC_FILE "driver/snd-page-alloc"
482static struct proc_dir_entry *snd_mem_proc; 483static struct proc_dir_entry *snd_mem_proc;
483 484
484static int snd_mem_proc_read(char *page, char **start, off_t off, 485static int snd_mem_proc_read(struct seq_file *seq, void *offset)
485 int count, int *eof, void *data)
486{ 486{
487 int len = 0;
488 long pages = snd_allocated_pages >> (PAGE_SHIFT-12); 487 long pages = snd_allocated_pages >> (PAGE_SHIFT-12);
489 struct snd_mem_list *mem; 488 struct snd_mem_list *mem;
490 int devno; 489 int devno;
491 static char *types[] = { "UNKNOWN", "CONT", "DEV", "DEV-SG", "SBUS" }; 490 static char *types[] = { "UNKNOWN", "CONT", "DEV", "DEV-SG", "SBUS" };
492 491
493 mutex_lock(&list_mutex); 492 mutex_lock(&list_mutex);
494 len += snprintf(page + len, count - len, 493 seq_printf(seq, "pages : %li bytes (%li pages per %likB)\n",
495 "pages : %li bytes (%li pages per %likB)\n", 494 pages * PAGE_SIZE, pages, PAGE_SIZE / 1024);
496 pages * PAGE_SIZE, pages, PAGE_SIZE / 1024);
497 devno = 0; 495 devno = 0;
498 list_for_each_entry(mem, &mem_list_head, list) { 496 list_for_each_entry(mem, &mem_list_head, list) {
499 devno++; 497 devno++;
500 len += snprintf(page + len, count - len, 498 seq_printf(seq, "buffer %d : ID %08x : type %s\n",
501 "buffer %d : ID %08x : type %s\n", 499 devno, mem->id, types[mem->buffer.dev.type]);
502 devno, mem->id, types[mem->buffer.dev.type]); 500 seq_printf(seq, " addr = 0x%lx, size = %d bytes\n",
503 len += snprintf(page + len, count - len, 501 (unsigned long)mem->buffer.addr,
504 " addr = 0x%lx, size = %d bytes\n", 502 (int)mem->buffer.bytes);
505 (unsigned long)mem->buffer.addr, (int)mem->buffer.bytes);
506 } 503 }
507 mutex_unlock(&list_mutex); 504 mutex_unlock(&list_mutex);
508 return len; 505 return 0;
506}
507
508static int snd_mem_proc_open(struct inode *inode, struct file *file)
509{
510 return single_open(file, snd_mem_proc_read, NULL);
509} 511}
510 512
511/* FIXME: for pci only - other bus? */ 513/* FIXME: for pci only - other bus? */
512#ifdef CONFIG_PCI 514#ifdef CONFIG_PCI
513#define gettoken(bufp) strsep(bufp, " \t\n") 515#define gettoken(bufp) strsep(bufp, " \t\n")
514 516
515static int snd_mem_proc_write(struct file *file, const char __user *buffer, 517static ssize_t snd_mem_proc_write(struct file *file, const char __user * buffer,
516 unsigned long count, void *data) 518 size_t count, loff_t * ppos)
517{ 519{
518 char buf[128]; 520 char buf[128];
519 char *token, *p; 521 char *token, *p;
520 522
521 if (count > ARRAY_SIZE(buf) - 1) 523 if (count > sizeof(buf) - 1)
522 count = ARRAY_SIZE(buf) - 1; 524 return -EINVAL;
523 if (copy_from_user(buf, buffer, count)) 525 if (copy_from_user(buf, buffer, count))
524 return -EFAULT; 526 return -EFAULT;
525 buf[ARRAY_SIZE(buf) - 1] = '\0'; 527 buf[count] = '\0';
526 528
527 p = buf; 529 p = buf;
528 token = gettoken(&p); 530 token = gettoken(&p);
529 if (! token || *token == '#') 531 if (! token || *token == '#')
530 return (int)count; 532 return count;
531 if (strcmp(token, "add") == 0) { 533 if (strcmp(token, "add") == 0) {
532 char *endp; 534 char *endp;
533 int vendor, device, size, buffers; 535 int vendor, device, size, buffers;
@@ -548,7 +550,7 @@ static int snd_mem_proc_write(struct file *file, const char __user *buffer,
548 (buffers = simple_strtol(token, NULL, 0)) <= 0 || 550 (buffers = simple_strtol(token, NULL, 0)) <= 0 ||
549 buffers > 4) { 551 buffers > 4) {
550 printk(KERN_ERR "snd-page-alloc: invalid proc write format\n"); 552 printk(KERN_ERR "snd-page-alloc: invalid proc write format\n");
551 return (int)count; 553 return count;
552 } 554 }
553 vendor &= 0xffff; 555 vendor &= 0xffff;
554 device &= 0xffff; 556 device &= 0xffff;
@@ -560,7 +562,7 @@ static int snd_mem_proc_write(struct file *file, const char __user *buffer,
560 if (pci_set_dma_mask(pci, mask) < 0 || 562 if (pci_set_dma_mask(pci, mask) < 0 ||
561 pci_set_consistent_dma_mask(pci, mask) < 0) { 563 pci_set_consistent_dma_mask(pci, mask) < 0) {
562 printk(KERN_ERR "snd-page-alloc: cannot set DMA mask %lx for pci %04x:%04x\n", mask, vendor, device); 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 for (i = 0; i < buffers; i++) { 568 for (i = 0; i < buffers; i++) {
@@ -570,7 +572,7 @@ static int snd_mem_proc_write(struct file *file, const char __user *buffer,
570 size, &dmab) < 0) { 572 size, &dmab) < 0) {
571 printk(KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size); 573 printk(KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size);
572 pci_dev_put(pci); 574 pci_dev_put(pci);
573 return (int)count; 575 return count;
574 } 576 }
575 snd_dma_reserve_buf(&dmab, snd_dma_pci_buf_id(pci)); 577 snd_dma_reserve_buf(&dmab, snd_dma_pci_buf_id(pci));
576 } 578 }
@@ -596,9 +598,21 @@ static int snd_mem_proc_write(struct file *file, const char __user *buffer,
596 free_all_reserved_pages(); 598 free_all_reserved_pages();
597 else 599 else
598 printk(KERN_ERR "snd-page-alloc: invalid proc cmd\n"); 600 printk(KERN_ERR "snd-page-alloc: invalid proc cmd\n");
599 return (int)count; 601 return count;
600} 602}
601#endif /* CONFIG_PCI */ 603#endif /* CONFIG_PCI */
604
605static 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#endif /* CONFIG_PROC_FS */ 616#endif /* CONFIG_PROC_FS */
603 617
604/* 618/*
@@ -609,12 +623,8 @@ static int __init snd_mem_init(void)
609{ 623{
610#ifdef CONFIG_PROC_FS 624#ifdef CONFIG_PROC_FS
611 snd_mem_proc = create_proc_entry(SND_MEM_PROC_FILE, 0644, NULL); 625 snd_mem_proc = create_proc_entry(SND_MEM_PROC_FILE, 0644, NULL);
612 if (snd_mem_proc) { 626 if (snd_mem_proc)
613 snd_mem_proc->read_proc = snd_mem_proc_read; 627 snd_mem_proc->proc_fops = &snd_mem_proc_fops;
614#ifdef CONFIG_PCI
615 snd_mem_proc->write_proc = snd_mem_proc_write;
616#endif
617 }
618#endif 628#endif
619 return 0; 629 return 0;
620} 630}