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

USB: convert ohci debug files to use debugfs instead of sysfs

We should not have multiple line files in sysfs, this moves the data to
debugfs instead, like the UHCI driver.

Signed-off-by: Tony Jones <tonyj@suse.de>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Tony Jones and committed by
Greg Kroah-Hartman
684c19e0 f2a383e4

+209 -29
+184 -29
drivers/usb/host/ohci-dbg.c
··· 401 401 402 402 #else 403 403 404 + static int debug_async_open(struct inode *, struct file *); 405 + static int debug_periodic_open(struct inode *, struct file *); 406 + static int debug_registers_open(struct inode *, struct file *); 407 + static int debug_async_open(struct inode *, struct file *); 408 + static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); 409 + static int debug_close(struct inode *, struct file *); 410 + 411 + static const struct file_operations debug_async_fops = { 412 + .owner = THIS_MODULE, 413 + .open = debug_async_open, 414 + .read = debug_output, 415 + .release = debug_close, 416 + }; 417 + static const struct file_operations debug_periodic_fops = { 418 + .owner = THIS_MODULE, 419 + .open = debug_periodic_open, 420 + .read = debug_output, 421 + .release = debug_close, 422 + }; 423 + static const struct file_operations debug_registers_fops = { 424 + .owner = THIS_MODULE, 425 + .open = debug_registers_open, 426 + .read = debug_output, 427 + .release = debug_close, 428 + }; 429 + 430 + static struct dentry *ohci_debug_root; 431 + 432 + struct debug_buffer { 433 + ssize_t (*fill_func)(struct debug_buffer *); /* fill method */ 434 + struct device *dev; 435 + struct mutex mutex; /* protect filling of buffer */ 436 + size_t count; /* number of characters filled into buffer */ 437 + char *page; 438 + }; 439 + 404 440 static ssize_t 405 441 show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed) 406 442 { ··· 503 467 return count - size; 504 468 } 505 469 506 - static ssize_t 507 - show_async(struct device *dev, struct device_attribute *attr, char *buf) 470 + static ssize_t fill_async_buffer(struct debug_buffer *buf) 508 471 { 509 472 struct usb_bus *bus; 510 473 struct usb_hcd *hcd; ··· 511 476 size_t temp; 512 477 unsigned long flags; 513 478 514 - bus = dev_get_drvdata(dev); 479 + bus = dev_get_drvdata(buf->dev); 515 480 hcd = bus_to_hcd(bus); 516 481 ohci = hcd_to_ohci(hcd); 517 482 518 483 /* display control and bulk lists together, for simplicity */ 519 484 spin_lock_irqsave (&ohci->lock, flags); 520 - temp = show_list (ohci, buf, PAGE_SIZE, ohci->ed_controltail); 521 - temp += show_list (ohci, buf + temp, PAGE_SIZE - temp, ohci->ed_bulktail); 485 + temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail); 486 + temp += show_list(ohci, buf->page + temp, buf->count - temp, 487 + ohci->ed_bulktail); 522 488 spin_unlock_irqrestore (&ohci->lock, flags); 523 489 524 490 return temp; 525 491 } 526 - static DEVICE_ATTR(async, S_IRUGO, show_async, NULL); 527 - 528 492 529 493 #define DBG_SCHED_LIMIT 64 530 494 531 - static ssize_t 532 - show_periodic(struct device *dev, struct device_attribute *attr, char *buf) 495 + static ssize_t fill_periodic_buffer(struct debug_buffer *buf) 533 496 { 534 497 struct usb_bus *bus; 535 498 struct usb_hcd *hcd; ··· 542 509 return 0; 543 510 seen_count = 0; 544 511 545 - bus = dev_get_drvdata(dev); 512 + bus = (struct usb_bus *)dev_get_drvdata(buf->dev); 546 513 hcd = bus_to_hcd(bus); 547 514 ohci = hcd_to_ohci(hcd); 548 - next = buf; 515 + next = buf->page; 549 516 size = PAGE_SIZE; 550 517 551 518 temp = scnprintf (next, size, "size = %d\n", NUM_INTS); ··· 622 589 623 590 return PAGE_SIZE - size; 624 591 } 625 - static DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL); 626 - 627 - 628 592 #undef DBG_SCHED_LIMIT 629 593 630 - static ssize_t 631 - show_registers(struct device *dev, struct device_attribute *attr, char *buf) 594 + static ssize_t fill_registers_buffer(struct debug_buffer *buf) 632 595 { 633 596 struct usb_bus *bus; 634 597 struct usb_hcd *hcd; ··· 635 606 char *next; 636 607 u32 rdata; 637 608 638 - bus = dev_get_drvdata(dev); 609 + bus = (struct usb_bus *)dev_get_drvdata(buf->dev); 639 610 hcd = bus_to_hcd(bus); 640 611 ohci = hcd_to_ohci(hcd); 641 612 regs = ohci->regs; 642 - next = buf; 613 + next = buf->page; 643 614 size = PAGE_SIZE; 644 615 645 616 spin_lock_irqsave (&ohci->lock, flags); ··· 706 677 707 678 done: 708 679 spin_unlock_irqrestore (&ohci->lock, flags); 680 + 709 681 return PAGE_SIZE - size; 710 682 } 711 - static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL); 712 683 684 + static struct debug_buffer *alloc_buffer(struct device *dev, 685 + ssize_t (*fill_func)(struct debug_buffer *)) 686 + { 687 + struct debug_buffer *buf; 713 688 689 + buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL); 690 + 691 + if (buf) { 692 + buf->dev = dev; 693 + buf->fill_func = fill_func; 694 + mutex_init(&buf->mutex); 695 + } 696 + 697 + return buf; 698 + } 699 + 700 + static int fill_buffer(struct debug_buffer *buf) 701 + { 702 + int ret = 0; 703 + 704 + if (!buf->page) 705 + buf->page = (char *)get_zeroed_page(GFP_KERNEL); 706 + 707 + if (!buf->page) { 708 + ret = -ENOMEM; 709 + goto out; 710 + } 711 + 712 + ret = buf->fill_func(buf); 713 + 714 + if (ret >= 0) { 715 + buf->count = ret; 716 + ret = 0; 717 + } 718 + 719 + out: 720 + return ret; 721 + } 722 + 723 + static ssize_t debug_output(struct file *file, char __user *user_buf, 724 + size_t len, loff_t *offset) 725 + { 726 + struct debug_buffer *buf = file->private_data; 727 + int ret = 0; 728 + 729 + mutex_lock(&buf->mutex); 730 + if (buf->count == 0) { 731 + ret = fill_buffer(buf); 732 + if (ret != 0) { 733 + mutex_unlock(&buf->mutex); 734 + goto out; 735 + } 736 + } 737 + mutex_unlock(&buf->mutex); 738 + 739 + ret = simple_read_from_buffer(user_buf, len, offset, 740 + buf->page, buf->count); 741 + 742 + out: 743 + return ret; 744 + 745 + } 746 + 747 + static int debug_close(struct inode *inode, struct file *file) 748 + { 749 + struct debug_buffer *buf = file->private_data; 750 + 751 + if (buf) { 752 + if (buf->page) 753 + free_page((unsigned long)buf->page); 754 + kfree(buf); 755 + } 756 + 757 + return 0; 758 + } 759 + static int debug_async_open(struct inode *inode, struct file *file) 760 + { 761 + file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); 762 + 763 + return file->private_data ? 0 : -ENOMEM; 764 + } 765 + 766 + static int debug_periodic_open(struct inode *inode, struct file *file) 767 + { 768 + file->private_data = alloc_buffer(inode->i_private, 769 + fill_periodic_buffer); 770 + 771 + return file->private_data ? 0 : -ENOMEM; 772 + } 773 + 774 + static int debug_registers_open(struct inode *inode, struct file *file) 775 + { 776 + file->private_data = alloc_buffer(inode->i_private, 777 + fill_registers_buffer); 778 + 779 + return file->private_data ? 0 : -ENOMEM; 780 + } 714 781 static inline void create_debug_files (struct ohci_hcd *ohci) 715 782 { 716 - struct device *dev = ohci_to_hcd(ohci)->self.dev; 717 - int retval; 783 + struct usb_bus *bus = &ohci_to_hcd(ohci)->self; 784 + struct device *dev = bus->dev; 718 785 719 - retval = device_create_file(dev, &dev_attr_async); 720 - retval = device_create_file(dev, &dev_attr_periodic); 721 - retval = device_create_file(dev, &dev_attr_registers); 786 + ohci->debug_dir = debugfs_create_dir(bus->bus_name, ohci_debug_root); 787 + if (!ohci->debug_dir) 788 + goto dir_error; 789 + 790 + ohci->debug_async = debugfs_create_file("async", S_IRUGO, 791 + ohci->debug_dir, dev, 792 + &debug_async_fops); 793 + if (!ohci->debug_async) 794 + goto async_error; 795 + 796 + ohci->debug_periodic = debugfs_create_file("periodic", S_IRUGO, 797 + ohci->debug_dir, dev, 798 + &debug_periodic_fops); 799 + if (!ohci->debug_periodic) 800 + goto periodic_error; 801 + 802 + ohci->debug_registers = debugfs_create_file("registers", S_IRUGO, 803 + ohci->debug_dir, dev, 804 + &debug_registers_fops); 805 + if (!ohci->debug_registers) 806 + goto registers_error; 807 + 722 808 ohci_dbg (ohci, "created debug files\n"); 809 + return; 810 + 811 + registers_error: 812 + debugfs_remove(ohci->debug_periodic); 813 + periodic_error: 814 + debugfs_remove(ohci->debug_async); 815 + async_error: 816 + debugfs_remove(ohci->debug_dir); 817 + dir_error: 818 + ohci->debug_periodic = NULL; 819 + ohci->debug_async = NULL; 820 + ohci->debug_dir = NULL; 723 821 } 724 822 725 823 static inline void remove_debug_files (struct ohci_hcd *ohci) 726 824 { 727 - struct device *dev = ohci_to_hcd(ohci)->self.dev; 728 - 729 - device_remove_file(dev, &dev_attr_async); 730 - device_remove_file(dev, &dev_attr_periodic); 731 - device_remove_file(dev, &dev_attr_registers); 825 + debugfs_remove(ohci->debug_registers); 826 + debugfs_remove(ohci->debug_periodic); 827 + debugfs_remove(ohci->debug_async); 828 + debugfs_remove(ohci->debug_dir); 732 829 } 733 830 734 831 #endif
+18
drivers/usb/host/ohci-hcd.c
··· 36 36 #include <linux/dmapool.h> 37 37 #include <linux/reboot.h> 38 38 #include <linux/workqueue.h> 39 + #include <linux/debugfs.h> 39 40 40 41 #include <asm/io.h> 41 42 #include <asm/irq.h> ··· 1069 1068 pr_debug ("%s: block sizes: ed %Zd td %Zd\n", hcd_name, 1070 1069 sizeof (struct ed), sizeof (struct td)); 1071 1070 1071 + #ifdef DEBUG 1072 + ohci_debug_root = debugfs_create_dir("ohci", NULL); 1073 + if (!ohci_debug_root) { 1074 + retval = -ENOENT; 1075 + goto error_debug; 1076 + } 1077 + #endif 1078 + 1072 1079 #ifdef PS3_SYSTEM_BUS_DRIVER 1073 1080 retval = ps3_ohci_driver_register(&PS3_SYSTEM_BUS_DRIVER); 1074 1081 if (retval < 0) ··· 1139 1130 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1140 1131 error_ps3: 1141 1132 #endif 1133 + #ifdef DEBUG 1134 + debugfs_remove(ohci_debug_root); 1135 + ohci_debug_root = NULL; 1136 + error_debug: 1137 + #endif 1138 + 1142 1139 return retval; 1143 1140 } 1144 1141 module_init(ohci_hcd_mod_init); ··· 1168 1153 #endif 1169 1154 #ifdef PS3_SYSTEM_BUS_DRIVER 1170 1155 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1156 + #endif 1157 + #ifdef DEBUG 1158 + debugfs_remove(ohci_debug_root); 1171 1159 #endif 1172 1160 } 1173 1161 module_exit(ohci_hcd_mod_exit);
+7
drivers/usb/host/ohci.h
··· 408 408 unsigned eds_scheduled; 409 409 struct ed *ed_to_check; 410 410 unsigned zf_delay; 411 + 412 + #ifdef DEBUG 413 + struct dentry *debug_dir; 414 + struct dentry *debug_async; 415 + struct dentry *debug_periodic; 416 + struct dentry *debug_registers; 417 + #endif 411 418 }; 412 419 413 420 #ifdef CONFIG_PCI