2019-05-29 23:57:50 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2009-08-06 13:25:28 +00:00
|
|
|
/*
|
|
|
|
* This file is part of wl1271
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Nokia Corporation
|
|
|
|
*
|
|
|
|
* Contact: Luciano Coelho <luciano.coelho@nokia.com>
|
|
|
|
*/
|
|
|
|
|
2010-11-08 11:20:10 +00:00
|
|
|
#ifndef __DEBUGFS_H__
|
|
|
|
#define __DEBUGFS_H__
|
2009-08-06 13:25:28 +00:00
|
|
|
|
2011-11-21 17:25:24 +00:00
|
|
|
#include "wlcore.h"
|
2009-08-06 13:25:28 +00:00
|
|
|
|
2015-03-13 07:17:14 +00:00
|
|
|
__printf(4, 5) int wl1271_format_buffer(char __user *userbuf, size_t count,
|
|
|
|
loff_t *ppos, char *fmt, ...);
|
2012-05-10 09:14:06 +00:00
|
|
|
|
2009-08-06 13:25:28 +00:00
|
|
|
int wl1271_debugfs_init(struct wl1271 *wl);
|
|
|
|
void wl1271_debugfs_exit(struct wl1271 *wl);
|
|
|
|
void wl1271_debugfs_reset(struct wl1271 *wl);
|
2012-05-10 09:14:06 +00:00
|
|
|
void wl1271_debugfs_update_stats(struct wl1271 *wl);
|
|
|
|
|
2012-05-10 09:14:07 +00:00
|
|
|
#define DEBUGFS_FORMAT_BUFFER_SIZE 256
|
|
|
|
|
2012-05-10 09:14:06 +00:00
|
|
|
#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
|
|
|
|
static ssize_t name## _read(struct file *file, char __user *userbuf, \
|
|
|
|
size_t count, loff_t *ppos) \
|
|
|
|
{ \
|
|
|
|
struct wl1271 *wl = file->private_data; \
|
|
|
|
return wl1271_format_buffer(userbuf, count, ppos, \
|
|
|
|
fmt "\n", ##value); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static const struct file_operations name## _ops = { \
|
|
|
|
.read = name## _read, \
|
|
|
|
.open = simple_open, \
|
|
|
|
.llseek = generic_file_llseek, \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEBUGFS_ADD(name, parent) \
|
|
|
|
do { \
|
2019-01-22 15:21:24 +00:00
|
|
|
debugfs_create_file(#name, 0400, parent, \
|
|
|
|
wl, &name## _ops); \
|
2014-05-14 19:15:14 +00:00
|
|
|
} while (0)
|
2012-05-10 09:14:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
|
|
|
|
do { \
|
2019-01-22 15:21:24 +00:00
|
|
|
debugfs_create_file(#name, 0400, parent, \
|
2012-05-10 09:14:06 +00:00
|
|
|
wl, &prefix## _## name## _ops); \
|
2014-05-14 19:15:14 +00:00
|
|
|
} while (0)
|
2012-05-10 09:14:06 +00:00
|
|
|
|
|
|
|
#define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type) \
|
|
|
|
static ssize_t sub## _ ##name## _read(struct file *file, \
|
|
|
|
char __user *userbuf, \
|
|
|
|
size_t count, loff_t *ppos) \
|
|
|
|
{ \
|
|
|
|
struct wl1271 *wl = file->private_data; \
|
|
|
|
struct struct_type *stats = wl->stats.fw_stats; \
|
|
|
|
\
|
|
|
|
wl1271_debugfs_update_stats(wl); \
|
|
|
|
\
|
|
|
|
return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
|
|
|
|
stats->sub.name); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static const struct file_operations sub## _ ##name## _ops = { \
|
|
|
|
.read = sub## _ ##name## _read, \
|
|
|
|
.open = simple_open, \
|
|
|
|
.llseek = generic_file_llseek, \
|
|
|
|
};
|
|
|
|
|
2012-05-10 09:14:07 +00:00
|
|
|
#define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type) \
|
|
|
|
static ssize_t sub## _ ##name## _read(struct file *file, \
|
|
|
|
char __user *userbuf, \
|
|
|
|
size_t count, loff_t *ppos) \
|
|
|
|
{ \
|
|
|
|
struct wl1271 *wl = file->private_data; \
|
|
|
|
struct struct_type *stats = wl->stats.fw_stats; \
|
|
|
|
char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = ""; \
|
wlcore: fix overlapping snprintf arguments in debugfs
gcc complains about undefined behavior in calling snprintf()
with the same buffer as input and output:
drivers/net/wireless/ti/wl18xx/debugfs.c: In function 'diversity_num_of_packets_per_ant_read':
drivers/net/wireless/ti/wl18xx/../wlcore/debugfs.h:86:3: error: 'snprintf' argument 4 overlaps destination object 'buf' [-Werror=restrict]
86 | snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 | buf, i, stats->sub.name[i]); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/ti/wl18xx/debugfs.c:24:2: note: in expansion of macro 'DEBUGFS_FWSTATS_FILE_ARRAY'
24 | DEBUGFS_FWSTATS_FILE_ARRAY(a, b, c, wl18xx_acx_statistics)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/ti/wl18xx/debugfs.c:159:1: note: in expansion of macro 'WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY'
159 | WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(diversity, num_of_packets_per_ant,
There are probably other ways of handling the debugfs file, without
using on-stack buffers, but a simple workaround here is to remember the
current position in the buffer and just keep printing in there.
Fixes: bcca1bbdd412 ("wlcore: add debugfs macro to help print fw statistics arrays")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210323125723.1961432-1-arnd@kernel.org
2021-03-23 12:57:14 +00:00
|
|
|
int pos = 0; \
|
2020-08-26 09:33:46 +00:00
|
|
|
int i; \
|
2012-05-10 09:14:07 +00:00
|
|
|
\
|
|
|
|
wl1271_debugfs_update_stats(wl); \
|
|
|
|
\
|
wlcore: fix overlapping snprintf arguments in debugfs
gcc complains about undefined behavior in calling snprintf()
with the same buffer as input and output:
drivers/net/wireless/ti/wl18xx/debugfs.c: In function 'diversity_num_of_packets_per_ant_read':
drivers/net/wireless/ti/wl18xx/../wlcore/debugfs.h:86:3: error: 'snprintf' argument 4 overlaps destination object 'buf' [-Werror=restrict]
86 | snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 | buf, i, stats->sub.name[i]); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/ti/wl18xx/debugfs.c:24:2: note: in expansion of macro 'DEBUGFS_FWSTATS_FILE_ARRAY'
24 | DEBUGFS_FWSTATS_FILE_ARRAY(a, b, c, wl18xx_acx_statistics)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/ti/wl18xx/debugfs.c:159:1: note: in expansion of macro 'WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY'
159 | WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(diversity, num_of_packets_per_ant,
There are probably other ways of handling the debugfs file, without
using on-stack buffers, but a simple workaround here is to remember the
current position in the buffer and just keep printing in there.
Fixes: bcca1bbdd412 ("wlcore: add debugfs macro to help print fw statistics arrays")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210323125723.1961432-1-arnd@kernel.org
2021-03-23 12:57:14 +00:00
|
|
|
for (i = 0; i < len && pos < sizeof(buf); i++) \
|
2021-04-19 14:14:05 +00:00
|
|
|
pos += snprintf(buf + pos, sizeof(buf) - pos, \
|
wlcore: fix overlapping snprintf arguments in debugfs
gcc complains about undefined behavior in calling snprintf()
with the same buffer as input and output:
drivers/net/wireless/ti/wl18xx/debugfs.c: In function 'diversity_num_of_packets_per_ant_read':
drivers/net/wireless/ti/wl18xx/../wlcore/debugfs.h:86:3: error: 'snprintf' argument 4 overlaps destination object 'buf' [-Werror=restrict]
86 | snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 | buf, i, stats->sub.name[i]); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/ti/wl18xx/debugfs.c:24:2: note: in expansion of macro 'DEBUGFS_FWSTATS_FILE_ARRAY'
24 | DEBUGFS_FWSTATS_FILE_ARRAY(a, b, c, wl18xx_acx_statistics)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/wireless/ti/wl18xx/debugfs.c:159:1: note: in expansion of macro 'WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY'
159 | WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(diversity, num_of_packets_per_ant,
There are probably other ways of handling the debugfs file, without
using on-stack buffers, but a simple workaround here is to remember the
current position in the buffer and just keep printing in there.
Fixes: bcca1bbdd412 ("wlcore: add debugfs macro to help print fw statistics arrays")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210323125723.1961432-1-arnd@kernel.org
2021-03-23 12:57:14 +00:00
|
|
|
"[%d] = %d\n", i, stats->sub.name[i]); \
|
2012-05-10 09:14:07 +00:00
|
|
|
\
|
|
|
|
return wl1271_format_buffer(userbuf, count, ppos, "%s", buf); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static const struct file_operations sub## _ ##name## _ops = { \
|
|
|
|
.read = sub## _ ##name## _read, \
|
|
|
|
.open = simple_open, \
|
|
|
|
.llseek = generic_file_llseek, \
|
|
|
|
};
|
|
|
|
|
2012-05-10 09:14:06 +00:00
|
|
|
#define DEBUGFS_FWSTATS_ADD(sub, name) \
|
|
|
|
DEBUGFS_ADD(sub## _ ##name, stats)
|
|
|
|
|
2009-08-06 13:25:28 +00:00
|
|
|
|
|
|
|
#endif /* WL1271_DEBUGFS_H */
|