| .. | .. |
|---|
| 1 | 1 | // 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: |
|---|
| 3 | 3 | * |
|---|
| 4 | 4 | * 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/>. |
|---|
| 17 | 5 | */ |
|---|
| 18 | 6 | |
|---|
| 19 | 7 | #include "log.h" |
|---|
| .. | .. |
|---|
| 39 | 27 | #include <linux/uaccess.h> |
|---|
| 40 | 28 | #include <linux/wait.h> |
|---|
| 41 | 29 | #include <stdarg.h> |
|---|
| 30 | + |
|---|
| 31 | +#include "debugfs.h" |
|---|
| 32 | +#include "trace.h" |
|---|
| 33 | + |
|---|
| 34 | +#ifdef CONFIG_BATMAN_ADV_DEBUGFS |
|---|
| 42 | 35 | |
|---|
| 43 | 36 | #define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1) |
|---|
| 44 | 37 | |
|---|
| .. | .. |
|---|
| 89 | 82 | return 0; |
|---|
| 90 | 83 | } |
|---|
| 91 | 84 | |
|---|
| 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 | | - |
|---|
| 113 | 85 | static int batadv_log_open(struct inode *inode, struct file *file) |
|---|
| 114 | 86 | { |
|---|
| 115 | 87 | if (!try_module_get(THIS_MODULE)) |
|---|
| 116 | 88 | return -EBUSY; |
|---|
| 117 | 89 | |
|---|
| 118 | | - nonseekable_open(inode, file); |
|---|
| 90 | + batadv_debugfs_deprecated(file, |
|---|
| 91 | + "Use tracepoint batadv:batadv_dbg instead\n"); |
|---|
| 92 | + |
|---|
| 93 | + stream_open(inode, file); |
|---|
| 119 | 94 | file->private_data = inode->i_private; |
|---|
| 120 | 95 | return 0; |
|---|
| 121 | 96 | } |
|---|
| .. | .. |
|---|
| 149 | 124 | if (count == 0) |
|---|
| 150 | 125 | return 0; |
|---|
| 151 | 126 | |
|---|
| 152 | | - if (!access_ok(VERIFY_WRITE, buf, count)) |
|---|
| 127 | + if (!access_ok(buf, count)) |
|---|
| 153 | 128 | return -EFAULT; |
|---|
| 154 | 129 | |
|---|
| 155 | 130 | error = wait_event_interruptible(debug_log->queue_wait, |
|---|
| .. | .. |
|---|
| 216 | 191 | */ |
|---|
| 217 | 192 | int batadv_debug_log_setup(struct batadv_priv *bat_priv) |
|---|
| 218 | 193 | { |
|---|
| 219 | | - struct dentry *d; |
|---|
| 220 | | - |
|---|
| 221 | | - if (!bat_priv->debug_dir) |
|---|
| 222 | | - goto err; |
|---|
| 223 | | - |
|---|
| 224 | 194 | bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC); |
|---|
| 225 | 195 | if (!bat_priv->debug_log) |
|---|
| 226 | | - goto err; |
|---|
| 196 | + return -ENOMEM; |
|---|
| 227 | 197 | |
|---|
| 228 | 198 | spin_lock_init(&bat_priv->debug_log->lock); |
|---|
| 229 | 199 | init_waitqueue_head(&bat_priv->debug_log->queue_wait); |
|---|
| 230 | 200 | |
|---|
| 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); |
|---|
| 236 | 203 | return 0; |
|---|
| 237 | | - |
|---|
| 238 | | -err: |
|---|
| 239 | | - return -ENOMEM; |
|---|
| 240 | 204 | } |
|---|
| 241 | 205 | |
|---|
| 242 | 206 | /** |
|---|
| .. | .. |
|---|
| 248 | 212 | kfree(bat_priv->debug_log); |
|---|
| 249 | 213 | bat_priv->debug_log = NULL; |
|---|
| 250 | 214 | } |
|---|
| 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 | +} |
|---|