swiotlb: fix passing local variable to debugfs_create_ulong()
authorTianyu Lan <tiala@microsoft.com>
Thu, 28 Jul 2022 07:24:20 +0000 (03:24 -0400)
committerChristoph Hellwig <hch@lst.de>
Thu, 28 Jul 2022 14:23:30 +0000 (07:23 -0700)
Debugfs node will be run-timely checked and so local variable
should be not passed to debugfs_create_ulong(). Fix it via
debugfs_create_file() to create io_tlb_used node and calculate
used io tlb number with fops_io_tlb_used attribute.

Fixes: 20347fca71a3 ("swiotlb: split up the global swiotlb lock")
Signed-off-by: Tianyu Lan <tiala@microsoft.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
kernel/dma/swiotlb.c

index cc50f1fb127ffc6b578fb9804568db28cd4a51c2..c5a9190b218f959d3a050e23fc25472ab8fbfeb5 100644 (file)
@@ -912,17 +912,23 @@ bool is_swiotlb_active(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(is_swiotlb_active);
 
+static int io_tlb_used_get(void *data, u64 *val)
+{
+       *val = mem_used(&io_tlb_default_mem);
+       return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(fops_io_tlb_used, io_tlb_used_get, NULL, "%llu\n");
+
 static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem,
                                         const char *dirname)
 {
-       unsigned long used = mem_used(mem);
-
        mem->debugfs = debugfs_create_dir(dirname, io_tlb_default_mem.debugfs);
        if (!mem->nslabs)
                return;
 
        debugfs_create_ulong("io_tlb_nslabs", 0400, mem->debugfs, &mem->nslabs);
-       debugfs_create_ulong("io_tlb_used", 0400, mem->debugfs, &used);
+       debugfs_create_file("io_tlb_used", 0400, mem->debugfs, NULL,
+                       &fops_io_tlb_used);
 }
 
 static int __init __maybe_unused swiotlb_create_default_debugfs(void)