Skip to content

Commit a4ca44f

Browse files
JoePerchesdavem330
authored andcommitted
net: l2tp: Standardize logging styles
Use more current logging styles. Add pr_fmt to prefix output appropriately. Convert printks to pr_<level>. Convert PRINTK macros to new l2tp_<level> macros. Neaten some <foo>_refcount debugging macros. Use print_hex_dump_bytes instead of hand-coded loops. Coalesce formats and align arguments. Some KERN_DEBUG output is not now emitted unless dynamic_debugging is enabled. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: James Chapman <jchapman@katalix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0289403 commit a4ca44f

8 files changed

Lines changed: 213 additions & 221 deletions

File tree

‎net/l2tp/l2tp_core.c‎

Lines changed: 101 additions & 115 deletions
Large diffs are not rendered by default.

‎net/l2tp/l2tp_core.h‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,36 @@ static inline void l2tp_session_dec_refcount_1(struct l2tp_session *session)
261261
}
262262

263263
#ifdef L2TP_REFCNT_DEBUG
264-
#define l2tp_session_inc_refcount(_s) do { \
265-
printk(KERN_DEBUG "l2tp_session_inc_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_s)->name, atomic_read(&_s->ref_count)); \
266-
l2tp_session_inc_refcount_1(_s); \
267-
} while (0)
268-
#define l2tp_session_dec_refcount(_s) do { \
269-
printk(KERN_DEBUG "l2tp_session_dec_refcount: %s:%d %s: cnt=%d\n", __func__, __LINE__, (_s)->name, atomic_read(&_s->ref_count)); \
270-
l2tp_session_dec_refcount_1(_s); \
271-
} while (0)
264+
#define l2tp_session_inc_refcount(_s) \
265+
do { \
266+
pr_debug("l2tp_session_inc_refcount: %s:%d %s: cnt=%d\n", \
267+
__func__, __LINE__, (_s)->name, \
268+
atomic_read(&_s->ref_count)); \
269+
l2tp_session_inc_refcount_1(_s); \
270+
} while (0)
271+
#define l2tp_session_dec_refcount(_s) \
272+
do { \
273+
pr_debug("l2tp_session_dec_refcount: %s:%d %s: cnt=%d\n", \
274+
__func__, __LINE__, (_s)->name, \
275+
atomic_read(&_s->ref_count)); \
276+
l2tp_session_dec_refcount_1(_s); \
277+
} while (0)
272278
#else
273279
#define l2tp_session_inc_refcount(s) l2tp_session_inc_refcount_1(s)
274280
#define l2tp_session_dec_refcount(s) l2tp_session_dec_refcount_1(s)
275281
#endif
276282

283+
#define l2tp_printk(ptr, type, func, fmt, ...) \
284+
do { \
285+
if (((ptr)->debug) & (type)) \
286+
func(fmt, ##__VA_ARGS__); \
287+
} while (0)
288+
289+
#define l2tp_warn(ptr, type, fmt, ...) \
290+
l2tp_printk(ptr, type, pr_warn, fmt, ##__VA_ARGS__)
291+
#define l2tp_info(ptr, type, fmt, ...) \
292+
l2tp_printk(ptr, type, pr_info, fmt, ##__VA_ARGS__)
293+
#define l2tp_dbg(ptr, type, fmt, ...) \
294+
l2tp_printk(ptr, type, pr_debug, fmt, ##__VA_ARGS__)
295+
277296
#endif /* _L2TP_CORE_H_ */

‎net/l2tp/l2tp_debugfs.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* 2 of the License, or (at your option) any later version.
1010
*/
1111

12+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13+
1214
#include <linux/module.h>
1315
#include <linux/skbuff.h>
1416
#include <linux/socket.h>
@@ -325,11 +327,11 @@ static int __init l2tp_debugfs_init(void)
325327
if (tunnels == NULL)
326328
rc = -EIO;
327329

328-
printk(KERN_INFO "L2TP debugfs support\n");
330+
pr_info("L2TP debugfs support\n");
329331

330332
out:
331333
if (rc)
332-
printk(KERN_WARNING "l2tp debugfs: unable to init\n");
334+
pr_warn("unable to init\n");
333335

334336
return rc;
335337
}

‎net/l2tp/l2tp_eth.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* 2 of the License, or (at your option) any later version.
1010
*/
1111

12+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13+
1214
#include <linux/module.h>
1315
#include <linux/skbuff.h>
1416
#include <linux/socket.h>
@@ -115,21 +117,14 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
115117

116118
if (session->debug & L2TP_MSG_DATA) {
117119
unsigned int length;
118-
int offset;
119120
u8 *ptr = skb->data;
120121

121122
length = min(32u, skb->len);
122123
if (!pskb_may_pull(skb, length))
123124
goto error;
124125

125-
printk(KERN_DEBUG "%s: eth recv: ", session->name);
126-
127-
offset = 0;
128-
do {
129-
printk(" %02X", ptr[offset]);
130-
} while (++offset < length);
131-
132-
printk("\n");
126+
pr_debug("%s: eth recv\n", session->name);
127+
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length);
133128
}
134129

135130
if (!pskb_may_pull(skb, sizeof(ETH_HLEN)))
@@ -308,7 +303,7 @@ static int __init l2tp_eth_init(void)
308303
if (err)
309304
goto out_unreg;
310305

311-
printk(KERN_INFO "L2TP ethernet pseudowire support (L2TPv3)\n");
306+
pr_info("L2TP ethernet pseudowire support (L2TPv3)\n");
312307

313308
return 0;
314309

‎net/l2tp/l2tp_ip.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* 2 of the License, or (at your option) any later version.
1010
*/
1111

12+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13+
1214
#include <linux/icmp.h>
1315
#include <linux/module.h>
1416
#include <linux/skbuff.h>
@@ -120,7 +122,6 @@ static int l2tp_ip_recv(struct sk_buff *skb)
120122
struct l2tp_session *session;
121123
struct l2tp_tunnel *tunnel = NULL;
122124
int length;
123-
int offset;
124125

125126
/* Point to L2TP header */
126127
optr = ptr = skb->data;
@@ -155,14 +156,8 @@ static int l2tp_ip_recv(struct sk_buff *skb)
155156
if (!pskb_may_pull(skb, length))
156157
goto discard;
157158

158-
printk(KERN_DEBUG "%s: ip recv: ", tunnel->name);
159-
160-
offset = 0;
161-
do {
162-
printk(" %02X", ptr[offset]);
163-
} while (++offset < length);
164-
165-
printk("\n");
159+
pr_debug("%s: ip recv\n", tunnel->name);
160+
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length);
166161
}
167162

