Commit f737b095 authored by Robin Murphy's avatar Robin Murphy Committed by Christoph Hellwig

dma-debug: Use pr_fmt()

Use pr_fmt() to generate the "DMA-API: " prefix consistently. This
results in it being added to a couple of pr_*() messages which were
missing it before, and for the err_printk() calls moves it to the actual
start of the message instead of somewhere in the middle.
Signed-off-by: default avatarRobin Murphy <robin.murphy@arm.com>
Tested-by: default avatarQian Cai <cai@lca.pw>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 9f191555
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#define pr_fmt(fmt) "DMA-API: " fmt
#include <linux/sched/task_stack.h> #include <linux/sched/task_stack.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
...@@ -235,7 +237,7 @@ static bool driver_filter(struct device *dev) ...@@ -235,7 +237,7 @@ static bool driver_filter(struct device *dev)
error_count += 1; \ error_count += 1; \
if (driver_filter(dev) && \ if (driver_filter(dev) && \
(show_all_errors || show_num_errors > 0)) { \ (show_all_errors || show_num_errors > 0)) { \
WARN(1, "%s %s: " format, \ WARN(1, pr_fmt("%s %s: ") format, \
dev ? dev_driver_string(dev) : "NULL", \ dev ? dev_driver_string(dev) : "NULL", \
dev ? dev_name(dev) : "NULL", ## arg); \ dev ? dev_name(dev) : "NULL", ## arg); \
dump_entry_trace(entry); \ dump_entry_trace(entry); \
...@@ -520,7 +522,7 @@ static void active_cacheline_inc_overlap(phys_addr_t cln) ...@@ -520,7 +522,7 @@ static void active_cacheline_inc_overlap(phys_addr_t cln)
* prematurely. * prematurely.
*/ */
WARN_ONCE(overlap > ACTIVE_CACHELINE_MAX_OVERLAP, WARN_ONCE(overlap > ACTIVE_CACHELINE_MAX_OVERLAP,
"DMA-API: exceeded %d overlapping mappings of cacheline %pa\n", pr_fmt("exceeded %d overlapping mappings of cacheline %pa\n"),
ACTIVE_CACHELINE_MAX_OVERLAP, &cln); ACTIVE_CACHELINE_MAX_OVERLAP, &cln);
} }
...@@ -615,7 +617,7 @@ void debug_dma_assert_idle(struct page *page) ...@@ -615,7 +617,7 @@ void debug_dma_assert_idle(struct page *page)
cln = to_cacheline_number(entry); cln = to_cacheline_number(entry);
err_printk(entry->dev, entry, err_printk(entry->dev, entry,
"DMA-API: cpu touching an active dma mapped cacheline [cln=%pa]\n", "cpu touching an active dma mapped cacheline [cln=%pa]\n",
&cln); &cln);
} }
...@@ -635,7 +637,7 @@ static void add_dma_entry(struct dma_debug_entry *entry) ...@@ -635,7 +637,7 @@ static void add_dma_entry(struct dma_debug_entry *entry)
rc = active_cacheline_insert(entry); rc = active_cacheline_insert(entry);
if (rc == -ENOMEM) { if (rc == -ENOMEM) {
pr_err("DMA-API: cacheline tracking ENOMEM, dma-debug disabled\n"); pr_err("cacheline tracking ENOMEM, dma-debug disabled\n");
global_disable = true; global_disable = true;
} }
...@@ -674,7 +676,7 @@ static struct dma_debug_entry *dma_entry_alloc(void) ...@@ -674,7 +676,7 @@ static struct dma_debug_entry *dma_entry_alloc(void)
if (list_empty(&free_entries)) { if (list_empty(&free_entries)) {
global_disable = true; global_disable = true;
spin_unlock_irqrestore(&free_entries_lock, flags); spin_unlock_irqrestore(&free_entries_lock, flags);
pr_err("DMA-API: debugging out of memory - disabling\n"); pr_err("debugging out of memory - disabling\n");
return NULL; return NULL;
} }
...@@ -778,7 +780,7 @@ static int prealloc_memory(u32 num_entries) ...@@ -778,7 +780,7 @@ static int prealloc_memory(u32 num_entries)
num_free_entries = num_entries; num_free_entries = num_entries;
min_free_entries = num_entries; min_free_entries = num_entries;
pr_info("DMA-API: preallocated %d debug entries\n", num_entries); pr_info("preallocated %d debug entries\n", num_entries);
return 0; return 0;
...@@ -851,7 +853,7 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf, ...@@ -851,7 +853,7 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf,
* switched off. * switched off.
*/ */
if (current_driver_name[0]) if (current_driver_name[0])
pr_info("DMA-API: switching off dma-debug driver filter\n"); pr_info("switching off dma-debug driver filter\n");
current_driver_name[0] = 0; current_driver_name[0] = 0;
current_driver = NULL; current_driver = NULL;
goto out_unlock; goto out_unlock;
...@@ -869,7 +871,7 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf, ...@@ -869,7 +871,7 @@ static ssize_t filter_write(struct file *file, const char __user *userbuf,
current_driver_name[i] = 0; current_driver_name[i] = 0;
current_driver = NULL; current_driver = NULL;
pr_info("DMA-API: enable driver filter for driver [%s]\n", pr_info("enable driver filter for driver [%s]\n",
current_driver_name); current_driver_name);
out_unlock: out_unlock:
...@@ -888,7 +890,7 @@ static int dma_debug_fs_init(void) ...@@ -888,7 +890,7 @@ static int dma_debug_fs_init(void)
{ {
dma_debug_dent = debugfs_create_dir("dma-api", NULL); dma_debug_dent = debugfs_create_dir("dma-api", NULL);
if (!dma_debug_dent) { if (!dma_debug_dent) {
pr_err("DMA-API: can not create debugfs directory\n"); pr_err("can not create debugfs directory\n");
return -ENOMEM; return -ENOMEM;
} }
...@@ -980,7 +982,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti ...@@ -980,7 +982,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
count = device_dma_allocations(dev, &entry); count = device_dma_allocations(dev, &entry);
if (count == 0) if (count == 0)
break; break;
err_printk(dev, entry, "DMA-API: device driver has pending " err_printk(dev, entry, "device driver has pending "
"DMA allocations while released from device " "DMA allocations while released from device "
"[count=%d]\n" "[count=%d]\n"
"One of leaked entries details: " "One of leaked entries details: "
...@@ -1030,14 +1032,14 @@ static int dma_debug_init(void) ...@@ -1030,14 +1032,14 @@ static int dma_debug_init(void)
} }
if (dma_debug_fs_init() != 0) { if (dma_debug_fs_init() != 0) {
pr_err("DMA-API: error creating debugfs entries - disabling\n"); pr_err("error creating debugfs entries - disabling\n");
global_disable = true; global_disable = true;
return 0; return 0;
} }
if (prealloc_memory(nr_prealloc_entries) != 0) { if (prealloc_memory(nr_prealloc_entries) != 0) {
pr_err("DMA-API: debugging out of memory error - disabled\n"); pr_err("debugging out of memory error - disabled\n");
global_disable = true; global_disable = true;
return 0; return 0;
...@@ -1047,7 +1049,7 @@ static int dma_debug_init(void) ...@@ -1047,7 +1049,7 @@ static int dma_debug_init(void)
dma_debug_initialized = true; dma_debug_initialized = true;
pr_info("DMA-API: debugging enabled by kernel config\n"); pr_info("debugging enabled by kernel config\n");
return 0; return 0;
} }
core_initcall(dma_debug_init); core_initcall(dma_debug_init);
...@@ -1058,7 +1060,7 @@ static __init int dma_debug_cmdline(char *str) ...@@ -1058,7 +1060,7 @@ static __init int dma_debug_cmdline(char *str)
return -EINVAL; return -EINVAL;
if (strncmp(str, "off", 3) == 0) { if (strncmp(str, "off", 3) == 0) {
pr_info("DMA-API: debugging disabled on kernel command line\n"); pr_info("debugging disabled on kernel command line\n");
global_disable = true; global_disable = true;
} }
...@@ -1092,11 +1094,11 @@ static void check_unmap(struct dma_debug_entry *ref) ...@@ -1092,11 +1094,11 @@ static void check_unmap(struct dma_debug_entry *ref)
if (dma_mapping_error(ref->dev, ref->dev_addr)) { if (dma_mapping_error(ref->dev, ref->dev_addr)) {
err_printk(ref->dev, NULL, err_printk(ref->dev, NULL,
"DMA-API: device driver tries to free an " "device driver tries to free an "
"invalid DMA memory address\n"); "invalid DMA memory address\n");
} else { } else {
err_printk(ref->dev, NULL, err_printk(ref->dev, NULL,
"DMA-API: device driver tries to free DMA " "device driver tries to free DMA "
"memory it has not allocated [device " "memory it has not allocated [device "
"address=0x%016llx] [size=%llu bytes]\n", "address=0x%016llx] [size=%llu bytes]\n",
ref->dev_addr, ref->size); ref->dev_addr, ref->size);
...@@ -1105,7 +1107,7 @@ static void check_unmap(struct dma_debug_entry *ref) ...@@ -1105,7 +1107,7 @@ static void check_unmap(struct dma_debug_entry *ref)
} }
if (ref->size != entry->size) { if (ref->size != entry->size) {
err_printk(ref->dev, entry, "DMA-API: device driver frees " err_printk(ref->dev, entry, "device driver frees "
"DMA memory with different size " "DMA memory with different size "
"[device address=0x%016llx] [map size=%llu bytes] " "[device address=0x%016llx] [map size=%llu bytes] "
"[unmap size=%llu bytes]\n", "[unmap size=%llu bytes]\n",
...@@ -1113,7 +1115,7 @@ static void check_unmap(struct dma_debug_entry *ref) ...@@ -1113,7 +1115,7 @@ static void check_unmap(struct dma_debug_entry *ref)
} }
if (ref->type != entry->type) { if (ref->type != entry->type) {
err_printk(ref->dev, entry, "DMA-API: device driver frees " err_printk(ref->dev, entry, "device driver frees "
"DMA memory with wrong function " "DMA memory with wrong function "
"[device address=0x%016llx] [size=%llu bytes] " "[device address=0x%016llx] [size=%llu bytes] "
"[mapped as %s] [unmapped as %s]\n", "[mapped as %s] [unmapped as %s]\n",
...@@ -1121,7 +1123,7 @@ static void check_unmap(struct dma_debug_entry *ref) ...@@ -1121,7 +1123,7 @@ static void check_unmap(struct dma_debug_entry *ref)
type2name[entry->type], type2name[ref->type]); type2name[entry->type], type2name[ref->type]);
} else if ((entry->type == dma_debug_coherent) && } else if ((entry->type == dma_debug_coherent) &&
(phys_addr(ref) != phys_addr(entry))) { (phys_addr(ref) != phys_addr(entry))) {
err_printk(ref->dev, entry, "DMA-API: device driver frees " err_printk(ref->dev, entry, "device driver frees "
"DMA memory with different CPU address " "DMA memory with different CPU address "
"[device address=0x%016llx] [size=%llu bytes] " "[device address=0x%016llx] [size=%llu bytes] "
"[cpu alloc address=0x%016llx] " "[cpu alloc address=0x%016llx] "
...@@ -1133,7 +1135,7 @@ static void check_unmap(struct dma_debug_entry *ref) ...@@ -1133,7 +1135,7 @@ static void check_unmap(struct dma_debug_entry *ref)
if (ref->sg_call_ents && ref->type == dma_debug_sg && if (ref->sg_call_ents && ref->type == dma_debug_sg &&
ref->sg_call_ents != entry->sg_call_ents) { ref->sg_call_ents != entry->sg_call_ents) {
err_printk(ref->dev, entry, "DMA-API: device driver frees " err_printk(ref->dev, entry, "device driver frees "
"DMA sg list with different entry count " "DMA sg list with different entry count "
"[map count=%d] [unmap count=%d]\n", "[map count=%d] [unmap count=%d]\n",
entry->sg_call_ents, ref->sg_call_ents); entry->sg_call_ents, ref->sg_call_ents);
...@@ -1144,7 +1146,7 @@ static void check_unmap(struct dma_debug_entry *ref) ...@@ -1144,7 +1146,7 @@ static void check_unmap(struct dma_debug_entry *ref)
* DMA API don't handle this properly, so check for it here * DMA API don't handle this properly, so check for it here
*/ */
if (ref->direction != entry->direction) { if (ref->direction != entry->direction) {
err_printk(ref->dev, entry, "DMA-API: device driver frees " err_printk(ref->dev, entry, "device driver frees "
"DMA memory with different direction " "DMA memory with different direction "
"[device address=0x%016llx] [size=%llu bytes] " "[device address=0x%016llx] [size=%llu bytes] "
"[mapped with %s] [unmapped with %s]\n", "[mapped with %s] [unmapped with %s]\n",
...@@ -1160,7 +1162,7 @@ static void check_unmap(struct dma_debug_entry *ref) ...@@ -1160,7 +1162,7 @@ static void check_unmap(struct dma_debug_entry *ref)
*/ */
if (entry->map_err_type == MAP_ERR_NOT_CHECKED) { if (entry->map_err_type == MAP_ERR_NOT_CHECKED) {
err_printk(ref->dev, entry, err_printk(ref->dev, entry,
"DMA-API: device driver failed to check map error" "device driver failed to check map error"
"[device address=0x%016llx] [size=%llu bytes] " "[device address=0x%016llx] [size=%llu bytes] "
"[mapped as %s]", "[mapped as %s]",
ref->dev_addr, ref->size, ref->dev_addr, ref->size,
...@@ -1185,7 +1187,7 @@ static void check_for_stack(struct device *dev, ...@@ -1185,7 +1187,7 @@ static void check_for_stack(struct device *dev,
return; return;
addr = page_address(page) + offset; addr = page_address(page) + offset;
if (object_is_on_stack(addr)) if (object_is_on_stack(addr))
err_printk(dev, NULL, "DMA-API: device driver maps memory from stack [addr=%p]\n", addr); err_printk(dev, NULL, "device driver maps memory from stack [addr=%p]\n", addr);
} else { } else {
/* Stack is vmalloced. */ /* Stack is vmalloced. */
int i; int i;
...@@ -1195,7 +1197,7 @@ static void check_for_stack(struct device *dev, ...@@ -1195,7 +1197,7 @@ static void check_for_stack(struct device *dev,
continue; continue;
addr = (u8 *)current->stack + i * PAGE_SIZE + offset; addr = (u8 *)current->stack + i * PAGE_SIZE + offset;
err_printk(dev, NULL, "DMA-API: device driver maps memory from stack [probable addr=%p]\n", addr); err_printk(dev, NULL, "device driver maps memory from stack [probable addr=%p]\n", addr);
break; break;
} }
} }
...@@ -1215,7 +1217,7 @@ static void check_for_illegal_area(struct device *dev, void *addr, unsigned long ...@@ -1215,7 +1217,7 @@ static void check_for_illegal_area(struct device *dev, void *addr, unsigned long
{ {
if (overlap(addr, len, _stext, _etext) || if (overlap(addr, len, _stext, _etext) ||
overlap(addr, len, __start_rodata, __end_rodata)) overlap(addr, len, __start_rodata, __end_rodata))
err_printk(dev, NULL, "DMA-API: device driver maps memory from kernel text or rodata [addr=%p] [len=%lu]\n", addr, len); err_printk(dev, NULL, "device driver maps memory from kernel text or rodata [addr=%p] [len=%lu]\n", addr, len);
} }
static void check_sync(struct device *dev, static void check_sync(struct device *dev,
...@@ -1231,7 +1233,7 @@ static void check_sync(struct device *dev, ...@@ -1231,7 +1233,7 @@ static void check_sync(struct device *dev,
entry = bucket_find_contain(&bucket, ref, &flags); entry = bucket_find_contain(&bucket, ref, &flags);
if (!entry) { if (!entry) {
err_printk(dev, NULL, "DMA-API: device driver tries " err_printk(dev, NULL, "device driver tries "
"to sync DMA memory it has not allocated " "to sync DMA memory it has not allocated "
"[device address=0x%016llx] [size=%llu bytes]\n", "[device address=0x%016llx] [size=%llu bytes]\n",
(unsigned long long)ref->dev_addr, ref->size); (unsigned long long)ref->dev_addr, ref->size);
...@@ -1239,7 +1241,7 @@ static void check_sync(struct device *dev, ...@@ -1239,7 +1241,7 @@ static void check_sync(struct device *dev,
} }
if (ref->size > entry->size) { if (ref->size > entry->size) {
err_printk(dev, entry, "DMA-API: device driver syncs" err_printk(dev, entry, "device driver syncs"
" DMA memory outside allocated range " " DMA memory outside allocated range "
"[device address=0x%016llx] " "[device address=0x%016llx] "
"[allocation size=%llu bytes] " "[allocation size=%llu bytes] "
...@@ -1252,7 +1254,7 @@ static void check_sync(struct device *dev, ...@@ -1252,7 +1254,7 @@ static void check_sync(struct device *dev,
goto out; goto out;
if (ref->direction != entry->direction) { if (ref->direction != entry->direction) {
err_printk(dev, entry, "DMA-API: device driver syncs " err_printk(dev, entry, "device driver syncs "
"DMA memory with different direction " "DMA memory with different direction "
"[device address=0x%016llx] [size=%llu bytes] " "[device address=0x%016llx] [size=%llu bytes] "
"[mapped with %s] [synced with %s]\n", "[mapped with %s] [synced with %s]\n",
...@@ -1263,7 +1265,7 @@ static void check_sync(struct device *dev, ...@@ -1263,7 +1265,7 @@ static void check_sync(struct device *dev,
if (to_cpu && !(entry->direction == DMA_FROM_DEVICE) && if (to_cpu && !(entry->direction == DMA_FROM_DEVICE) &&
!(ref->direction == DMA_TO_DEVICE)) !(ref->direction == DMA_TO_DEVICE))
err_printk(dev, entry, "DMA-API: device driver syncs " err_printk(dev, entry, "device driver syncs "
"device read-only DMA memory for cpu " "device read-only DMA memory for cpu "
"[device address=0x%016llx] [size=%llu bytes] " "[device address=0x%016llx] [size=%llu bytes] "
"[mapped with %s] [synced with %s]\n", "[mapped with %s] [synced with %s]\n",
...@@ -1273,7 +1275,7 @@ static void check_sync(struct device *dev, ...@@ -1273,7 +1275,7 @@ static void check_sync(struct device *dev,
if (!to_cpu && !(entry->direction == DMA_TO_DEVICE) && if (!to_cpu && !(entry->direction == DMA_TO_DEVICE) &&
!(ref->direction == DMA_FROM_DEVICE)) !(ref->direction == DMA_FROM_DEVICE))
err_printk(dev, entry, "DMA-API: device driver syncs " err_printk(dev, entry, "device driver syncs "
"device write-only DMA memory to device " "device write-only DMA memory to device "
"[device address=0x%016llx] [size=%llu bytes] " "[device address=0x%016llx] [size=%llu bytes] "
"[mapped with %s] [synced with %s]\n", "[mapped with %s] [synced with %s]\n",
...@@ -1283,7 +1285,7 @@ static void check_sync(struct device *dev, ...@@ -1283,7 +1285,7 @@ static void check_sync(struct device *dev,
if (ref->sg_call_ents && ref->type == dma_debug_sg && if (ref->sg_call_ents && ref->type == dma_debug_sg &&
ref->sg_call_ents != entry->sg_call_ents) { ref->sg_call_ents != entry->sg_call_ents) {
err_printk(ref->dev, entry, "DMA-API: device driver syncs " err_printk(ref->dev, entry, "device driver syncs "
"DMA sg list with different entry count " "DMA sg list with different entry count "
"[map count=%d] [sync count=%d]\n", "[map count=%d] [sync count=%d]\n",
entry->sg_call_ents, ref->sg_call_ents); entry->sg_call_ents, ref->sg_call_ents);
...@@ -1304,7 +1306,7 @@ static void check_sg_segment(struct device *dev, struct scatterlist *sg) ...@@ -1304,7 +1306,7 @@ static void check_sg_segment(struct device *dev, struct scatterlist *sg)
* whoever generated the list forgot to check them. * whoever generated the list forgot to check them.
*/ */
if (sg->length > max_seg) if (sg->length > max_seg)
err_printk(dev, NULL, "DMA-API: mapping sg segment longer than device claims to support [len=%u] [max=%u]\n", err_printk(dev, NULL, "mapping sg segment longer than device claims to support [len=%u] [max=%u]\n",
sg->length, max_seg); sg->length, max_seg);
/* /*
* In some cases this could potentially be the DMA API * In some cases this could potentially be the DMA API
...@@ -1314,7 +1316,7 @@ static void check_sg_segment(struct device *dev, struct scatterlist *sg) ...@@ -1314,7 +1316,7 @@ static void check_sg_segment(struct device *dev, struct scatterlist *sg)
start = sg_dma_address(sg); start = sg_dma_address(sg);
end = start + sg_dma_len(sg) - 1; end = start + sg_dma_len(sg) - 1;
if ((start ^ end) & ~boundary) if ((start ^ end) & ~boundary)
err_printk(dev, NULL, "DMA-API: mapping sg segment across boundary [start=0x%016llx] [end=0x%016llx] [boundary=0x%016llx]\n", err_printk(dev, NULL, "mapping sg segment across boundary [start=0x%016llx] [end=0x%016llx] [boundary=0x%016llx]\n",
start, end, boundary); start, end, boundary);
#endif #endif
} }
...@@ -1326,11 +1328,11 @@ void debug_dma_map_single(struct device *dev, const void *addr, ...@@ -1326,11 +1328,11 @@ void debug_dma_map_single(struct device *dev, const void *addr,
return; return;
if (!virt_addr_valid(addr)) if (!virt_addr_valid(addr))
err_printk(dev, NULL, "DMA-API: device driver maps memory from invalid area [addr=%p] [len=%lu]\n", err_printk(dev, NULL, "device driver maps memory from invalid area [addr=%p] [len=%lu]\n",
addr, len); addr, len);
if (is_vmalloc_addr(addr)) if (is_vmalloc_addr(addr))
err_printk(dev, NULL, "DMA-API: device driver maps memory from vmalloc area [addr=%p] [len=%lu]\n", err_printk(dev, NULL, "device driver maps memory from vmalloc area [addr=%p] [len=%lu]\n",
addr, len); addr, len);
} }
EXPORT_SYMBOL(debug_dma_map_single); EXPORT_SYMBOL(debug_dma_map_single);
...@@ -1787,7 +1789,7 @@ static int __init dma_debug_driver_setup(char *str) ...@@ -1787,7 +1789,7 @@ static int __init dma_debug_driver_setup(char *str)
} }
if (current_driver_name[0]) if (current_driver_name[0])
pr_info("DMA-API: enable driver filter for driver [%s]\n", pr_info("enable driver filter for driver [%s]\n",
current_driver_name); current_driver_name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment