diff options
Diffstat (limited to 'lib/dma-debug.c')
-rw-r--r-- | lib/dma-debug.c | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/lib/dma-debug.c b/lib/dma-debug.c index 77053d9ef513..ad65fc0317d9 100644 --- a/lib/dma-debug.c +++ b/lib/dma-debug.c | |||
@@ -139,7 +139,7 @@ static inline void dump_entry_trace(struct dma_debug_entry *entry) | |||
139 | { | 139 | { |
140 | #ifdef CONFIG_STACKTRACE | 140 | #ifdef CONFIG_STACKTRACE |
141 | if (entry) { | 141 | if (entry) { |
142 | printk(KERN_WARNING "Mapped at:\n"); | 142 | pr_warning("Mapped at:\n"); |
143 | print_stack_trace(&entry->stacktrace, 0); | 143 | print_stack_trace(&entry->stacktrace, 0); |
144 | } | 144 | } |
145 | #endif | 145 | #endif |
@@ -147,6 +147,10 @@ static inline void dump_entry_trace(struct dma_debug_entry *entry) | |||
147 | 147 | ||
148 | static bool driver_filter(struct device *dev) | 148 | static bool driver_filter(struct device *dev) |
149 | { | 149 | { |
150 | struct device_driver *drv; | ||
151 | unsigned long flags; | ||
152 | bool ret; | ||
153 | |||
150 | /* driver filter off */ | 154 | /* driver filter off */ |
151 | if (likely(!current_driver_name[0])) | 155 | if (likely(!current_driver_name[0])) |
152 | return true; | 156 | return true; |
@@ -155,32 +159,28 @@ static bool driver_filter(struct device *dev) | |||
155 | if (current_driver && dev->driver == current_driver) | 159 | if (current_driver && dev->driver == current_driver) |
156 | return true; | 160 | return true; |
157 | 161 | ||
158 | /* driver filter on but not yet initialized */ | 162 | if (current_driver || !current_driver_name[0]) |
159 | if (!current_driver && current_driver_name[0]) { | 163 | return false; |
160 | struct device_driver *drv = get_driver(dev->driver); | ||
161 | unsigned long flags; | ||
162 | bool ret = false; | ||
163 | |||
164 | if (!drv) | ||
165 | return false; | ||
166 | |||
167 | /* lock to protect against change of current_driver_name */ | ||
168 | read_lock_irqsave(&driver_name_lock, flags); | ||
169 | 164 | ||
170 | if (drv->name && | 165 | /* driver filter on but not yet initialized */ |
171 | strncmp(current_driver_name, drv->name, | 166 | drv = get_driver(dev->driver); |
172 | NAME_MAX_LEN-1) == 0) { | 167 | if (!drv) |
173 | current_driver = drv; | 168 | return false; |
174 | ret = true; | ||
175 | } | ||
176 | 169 | ||
177 | read_unlock_irqrestore(&driver_name_lock, flags); | 170 | /* lock to protect against change of current_driver_name */ |
178 | put_driver(drv); | 171 | read_lock_irqsave(&driver_name_lock, flags); |
179 | 172 | ||
180 | return ret; | 173 | ret = false; |
174 | if (drv->name && | ||
175 | strncmp(current_driver_name, drv->name, NAME_MAX_LEN - 1) == 0) { | ||
176 | current_driver = drv; | ||
177 | ret = true; | ||
181 | } | 178 | } |
182 | 179 | ||
183 | return false; | 180 | read_unlock_irqrestore(&driver_name_lock, flags); |
181 | put_driver(drv); | ||
182 | |||
183 | return ret; | ||
184 | } | 184 | } |
185 | 185 | ||
186 | #define err_printk(dev, entry, format, arg...) do { \ | 186 | #define err_printk(dev, entry, format, arg...) do { \ |
@@ -377,8 +377,7 @@ static struct dma_debug_entry *dma_entry_alloc(void) | |||
377 | spin_lock_irqsave(&free_entries_lock, flags); | 377 | spin_lock_irqsave(&free_entries_lock, flags); |
378 | 378 | ||
379 | if (list_empty(&free_entries)) { | 379 | if (list_empty(&free_entries)) { |
380 | printk(KERN_ERR "DMA-API: debugging out of memory " | 380 | pr_err("DMA-API: debugging out of memory - disabling\n"); |
381 | "- disabling\n"); | ||
382 | global_disable = true; | 381 | global_disable = true; |
383 | goto out; | 382 | goto out; |
384 | } | 383 | } |
@@ -483,8 +482,7 @@ static int prealloc_memory(u32 num_entries) | |||
483 | num_free_entries = num_entries; | 482 | num_free_entries = num_entries; |
484 | min_free_entries = num_entries; | 483 | min_free_entries = num_entries; |
485 | 484 | ||
486 | printk(KERN_INFO "DMA-API: preallocated %d debug entries\n", | 485 | pr_info("DMA-API: preallocated %d debug entries\n", num_entries); |
487 | num_entries); | ||
488 | 486 | ||
489 | return 0; | 487 | return 0; |
490 | 488 | ||
@@ -501,8 +499,8 @@ out_err: | |||
501 | static ssize_t filter_read(struct file *file, char __user *user_buf, | 499 | static ssize_t filter_read(struct file *file, char __user *user_buf, |
502 | size_t count, loff_t *ppos) | 500 | size_t count, loff_t *ppos) |
503 | { | 501 | { |
504 | unsigned long flags; | ||
505 | char buf[NAME_MAX_LEN + 1]; | 502 | char buf[NAME_MAX_LEN + 1]; |
503 | unsigned long flags; | ||
506 | int len; | 504 | int len; |
507 | 505 | ||
508 | if (!current_driver_name[0]) | 506 | if (!current_driver_name[0]) |
@@ -523,9 +521,9 @@ static ssize_t filter_read(struct file *file, char __user *user_buf, | |||
523 | static ssize_t filter_write(struct file *file, const char __user *userbuf, | 521 | static ssize_t filter_write(struct file *file, const char __user *userbuf, |
524 | size_t count, loff_t *ppos) | 522 | size_t count, loff_t *ppos) |
525 | { | 523 | { |
526 | unsigned long flags; | ||
527 | char buf[NAME_MAX_LEN]; | 524 | char buf[NAME_MAX_LEN]; |
528 | size_t len = NAME_MAX_LEN - 1; | 525 | unsigned long flags; |
526 | size_t len; | ||
529 | int i; | 527 | int i; |
530 | 528 | ||
531 | /* | 529 | /* |
@@ -534,7 +532,7 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf, | |||
534 | * disabled. Since copy_from_user can fault and may sleep we | 532 | * disabled. Since copy_from_user can fault and may sleep we |
535 | * need to copy to temporary buffer first | 533 | * need to copy to temporary buffer first |
536 | */ | 534 | */ |
537 | len = min(count, len); | 535 | len = min(count, (size_t)(NAME_MAX_LEN - 1)); |
538 | if (copy_from_user(buf, userbuf, len)) | 536 | if (copy_from_user(buf, userbuf, len)) |
539 | return -EFAULT; | 537 | return -EFAULT; |
540 | 538 | ||
@@ -542,7 +540,8 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf, | |||
542 | 540 | ||
543 | write_lock_irqsave(&driver_name_lock, flags); | 541 | write_lock_irqsave(&driver_name_lock, flags); |
544 | 542 | ||
545 | /* Now handle the string we got from userspace very carefully. | 543 | /* |
544 | * Now handle the string we got from userspace very carefully. | ||
546 | * The rules are: | 545 | * The rules are: |
547 | * - only use the first token we got | 546 | * - only use the first token we got |
548 | * - token delimiter is everything looking like a space | 547 | * - token delimiter is everything looking like a space |
@@ -551,13 +550,12 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf, | |||
551 | */ | 550 | */ |
552 | if (!isalnum(buf[0])) { | 551 | if (!isalnum(buf[0])) { |
553 | /* | 552 | /* |
554 | If the first character userspace gave us is not | 553 | * If the first character userspace gave us is not |
555 | * alphanumerical then assume the filter should be | 554 | * alphanumerical then assume the filter should be |
556 | * switched off. | 555 | * switched off. |
557 | */ | 556 | */ |
558 | if (current_driver_name[0]) | 557 | if (current_driver_name[0]) |
559 | printk(KERN_INFO "DMA-API: switching off dma-debug " | 558 | pr_info("DMA-API: switching off dma-debug driver filter\n"); |
560 | "driver filter\n"); | ||
561 | current_driver_name[0] = 0; | 559 | current_driver_name[0] = 0; |
562 | current_driver = NULL; | 560 | current_driver = NULL; |
563 | goto out_unlock; | 561 | goto out_unlock; |
@@ -575,8 +573,8 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf, | |||
575 | current_driver_name[i] = 0; | 573 | current_driver_name[i] = 0; |
576 | current_driver = NULL; | 574 | current_driver = NULL; |
577 | 575 | ||
578 | printk(KERN_INFO "DMA-API: enable driver filter for driver [%s]\n", | 576 | pr_info("DMA-API: enable driver filter for driver [%s]\n", |
579 | current_driver_name); | 577 | current_driver_name); |
580 | 578 | ||
581 | out_unlock: | 579 | out_unlock: |
582 | write_unlock_irqrestore(&driver_name_lock, flags); | 580 | write_unlock_irqrestore(&driver_name_lock, flags); |
@@ -593,7 +591,7 @@ static int dma_debug_fs_init(void) | |||
593 | { | 591 | { |
594 | dma_debug_dent = debugfs_create_dir("dma-api", NULL); | 592 | dma_debug_dent = debugfs_create_dir("dma-api", NULL); |
595 | if (!dma_debug_dent) { | 593 | if (!dma_debug_dent) { |
596 | printk(KERN_ERR "DMA-API: can not create debugfs directory\n"); | 594 | pr_err("DMA-API: can not create debugfs directory\n"); |
597 | return -ENOMEM; | 595 | return -ENOMEM; |
598 | } | 596 | } |
599 | 597 | ||
@@ -651,15 +649,19 @@ static int device_dma_allocations(struct device *dev) | |||
651 | unsigned long flags; | 649 | unsigned long flags; |
652 | int count = 0, i; | 650 | int count = 0, i; |
653 | 651 | ||
652 | local_irq_save(flags); | ||
653 | |||
654 | for (i = 0; i < HASH_SIZE; ++i) { | 654 | for (i = 0; i < HASH_SIZE; ++i) { |
655 | spin_lock_irqsave(&dma_entry_hash[i].lock, flags); | 655 | spin_lock(&dma_entry_hash[i].lock); |
656 | list_for_each_entry(entry, &dma_entry_hash[i].list, list) { | 656 | list_for_each_entry(entry, &dma_entry_hash[i].list, list) { |
657 | if (entry->dev == dev) | 657 | if (entry->dev == dev) |
658 | count += 1; | 658 | count += 1; |
659 | } | 659 | } |
660 | spin_unlock_irqrestore(&dma_entry_hash[i].lock, flags); | 660 | spin_unlock(&dma_entry_hash[i].lock); |
661 | } | 661 | } |
662 | 662 | ||
663 | local_irq_restore(flags); | ||
664 | |||
663 | return count; | 665 | return count; |
664 | } | 666 | } |
665 | 667 | ||
@@ -692,7 +694,7 @@ void dma_debug_add_bus(struct bus_type *bus) | |||
692 | 694 | ||
693 | nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); | 695 | nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); |
694 | if (nb == NULL) { | 696 | if (nb == NULL) { |
695 | printk(KERN_ERR "dma_debug_add_bus: out of memory\n"); | 697 | pr_err("dma_debug_add_bus: out of memory\n"); |
696 | return; | 698 | return; |
697 | } | 699 | } |
698 | 700 | ||
@@ -717,8 +719,7 @@ void dma_debug_init(u32 num_entries) | |||
717 | } | 719 | } |
718 | 720 | ||
719 | if (dma_debug_fs_init() != 0) { | 721 | if (dma_debug_fs_init() != 0) { |
720 | printk(KERN_ERR "DMA-API: error creating debugfs entries " | 722 | pr_err("DMA-API: error creating debugfs entries - disabling\n"); |
721 | "- disabling\n"); | ||
722 | global_disable = true; | 723 | global_disable = true; |
723 | 724 | ||
724 | return; | 725 | return; |
@@ -728,8 +729,7 @@ void dma_debug_init(u32 num_entries) | |||
728 | num_entries = req_entries; | 729 | num_entries = req_entries; |
729 | 730 | ||
730 | if (prealloc_memory(num_entries) != 0) { | 731 | if (prealloc_memory(num_entries) != 0) { |
731 | printk(KERN_ERR "DMA-API: debugging out of memory error " | 732 | pr_err("DMA-API: debugging out of memory error - disabled\n"); |
732 | "- disabled\n"); | ||
733 | global_disable = true; | 733 | global_disable = true; |
734 | 734 | ||
735 | return; | 735 | return; |
@@ -737,7 +737,7 @@ void dma_debug_init(u32 num_entries) | |||
737 | 737 | ||
738 | nr_total_entries = num_free_entries; | 738 | nr_total_entries = num_free_entries; |
739 | 739 | ||
740 | printk(KERN_INFO "DMA-API: debugging enabled by kernel config\n"); | 740 | pr_info("DMA-API: debugging enabled by kernel config\n"); |
741 | } | 741 | } |
742 | 742 | ||
743 | static __init int dma_debug_cmdline(char *str) | 743 | static __init int dma_debug_cmdline(char *str) |
@@ -746,8 +746,7 @@ static __init int dma_debug_cmdline(char *str) | |||
746 | return -EINVAL; | 746 | return -EINVAL; |
747 | 747 | ||
748 | if (strncmp(str, "off", 3) == 0) { | 748 | if (strncmp(str, "off", 3) == 0) { |
749 | printk(KERN_INFO "DMA-API: debugging disabled on kernel " | 749 | pr_info("DMA-API: debugging disabled on kernel command line\n"); |
750 | "command line\n"); | ||
751 | global_disable = true; | 750 | global_disable = true; |
752 | } | 751 | } |
753 | 752 | ||
@@ -1039,18 +1038,19 @@ EXPORT_SYMBOL(debug_dma_map_sg); | |||
1039 | 1038 | ||
1040 | static int get_nr_mapped_entries(struct device *dev, struct scatterlist *s) | 1039 | static int get_nr_mapped_entries(struct device *dev, struct scatterlist *s) |
1041 | { | 1040 | { |
1042 | struct dma_debug_entry *entry; | 1041 | struct dma_debug_entry *entry, ref; |
1043 | struct hash_bucket *bucket; | 1042 | struct hash_bucket *bucket; |
1044 | unsigned long flags; | 1043 | unsigned long flags; |
1045 | int mapped_ents = 0; | 1044 | int mapped_ents; |
1046 | struct dma_debug_entry ref; | ||
1047 | 1045 | ||
1048 | ref.dev = dev; | 1046 | ref.dev = dev; |
1049 | ref.dev_addr = sg_dma_address(s); | 1047 | ref.dev_addr = sg_dma_address(s); |
1050 | ref.size = sg_dma_len(s), | 1048 | ref.size = sg_dma_len(s), |
1049 | |||
1050 | bucket = get_hash_bucket(&ref, &flags); | ||
1051 | entry = hash_bucket_find(bucket, &ref); | ||
1052 | mapped_ents = 0; | ||
1051 | 1053 | ||
1052 | bucket = get_hash_bucket(&ref, &flags); | ||
1053 | entry = hash_bucket_find(bucket, &ref); | ||
1054 | if (entry) | 1054 | if (entry) |
1055 | mapped_ents = entry->sg_mapped_ents; | 1055 | mapped_ents = entry->sg_mapped_ents; |
1056 | put_hash_bucket(bucket, &flags); | 1056 | put_hash_bucket(bucket, &flags); |
@@ -1237,8 +1237,8 @@ static int __init dma_debug_driver_setup(char *str) | |||
1237 | } | 1237 | } |
1238 | 1238 | ||
1239 | if (current_driver_name[0]) | 1239 | if (current_driver_name[0]) |
1240 | printk(KERN_INFO "DMA-API: enable driver filter for " | 1240 | pr_info("DMA-API: enable driver filter for driver [%s]\n", |
1241 | "driver [%s]\n", current_driver_name); | 1241 | current_driver_name); |
1242 | 1242 | ||
1243 | 1243 | ||
1244 | return 1; | 1244 | return 1; |