168163
l2tp_recv_common(session, skb, ptr, optr, 0, skb->len, tunnel->recv_payload_hook);
@@ -593,7 +588,7 @@ static int __init l2tp_ip_init(void)
593588
{
594589
int err;
595590

596-
printk(KERN_INFO "L2TP IP encapsulation support (L2TPv3)\n");
591+
pr_info("L2TP IP encapsulation support (L2TPv3)\n");
597592

598593
err = proto_register(&l2tp_ip_prot, 1);
599594
if (err != 0)

‎net/l2tp/l2tp_ip6.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* 2 of the License, or (at your option) any later version.
1010
*/
1111

12+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13+
1214
#include <linux/icmp.h>
1315
#include <linux/module.h>
1416
#include <linux/skbuff.h>
@@ -133,7 +135,6 @@ static int l2tp_ip6_recv(struct sk_buff *skb)
133135
struct l2tp_session *session;
134136
struct l2tp_tunnel *tunnel = NULL;
135137
int length;
136-
int offset;
137138

138139
/* Point to L2TP header */
139140
optr = ptr = skb->data;
@@ -168,14 +169,8 @@ static int l2tp_ip6_recv(struct sk_buff *skb)
168169
if (!pskb_may_pull(skb, length))
169170
goto discard;
170171

171-
printk(KERN_DEBUG "%s: ip recv: ", tunnel->name);
172-
173-
offset = 0;
174-
do {
175-
printk(" %02X", ptr[offset]);
176-
} while (++offset < length);
177-
178-
printk("\n");
172+
pr_debug("%s: ip recv\n", tunnel->name);
173+
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, ptr, length);
179174
}
180175

181176
l2tp_recv_common(session, skb, ptr, optr, 0, skb->len,
@@ -752,7 +747,7 @@ static int __init l2tp_ip6_init(void)
752747
{
753748
int err;
754749

755-
printk(KERN_INFO "L2TP IP encapsulation support for IPv6 (L2TPv3)\n");
750+
pr_info("L2TP IP encapsulation support for IPv6 (L2TPv3)\n");
756751

757752
err = proto_register(&l2tp_ip6_prot, 1);
758753
if (err != 0)

‎net/l2tp/l2tp_netlink.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* published by the Free Software Foundation.
1515
*/
1616

17+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18+
1719
#include <net/sock.h>
1820
#include <net/genetlink.h>
1921
#include <net/udp.h>
@@ -902,7 +904,7 @@ static int l2tp_nl_init(void)
902904
{
903905
int err;
904906

905-
printk(KERN_INFO "L2TP netlink interface\n");
907+
pr_info("L2TP netlink interface\n");
906908
err = genl_register_family_with_ops(&l2tp_nl_family, l2tp_nl_ops,
907909
ARRAY_SIZE(l2tp_nl_ops));
908910

0 commit comments

Comments
 (0)