mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:46:16 +00:00
4bbd360a50
I suggested to put DEBUG_NET_WARN_ON_ONCE() in __sock_create() to catch possible use-after-free. But the warning itself was not useful because our interest is in the callee than the caller. Let's define DEBUG_NET_WARN_ONCE() and print the name of pf->create() and the socket identifier. While at it, we enclose DEBUG_NET_WARN_ON_ONCE() in parentheses too to avoid a checkpatch error. Note that %pf or %pF were obsoleted and will be removed later as per comment in lib/vsprintf.c. Link: https://lore.kernel.org/netdev/202410231427.633734b3-lkp@intel.com/ Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20241024201458.49412-1-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
160 lines
5.2 KiB
C
160 lines
5.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_NET_DEBUG_H
|
|
#define _LINUX_NET_DEBUG_H
|
|
|
|
#include <linux/bug.h>
|
|
#include <linux/kern_levels.h>
|
|
|
|
struct net_device;
|
|
|
|
__printf(3, 4) __cold
|
|
void netdev_printk(const char *level, const struct net_device *dev,
|
|
const char *format, ...);
|
|
__printf(2, 3) __cold
|
|
void netdev_emerg(const struct net_device *dev, const char *format, ...);
|
|
__printf(2, 3) __cold
|
|
void netdev_alert(const struct net_device *dev, const char *format, ...);
|
|
__printf(2, 3) __cold
|
|
void netdev_crit(const struct net_device *dev, const char *format, ...);
|
|
__printf(2, 3) __cold
|
|
void netdev_err(const struct net_device *dev, const char *format, ...);
|
|
__printf(2, 3) __cold
|
|
void netdev_warn(const struct net_device *dev, const char *format, ...);
|
|
__printf(2, 3) __cold
|
|
void netdev_notice(const struct net_device *dev, const char *format, ...);
|
|
__printf(2, 3) __cold
|
|
void netdev_info(const struct net_device *dev, const char *format, ...);
|
|
|
|
#define netdev_level_once(level, dev, fmt, ...) \
|
|
do { \
|
|
static bool __section(".data.once") __print_once; \
|
|
\
|
|
if (!__print_once) { \
|
|
__print_once = true; \
|
|
netdev_printk(level, dev, fmt, ##__VA_ARGS__); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define netdev_emerg_once(dev, fmt, ...) \
|
|
netdev_level_once(KERN_EMERG, dev, fmt, ##__VA_ARGS__)
|
|
#define netdev_alert_once(dev, fmt, ...) \
|
|
netdev_level_once(KERN_ALERT, dev, fmt, ##__VA_ARGS__)
|
|
#define netdev_crit_once(dev, fmt, ...) \
|
|
netdev_level_once(KERN_CRIT, dev, fmt, ##__VA_ARGS__)
|
|
#define netdev_err_once(dev, fmt, ...) \
|
|
netdev_level_once(KERN_ERR, dev, fmt, ##__VA_ARGS__)
|
|
#define netdev_warn_once(dev, fmt, ...) \
|
|
netdev_level_once(KERN_WARNING, dev, fmt, ##__VA_ARGS__)
|
|
#define netdev_notice_once(dev, fmt, ...) \
|
|
netdev_level_once(KERN_NOTICE, dev, fmt, ##__VA_ARGS__)
|
|
#define netdev_info_once(dev, fmt, ...) \
|
|
netdev_level_once(KERN_INFO, dev, fmt, ##__VA_ARGS__)
|
|
|
|
#if defined(CONFIG_DYNAMIC_DEBUG) || \
|
|
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
|
|
#define netdev_dbg(__dev, format, args...) \
|
|
do { \
|
|
dynamic_netdev_dbg(__dev, format, ##args); \
|
|
} while (0)
|
|
#elif defined(DEBUG)
|
|
#define netdev_dbg(__dev, format, args...) \
|
|
netdev_printk(KERN_DEBUG, __dev, format, ##args)
|
|
#else
|
|
#define netdev_dbg(__dev, format, args...) \
|
|
({ \
|
|
if (0) \
|
|
netdev_printk(KERN_DEBUG, __dev, format, ##args); \
|
|
})
|
|
#endif
|
|
|
|
#if defined(VERBOSE_DEBUG)
|
|
#define netdev_vdbg netdev_dbg
|
|
#else
|
|
|
|
#define netdev_vdbg(dev, format, args...) \
|
|
({ \
|
|
if (0) \
|
|
netdev_printk(KERN_DEBUG, dev, format, ##args); \
|
|
0; \
|
|
})
|
|
#endif
|
|
|
|
/* netif printk helpers, similar to netdev_printk */
|
|
|
|
#define netif_printk(priv, type, level, dev, fmt, args...) \
|
|
do { \
|
|
if (netif_msg_##type(priv)) \
|
|
netdev_printk(level, (dev), fmt, ##args); \
|
|
} while (0)
|
|
|
|
#define netif_level(level, priv, type, dev, fmt, args...) \
|
|
do { \
|
|
if (netif_msg_##type(priv)) \
|
|
netdev_##level(dev, fmt, ##args); \
|
|
} while (0)
|
|
|
|
#define netif_emerg(priv, type, dev, fmt, args...) \
|
|
netif_level(emerg, priv, type, dev, fmt, ##args)
|
|
#define netif_alert(priv, type, dev, fmt, args...) \
|
|
netif_level(alert, priv, type, dev, fmt, ##args)
|
|
#define netif_crit(priv, type, dev, fmt, args...) \
|
|
netif_level(crit, priv, type, dev, fmt, ##args)
|
|
#define netif_err(priv, type, dev, fmt, args...) \
|
|
netif_level(err, priv, type, dev, fmt, ##args)
|
|
#define netif_warn(priv, type, dev, fmt, args...) \
|
|
netif_level(warn, priv, type, dev, fmt, ##args)
|
|
#define netif_notice(priv, type, dev, fmt, args...) \
|
|
netif_level(notice, priv, type, dev, fmt, ##args)
|
|
#define netif_info(priv, type, dev, fmt, args...) \
|
|
netif_level(info, priv, type, dev, fmt, ##args)
|
|
|
|
#if defined(CONFIG_DYNAMIC_DEBUG) || \
|
|
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
|
|
#define netif_dbg(priv, type, netdev, format, args...) \
|
|
do { \
|
|
if (netif_msg_##type(priv)) \
|
|
dynamic_netdev_dbg(netdev, format, ##args); \
|
|
} while (0)
|
|
#elif defined(DEBUG)
|
|
#define netif_dbg(priv, type, dev, format, args...) \
|
|
netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
|
|
#else
|
|
#define netif_dbg(priv, type, dev, format, args...) \
|
|
({ \
|
|
if (0) \
|
|
netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
|
|
0; \
|
|
})
|
|
#endif
|
|
|
|
/* if @cond then downgrade to debug, else print at @level */
|
|
#define netif_cond_dbg(priv, type, netdev, cond, level, fmt, args...) \
|
|
do { \
|
|
if (cond) \
|
|
netif_dbg(priv, type, netdev, fmt, ##args); \
|
|
else \
|
|
netif_ ## level(priv, type, netdev, fmt, ##args); \
|
|
} while (0)
|
|
|
|
#if defined(VERBOSE_DEBUG)
|
|
#define netif_vdbg netif_dbg
|
|
#else
|
|
#define netif_vdbg(priv, type, dev, format, args...) \
|
|
({ \
|
|
if (0) \
|
|
netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
|
|
0; \
|
|
})
|
|
#endif
|
|
|
|
|
|
#if defined(CONFIG_DEBUG_NET)
|
|
#define DEBUG_NET_WARN_ON_ONCE(cond) ((void)WARN_ON_ONCE(cond))
|
|
#define DEBUG_NET_WARN_ONCE(cond, format...) ((void)WARN_ONCE(cond, format))
|
|
#else
|
|
#define DEBUG_NET_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
|
|
#define DEBUG_NET_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)
|
|
#endif
|
|
|
|
#endif /* _LINUX_NET_DEBUG_H */
|