Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Takashi Iwai and committed by
Linus Torvalds
ccec6e2c 7bae705e

+39 -29
+39 -29
sound/core/memalloc.c
··· 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> ··· 482 481 #define SND_MEM_PROC_FILE "driver/snd-page-alloc" 483 482 static struct proc_dir_entry *snd_mem_proc; 484 483 485 - static int snd_mem_proc_read(char *page, char **start, off_t off, 486 - int count, int *eof, void *data) 484 + static int snd_mem_proc_read(struct seq_file *seq, void *offset) 487 485 { 488 - int len = 0; 489 486 long pages = snd_allocated_pages >> (PAGE_SHIFT-12); 490 487 struct snd_mem_list *mem; 491 488 int devno; 492 489 static char *types[] = { "UNKNOWN", "CONT", "DEV", "DEV-SG", "SBUS" }; 493 490 494 491 mutex_lock(&list_mutex); 495 - len += snprintf(page + len, count - len, 496 - "pages : %li bytes (%li pages per %likB)\n", 497 - pages * PAGE_SIZE, pages, PAGE_SIZE / 1024); 492 + seq_printf(seq, "pages : %li bytes (%li pages per %likB)\n", 493 + pages * PAGE_SIZE, pages, PAGE_SIZE / 1024); 498 494 devno = 0; 499 495 list_for_each_entry(mem, &mem_list_head, list) { 500 496 devno++; 501 - len += snprintf(page + len, count - len, 502 - "buffer %d : ID %08x : type %s\n", 503 - devno, mem->id, types[mem->buffer.dev.type]); 504 - len += snprintf(page + len, count - len, 505 - " addr = 0x%lx, size = %d bytes\n", 506 - (unsigned long)mem->buffer.addr, (int)mem->buffer.bytes); 497 + seq_printf(seq, "buffer %d : ID %08x : type %s\n", 498 + devno, mem->id, types[mem->buffer.dev.type]); 499 + seq_printf(seq, " addr = 0x%lx, size = %d bytes\n", 500 + (unsigned long)mem->buffer.addr, 501 + (int)mem->buffer.bytes); 507 502 } 508 503 mutex_unlock(&list_mutex); 509 - return len; 504 + return 0; 505 + } 506 + 507 + static int snd_mem_proc_open(struct inode *inode, struct file *file) 508 + { 509 + return single_open(file, snd_mem_proc_read, NULL); 510 510 } 511 511 512 512 /* FIXME: for pci only - other bus? */ 513 513 #ifdef CONFIG_PCI 514 514 #define gettoken(bufp) strsep(bufp, " \t\n") 515 515 516 - static int snd_mem_proc_write(struct file *file, const char __user *buffer, 517 - unsigned long count, void *data) 516 + static ssize_t snd_mem_proc_write(struct file *file, const char __user * buffer, 517 + size_t count, loff_t * ppos) 518 518 { 519 519 char buf[128]; 520 520 char *token, *p; 521 521 522 - if (count > ARRAY_SIZE(buf) - 1) 523 - count = ARRAY_SIZE(buf) - 1; 522 + if (count > sizeof(buf) - 1) 523 + return -EINVAL; 524 524 if (copy_from_user(buf, buffer, count)) 525 525 return -EFAULT; 526 - buf[ARRAY_SIZE(buf) - 1] = '\0'; 526 + buf[count] = '\0'; 527 527 528 528 p = buf; 529 529 token = gettoken(&p); 530 530 if (! token || *token == '#') 531 - return (int)count; 531 + return count; 532 532 if (strcmp(token, "add") == 0) { 533 533 char *endp; 534 534 int vendor, device, size, buffers; ··· 550 548 (buffers = simple_strtol(token, NULL, 0)) <= 0 || 551 549 buffers > 4) { 552 550 printk(KERN_ERR "snd-page-alloc: invalid proc write format\n"); 553 - return (int)count; 551 + return count; 554 552 } 555 553 vendor &= 0xffff; 556 554 device &= 0xffff; ··· 562 560 if (pci_set_dma_mask(pci, mask) < 0 || 563 561 pci_set_consistent_dma_mask(pci, mask) < 0) { 564 562 printk(KERN_ERR "snd-page-alloc: cannot set DMA mask %lx for pci %04x:%04x\n", mask, vendor, device); 565 - return (int)count; 563 + return count; 566 564 } 567 565 } 568 566 for (i = 0; i < buffers; i++) { ··· 572 570 size, &dmab) < 0) { 573 571 printk(KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size); 574 572 pci_dev_put(pci); 575 - return (int)count; 573 + return count; 576 574 } 577 575 snd_dma_reserve_buf(&dmab, snd_dma_pci_buf_id(pci)); 578 576 } ··· 598 596 free_all_reserved_pages(); 599 597 else 600 598 printk(KERN_ERR "snd-page-alloc: invalid proc cmd\n"); 601 - return (int)count; 599 + return count; 602 600 } 603 601 #endif /* CONFIG_PCI */ 602 + 603 + static const struct file_operations snd_mem_proc_fops = { 604 + .owner = THIS_MODULE, 605 + .open = snd_mem_proc_open, 606 + .read = seq_read, 607 + #ifdef CONFIG_PCI 608 + .write = snd_mem_proc_write, 609 + #endif 610 + .llseek = seq_lseek, 611 + .release = single_release, 612 + }; 613 + 604 614 #endif /* CONFIG_PROC_FS */ 605 615 606 616 /* ··· 623 609 { 624 610 #ifdef CONFIG_PROC_FS 625 611 snd_mem_proc = create_proc_entry(SND_MEM_PROC_FILE, 0644, NULL); 626 - if (snd_mem_proc) { 627 - snd_mem_proc->read_proc = snd_mem_proc_read; 628 - #ifdef CONFIG_PCI 629 - snd_mem_proc->write_proc = snd_mem_proc_write; 630 - #endif 631 - } 612 + if (snd_mem_proc) 613 + snd_mem_proc->proc_fops = &snd_mem_proc_fops; 632 614 #endif 633 615 return 0; 634 616 }