| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Linux WiMAX |
|---|
| 3 | 4 | * Collection of tools to manage debug operations. |
|---|
| 4 | 5 | * |
|---|
| 5 | | - * |
|---|
| 6 | 6 | * Copyright (C) 2005-2007 Intel Corporation |
|---|
| 7 | 7 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> |
|---|
| 8 | 8 | * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or |
|---|
| 10 | | - * modify it under the terms of the GNU General Public License version |
|---|
| 11 | | - * 2 as published by the Free Software Foundation. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | | - * |
|---|
| 18 | | - * You should have received a copy of the GNU General Public License |
|---|
| 19 | | - * along with this program; if not, write to the Free Software |
|---|
| 20 | | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|---|
| 21 | | - * 02110-1301, USA. |
|---|
| 22 | | - * |
|---|
| 23 | | - * |
|---|
| 24 | 9 | * Don't #include this file directly, read on! |
|---|
| 25 | | - * |
|---|
| 26 | 10 | * |
|---|
| 27 | 11 | * EXECUTING DEBUGGING ACTIONS OR NOT |
|---|
| 28 | 12 | * |
|---|
| .. | .. |
|---|
| 43 | 27 | * always false at compile time will get the code depending on it |
|---|
| 44 | 28 | * compiled out by optimization. |
|---|
| 45 | 29 | * |
|---|
| 46 | | - * |
|---|
| 47 | 30 | * DEBUG LEVELS |
|---|
| 48 | 31 | * |
|---|
| 49 | 32 | * It is up to the caller to define how much a debugging level is. |
|---|
| .. | .. |
|---|
| 52 | 35 | * will always be taken). The increasing debug levels are used for |
|---|
| 53 | 36 | * increased verbosity. |
|---|
| 54 | 37 | * |
|---|
| 55 | | - * |
|---|
| 56 | 38 | * USAGE |
|---|
| 57 | 39 | * |
|---|
| 58 | 40 | * Group the code in modules and submodules inside each module [which |
|---|
| 59 | 41 | * in most cases maps to Linux modules and .c files that compose |
|---|
| 60 | 42 | * those]. |
|---|
| 61 | | - * |
|---|
| 62 | 43 | * |
|---|
| 63 | 44 | * For each module, there is: |
|---|
| 64 | 45 | * |
|---|
| .. | .. |
|---|
| 117 | 98 | * To manipulate from user space the levels, create a debugfs dentry |
|---|
| 118 | 99 | * and then register each submodule with: |
|---|
| 119 | 100 | * |
|---|
| 120 | | - * result = d_level_register_debugfs("PREFIX_", submodule_X, parent); |
|---|
| 121 | | - * if (result < 0) |
|---|
| 122 | | - * goto error; |
|---|
| 101 | + * d_level_register_debugfs("PREFIX_", submodule_X, parent); |
|---|
| 123 | 102 | * |
|---|
| 124 | 103 | * Where PREFIX_ is a name of your chosing. This will create debugfs |
|---|
| 125 | 104 | * file with a single numeric value that can be use to tweak it. To |
|---|
| .. | .. |
|---|
| 128 | 107 | * NOTE: remember that even if this will show attached to some |
|---|
| 129 | 108 | * particular instance of a device, the settings are *global*. |
|---|
| 130 | 109 | * |
|---|
| 131 | | - * |
|---|
| 132 | 110 | * On each submodule (for example, .c files), the debug infrastructure |
|---|
| 133 | 111 | * should be included like this: |
|---|
| 134 | 112 | * |
|---|
| .. | .. |
|---|
| 136 | 114 | * #include "debug-levels.h" |
|---|
| 137 | 115 | * |
|---|
| 138 | 116 | * after #including all your include files. |
|---|
| 139 | | - * |
|---|
| 140 | 117 | * |
|---|
| 141 | 118 | * Now you can use the d_*() macros below [d_test(), d_fnstart(), |
|---|
| 142 | 119 | * d_fnend(), d_printf(), d_dump()]. |
|---|
| .. | .. |
|---|
| 207 | 184 | |
|---|
| 208 | 185 | |
|---|
| 209 | 186 | /* |
|---|
| 210 | | - * CPP sintatic sugar to generate A_B like symbol names when one of |
|---|
| 211 | | - * the arguments is a a preprocessor #define. |
|---|
| 187 | + * CPP syntactic sugar to generate A_B like symbol names when one of |
|---|
| 188 | + * the arguments is a preprocessor #define. |
|---|
| 212 | 189 | */ |
|---|
| 213 | 190 | #define __D_PASTE__(varname, modulename) varname##_##modulename |
|---|
| 214 | 191 | #define __D_PASTE(varname, modulename) (__D_PASTE__(varname, modulename)) |
|---|
| .. | .. |
|---|
| 429 | 406 | * @submodule: name of submodule (not a string, just the name) |
|---|
| 430 | 407 | * @dentry: debugfs parent dentry |
|---|
| 431 | 408 | * |
|---|
| 432 | | - * Returns: 0 if ok, < 0 errno on error. |
|---|
| 433 | | - * |
|---|
| 434 | 409 | * For removing, just use debugfs_remove_recursive() on the parent. |
|---|
| 435 | 410 | */ |
|---|
| 436 | 411 | #define d_level_register_debugfs(prefix, name, parent) \ |
|---|
| 437 | 412 | ({ \ |
|---|
| 438 | | - int rc; \ |
|---|
| 439 | | - struct dentry *fd; \ |
|---|
| 440 | | - struct dentry *verify_parent_type = parent; \ |
|---|
| 441 | | - fd = debugfs_create_u8( \ |
|---|
| 442 | | - prefix #name, 0600, verify_parent_type, \ |
|---|
| 413 | + debugfs_create_u8( \ |
|---|
| 414 | + prefix #name, 0600, parent, \ |
|---|
| 443 | 415 | &(D_LEVEL[__D_SUBMODULE_ ## name].level)); \ |
|---|
| 444 | | - rc = PTR_ERR(fd); \ |
|---|
| 445 | | - if (IS_ERR(fd) && rc != -ENODEV) \ |
|---|
| 446 | | - printk(KERN_ERR "%s: Can't create debugfs entry %s: " \ |
|---|
| 447 | | - "%d\n", __func__, prefix #name, rc); \ |
|---|
| 448 | | - else \ |
|---|
| 449 | | - rc = 0; \ |
|---|
| 450 | | - rc; \ |
|---|
| 451 | 416 | }) |
|---|
| 452 | 417 | |
|---|
| 453 | 418 | |
|---|