hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/net/6lowpan/debugfs.c
....@@ -1,11 +1,5 @@
1
-/* This program is free software; you can redistribute it and/or modify
2
- * it under the terms of the GNU General Public License version 2
3
- * as published by the Free Software Foundation.
4
- *
5
- * This program is distributed in the hope that it will be useful,
6
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
7
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8
- * GNU General Public License for more details.
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+/*
93 *
104 * Authors:
115 * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de>
....@@ -41,9 +35,9 @@
4135 return 0;
4236 }
4337
44
-DEFINE_SIMPLE_ATTRIBUTE(lowpan_ctx_flag_active_fops,
45
- lowpan_ctx_flag_active_get,
46
- lowpan_ctx_flag_active_set, "%llu\n");
38
+DEFINE_DEBUGFS_ATTRIBUTE(lowpan_ctx_flag_active_fops,
39
+ lowpan_ctx_flag_active_get,
40
+ lowpan_ctx_flag_active_set, "%llu\n");
4741
4842 static int lowpan_ctx_flag_c_set(void *data, u64 val)
4943 {
....@@ -66,8 +60,8 @@
6660 return 0;
6761 }
6862
69
-DEFINE_SIMPLE_ATTRIBUTE(lowpan_ctx_flag_c_fops, lowpan_ctx_flag_c_get,
70
- lowpan_ctx_flag_c_set, "%llu\n");
63
+DEFINE_DEBUGFS_ATTRIBUTE(lowpan_ctx_flag_c_fops, lowpan_ctx_flag_c_get,
64
+ lowpan_ctx_flag_c_set, "%llu\n");
7165
7266 static int lowpan_ctx_plen_set(void *data, u64 val)
7367 {
....@@ -97,8 +91,8 @@
9791 return 0;
9892 }
9993
100
-DEFINE_SIMPLE_ATTRIBUTE(lowpan_ctx_plen_fops, lowpan_ctx_plen_get,
101
- lowpan_ctx_plen_set, "%llu\n");
94
+DEFINE_DEBUGFS_ATTRIBUTE(lowpan_ctx_plen_fops, lowpan_ctx_plen_get,
95
+ lowpan_ctx_plen_set, "%llu\n");
10296
10397 static int lowpan_ctx_pfx_show(struct seq_file *file, void *offset)
10498 {
....@@ -169,46 +163,31 @@
169163 .release = single_release,
170164 };
171165
172
-static int lowpan_dev_debugfs_ctx_init(struct net_device *dev,
173
- struct dentry *ctx, u8 id)
166
+static void lowpan_dev_debugfs_ctx_init(struct net_device *dev,
167
+ struct dentry *ctx, u8 id)
174168 {
175169 struct lowpan_dev *ldev = lowpan_dev(dev);
176
- struct dentry *dentry, *root;
170
+ struct dentry *root;
177171 char buf[32];
178172
179
- WARN_ON_ONCE(id > LOWPAN_IPHC_CTX_TABLE_SIZE);
173
+ if (WARN_ON_ONCE(id >= LOWPAN_IPHC_CTX_TABLE_SIZE))
174
+ return;
180175
181176 sprintf(buf, "%d", id);
182177
183178 root = debugfs_create_dir(buf, ctx);
184
- if (!root)
185
- return -EINVAL;
186179
187
- dentry = debugfs_create_file("active", 0644, root,
188
- &ldev->ctx.table[id],
189
- &lowpan_ctx_flag_active_fops);
190
- if (!dentry)
191
- return -EINVAL;
180
+ debugfs_create_file("active", 0644, root, &ldev->ctx.table[id],
181
+ &lowpan_ctx_flag_active_fops);
192182
193
- dentry = debugfs_create_file("compression", 0644, root,
194
- &ldev->ctx.table[id],
195
- &lowpan_ctx_flag_c_fops);
196
- if (!dentry)
197
- return -EINVAL;
183
+ debugfs_create_file("compression", 0644, root, &ldev->ctx.table[id],
184
+ &lowpan_ctx_flag_c_fops);
198185
199
- dentry = debugfs_create_file("prefix", 0644, root,
200
- &ldev->ctx.table[id],
201
- &lowpan_ctx_pfx_fops);
202
- if (!dentry)
203
- return -EINVAL;
186
+ debugfs_create_file("prefix", 0644, root, &ldev->ctx.table[id],
187
+ &lowpan_ctx_pfx_fops);
204188
205
- dentry = debugfs_create_file("prefix_len", 0644, root,
206
- &ldev->ctx.table[id],
207
- &lowpan_ctx_plen_fops);
208
- if (!dentry)
209
- return -EINVAL;
210
-
211
- return 0;
189
+ debugfs_create_file("prefix_len", 0644, root, &ldev->ctx.table[id],
190
+ &lowpan_ctx_plen_fops);
212191 }
213192
214193 static int lowpan_context_show(struct seq_file *file, void *offset)
....@@ -232,18 +211,7 @@
232211
233212 return 0;
234213 }
235
-
236
-static int lowpan_context_open(struct inode *inode, struct file *file)
237
-{
238
- return single_open(file, lowpan_context_show, inode->i_private);
239
-}
240
-
241
-static const struct file_operations lowpan_context_fops = {
242
- .open = lowpan_context_open,
243
- .read = seq_read,
244
- .llseek = seq_lseek,
245
- .release = single_release,
246
-};
214
+DEFINE_SHOW_ATTRIBUTE(lowpan_context);
247215
248216 static int lowpan_short_addr_get(void *data, u64 *val)
249217 {
....@@ -256,67 +224,42 @@
256224 return 0;
257225 }
258226
259
-DEFINE_SIMPLE_ATTRIBUTE(lowpan_short_addr_fops, lowpan_short_addr_get,
260
- NULL, "0x%04llx\n");
227
+DEFINE_DEBUGFS_ATTRIBUTE(lowpan_short_addr_fops, lowpan_short_addr_get, NULL,
228
+ "0x%04llx\n");
261229
262
-static int lowpan_dev_debugfs_802154_init(const struct net_device *dev,
230
+static void lowpan_dev_debugfs_802154_init(const struct net_device *dev,
263231 struct lowpan_dev *ldev)
264232 {
265
- struct dentry *dentry, *root;
233
+ struct dentry *root;
266234
267235 if (!lowpan_is_ll(dev, LOWPAN_LLTYPE_IEEE802154))
268
- return 0;
236
+ return;
269237
270238 root = debugfs_create_dir("ieee802154", ldev->iface_debugfs);
271
- if (!root)
272
- return -EINVAL;
273239
274
- dentry = debugfs_create_file("short_addr", 0444, root,
275
- lowpan_802154_dev(dev)->wdev->ieee802154_ptr,
276
- &lowpan_short_addr_fops);
277
- if (!dentry)
278
- return -EINVAL;
279
-
280
- return 0;
240
+ debugfs_create_file("short_addr", 0444, root,
241
+ lowpan_802154_dev(dev)->wdev->ieee802154_ptr,
242
+ &lowpan_short_addr_fops);
281243 }
282244
283
-int lowpan_dev_debugfs_init(struct net_device *dev)
245
+void lowpan_dev_debugfs_init(struct net_device *dev)
284246 {
285247 struct lowpan_dev *ldev = lowpan_dev(dev);
286
- struct dentry *contexts, *dentry;
287
- int ret, i;
248
+ struct dentry *contexts;
249
+ int i;
288250
289251 /* creating the root */
290252 ldev->iface_debugfs = debugfs_create_dir(dev->name, lowpan_debugfs);
291
- if (!ldev->iface_debugfs)
292
- goto fail;
293253
294254 contexts = debugfs_create_dir("contexts", ldev->iface_debugfs);
295
- if (!contexts)
296
- goto remove_root;
297255
298
- dentry = debugfs_create_file("show", 0644, contexts,
299
- &lowpan_dev(dev)->ctx,
300
- &lowpan_context_fops);
301
- if (!dentry)
302
- goto remove_root;
256
+ debugfs_create_file("show", 0644, contexts, &lowpan_dev(dev)->ctx,
257
+ &lowpan_context_fops);
303258
304
- for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++) {
305
- ret = lowpan_dev_debugfs_ctx_init(dev, contexts, i);
306
- if (ret < 0)
307
- goto remove_root;
308
- }
259
+ for (i = 0; i < LOWPAN_IPHC_CTX_TABLE_SIZE; i++)
260
+ lowpan_dev_debugfs_ctx_init(dev, contexts, i);
309261
310
- ret = lowpan_dev_debugfs_802154_init(dev, ldev);
311
- if (ret < 0)
312
- goto remove_root;
313
-
314
- return 0;
315
-
316
-remove_root:
317
- lowpan_dev_debugfs_exit(dev);
318
-fail:
319
- return -EINVAL;
262
+ lowpan_dev_debugfs_802154_init(dev, ldev);
320263 }
321264
322265 void lowpan_dev_debugfs_exit(struct net_device *dev)
....@@ -324,13 +267,9 @@
324267 debugfs_remove_recursive(lowpan_dev(dev)->iface_debugfs);
325268 }
326269
327
-int __init lowpan_debugfs_init(void)
270
+void __init lowpan_debugfs_init(void)
328271 {
329272 lowpan_debugfs = debugfs_create_dir("6lowpan", NULL);
330
- if (!lowpan_debugfs)
331
- return -EINVAL;
332
-
333
- return 0;
334273 }
335274
336275 void lowpan_debugfs_exit(void)