hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/iommu/omap-iommu-debug.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * omap iommu: debugfs interface
34 *
45 * Copyright (C) 2008-2009 Nokia Corporation
56 *
67 * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/err.h>
....@@ -35,12 +32,12 @@
3532 ssize_t bytes; \
3633 const char *str = "%20s: %08x\n"; \
3734 const int maxcol = 32; \
38
- bytes = snprintf(p, maxcol, str, __stringify(name), \
35
+ if (len < maxcol) \
36
+ goto out; \
37
+ bytes = scnprintf(p, maxcol, str, __stringify(name), \
3938 iommu_read_reg(obj, MMU_##name)); \
4039 p += bytes; \
4140 len -= bytes; \
42
- if (len < maxcol) \
43
- goto out; \
4441 } while (0)
4542
4643 static ssize_t
....@@ -162,7 +159,7 @@
162159 return 0;
163160 }
164161
165
-static int debug_read_tlb(struct seq_file *s, void *data)
162
+static int tlb_show(struct seq_file *s, void *data)
166163 {
167164 struct omap_iommu *obj = s->private;
168165
....@@ -213,7 +210,7 @@
213210 spin_unlock(&obj->page_table_lock);
214211 }
215212
216
-static int debug_read_pagetable(struct seq_file *s, void *data)
213
+static int pagetable_show(struct seq_file *s, void *data)
217214 {
218215 struct omap_iommu *obj = s->private;
219216
....@@ -231,40 +228,16 @@
231228 return 0;
232229 }
233230
234
-#define DEBUG_SEQ_FOPS_RO(name) \
235
- static int debug_open_##name(struct inode *inode, struct file *file) \
236
- { \
237
- return single_open(file, debug_read_##name, inode->i_private); \
238
- } \
239
- \
240
- static const struct file_operations debug_##name##_fops = { \
241
- .open = debug_open_##name, \
242
- .read = seq_read, \
243
- .llseek = seq_lseek, \
244
- .release = single_release, \
245
- }
246
-
247231 #define DEBUG_FOPS_RO(name) \
248
- static const struct file_operations debug_##name##_fops = { \
232
+ static const struct file_operations name##_fops = { \
249233 .open = simple_open, \
250234 .read = debug_read_##name, \
251235 .llseek = generic_file_llseek, \
252236 }
253237
254238 DEBUG_FOPS_RO(regs);
255
-DEBUG_SEQ_FOPS_RO(tlb);
256
-DEBUG_SEQ_FOPS_RO(pagetable);
257
-
258
-#define __DEBUG_ADD_FILE(attr, mode) \
259
- { \
260
- struct dentry *dent; \
261
- dent = debugfs_create_file(#attr, mode, obj->debug_dir, \
262
- obj, &debug_##attr##_fops); \
263
- if (!dent) \
264
- goto err; \
265
- }
266
-
267
-#define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400)
239
+DEFINE_SHOW_ATTRIBUTE(tlb);
240
+DEFINE_SHOW_ATTRIBUTE(pagetable);
268241
269242 void omap_iommu_debugfs_add(struct omap_iommu *obj)
270243 {
....@@ -273,23 +246,13 @@
273246 if (!iommu_debug_root)
274247 return;
275248
276
- obj->debug_dir = debugfs_create_dir(obj->name, iommu_debug_root);
277
- if (!obj->debug_dir)
278
- return;
249
+ d = debugfs_create_dir(obj->name, iommu_debug_root);
250
+ obj->debug_dir = d;
279251
280
- d = debugfs_create_u32("nr_tlb_entries", 0400, obj->debug_dir,
281
- &obj->nr_tlb_entries);
282
- if (!d)
283
- return;
284
-
285
- DEBUG_ADD_FILE_RO(regs);
286
- DEBUG_ADD_FILE_RO(tlb);
287
- DEBUG_ADD_FILE_RO(pagetable);
288
-
289
- return;
290
-
291
-err:
292
- debugfs_remove_recursive(obj->debug_dir);
252
+ debugfs_create_u32("nr_tlb_entries", 0400, d, &obj->nr_tlb_entries);
253
+ debugfs_create_file("regs", 0400, d, obj, &regs_fops);
254
+ debugfs_create_file("tlb", 0400, d, obj, &tlb_fops);
255
+ debugfs_create_file("pagetable", 0400, d, obj, &pagetable_fops);
293256 }
294257
295258 void omap_iommu_debugfs_remove(struct omap_iommu *obj)
....@@ -303,8 +266,6 @@
303266 void __init omap_iommu_debugfs_init(void)
304267 {
305268 iommu_debug_root = debugfs_create_dir("omap_iommu", NULL);
306
- if (!iommu_debug_root)
307
- pr_err("can't create debugfs dir\n");
308269 }
309270
310271 void __exit omap_iommu_debugfs_exit(void)