hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/batman-adv/log.c
....@@ -1,19 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/* Copyright (C) 2010-2018 B.A.T.M.A.N. contributors:
2
+/* Copyright (C) 2010-2020 B.A.T.M.A.N. contributors:
33 *
44 * Marek Lindner
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of version 2 of the GNU General Public
8
- * License as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful, but
11
- * WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
175 */
186
197 #include "log.h"
....@@ -39,6 +27,11 @@
3927 #include <linux/uaccess.h>
4028 #include <linux/wait.h>
4129 #include <stdarg.h>
30
+
31
+#include "debugfs.h"
32
+#include "trace.h"
33
+
34
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
4235
4336 #define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
4437
....@@ -89,33 +82,15 @@
8982 return 0;
9083 }
9184
92
-/**
93
- * batadv_debug_log() - Add debug log entry
94
- * @bat_priv: the bat priv with all the soft interface information
95
- * @fmt: format string
96
- *
97
- * Return: 0 on success or negative error number in case of failure
98
- */
99
-int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
100
-{
101
- va_list args;
102
- char tmp_log_buf[256];
103
-
104
- va_start(args, fmt);
105
- vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
106
- batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
107
- jiffies_to_msecs(jiffies), tmp_log_buf);
108
- va_end(args);
109
-
110
- return 0;
111
-}
112
-
11385 static int batadv_log_open(struct inode *inode, struct file *file)
11486 {
11587 if (!try_module_get(THIS_MODULE))
11688 return -EBUSY;
11789
118
- nonseekable_open(inode, file);
90
+ batadv_debugfs_deprecated(file,
91
+ "Use tracepoint batadv:batadv_dbg instead\n");
92
+
93
+ stream_open(inode, file);
11994 file->private_data = inode->i_private;
12095 return 0;
12196 }
....@@ -149,7 +124,7 @@
149124 if (count == 0)
150125 return 0;
151126
152
- if (!access_ok(VERIFY_WRITE, buf, count))
127
+ if (!access_ok(buf, count))
153128 return -EFAULT;
154129
155130 error = wait_event_interruptible(debug_log->queue_wait,
....@@ -216,27 +191,16 @@
216191 */
217192 int batadv_debug_log_setup(struct batadv_priv *bat_priv)
218193 {
219
- struct dentry *d;
220
-
221
- if (!bat_priv->debug_dir)
222
- goto err;
223
-
224194 bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
225195 if (!bat_priv->debug_log)
226
- goto err;
196
+ return -ENOMEM;
227197
228198 spin_lock_init(&bat_priv->debug_log->lock);
229199 init_waitqueue_head(&bat_priv->debug_log->queue_wait);
230200
231
- d = debugfs_create_file("log", 0400, bat_priv->debug_dir, bat_priv,
232
- &batadv_log_fops);
233
- if (!d)
234
- goto err;
235
-
201
+ debugfs_create_file("log", 0400, bat_priv->debug_dir, bat_priv,
202
+ &batadv_log_fops);
236203 return 0;
237
-
238
-err:
239
- return -ENOMEM;
240204 }
241205
242206 /**
....@@ -248,3 +212,34 @@
248212 kfree(bat_priv->debug_log);
249213 bat_priv->debug_log = NULL;
250214 }
215
+
216
+#endif /* CONFIG_BATMAN_ADV_DEBUGFS */
217
+
218
+/**
219
+ * batadv_debug_log() - Add debug log entry
220
+ * @bat_priv: the bat priv with all the soft interface information
221
+ * @fmt: format string
222
+ *
223
+ * Return: 0 on success or negative error number in case of failure
224
+ */
225
+int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
226
+{
227
+ struct va_format vaf;
228
+ va_list args;
229
+
230
+ va_start(args, fmt);
231
+
232
+ vaf.fmt = fmt;
233
+ vaf.va = &args;
234
+
235
+#ifdef CONFIG_BATMAN_ADV_DEBUGFS
236
+ batadv_fdebug_log(bat_priv->debug_log, "[%10u] %pV",
237
+ jiffies_to_msecs(jiffies), &vaf);
238
+#endif
239
+
240
+ trace_batadv_dbg(bat_priv, &vaf);
241
+
242
+ va_end(args);
243
+
244
+ return 0;
245
+}