Re: [PATCH 2/7] CAN: Add PF_CAN core module

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Joe Perches
Date: Thursday, September 20, 2007 - 1:06 pm

On Thu, 2007-09-20 at 20:43 +0200, Urs Thuermann wrote:

Shouldn't these be like the more common

#define DBG(fmt, args...) \
do { \
	if (debug & 1) \
		printk(KERN_DEBUG "can-%s %s: " fmt, IDENT, __func__, ##args); \
} while (0)

#define DBG_FRAME(cf, fmt, args...) \
do { \
	if (debug & 2) \
		can_debug_cframe(cf, fmt, ##args); \
} while (0)

#define DBG_SKB(skb) \
do { \
	if (debug & 4) \
		can_debug_skb(skb); \
while (0)


This prototype looks backwards to me.

msg is a printf format string.

I'd prefer something like this, which removes the unnecessary
kmalloc/kfree pairs or the equivalent conversions to functions.

#define can_debug_cframe(cf, fmt, arg...) \
do { \
	char buf[20]; \
	int dlc = cf->can_dlc; \
	if (dlc > 8) \
		dlc = 8; \
	if (cf->can_id & CAN_EFF_FLAG) \
		sprintf(buf, "<%08X> [%X] ", cf->can_id & CAN_EFF_MASK, dlc); \
	else \
		sprintf(buf, "<%03X> [%X] ", cf->can_id & CAN_SFF_MASK, dlc); \
	printk(KERN_DEBUG fmt, ##arg); \
	print_hex_dump(buf, DUMP_PREFIX_NONE, cf->data, dlc); \
} while (0)

and

#define can_debug_skb(skb) \
do { \
	pr_debug("skbuff at %p, dev: %d, proto: %04x\n", \
		 skb, skb->dev ? skb->dev->ifindex : -1, \
		 ntohs(skb->protocol)); \
	pr_debug("users: %d, dataref: %d, nr_frags: %d, " \
		 "h,d,t,e,l: %p %+d %+d %+d, %d\n", \
		 atomic_read(&skb->users), \
		 atomic_read(&(skb_shinfo(skb)->dataref)), \
		 skb_shinfo(skb)->nr_frags, \
		 skb->head, skb->data - skb->head, \
		 skb->tail - skb->head, skb->end - skb->head, skb->len); \
	print_hex_dump(KERN_DEBUG, "skb_head: ", DUMP_PREFIX_NONE, \
		       16, 1, skb->head, skb->end - skb->head); \ 
} while (0)

cheers, Joe

-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 2/7] CAN: Add PF_CAN core module, Urs Thuermann, (Thu Sep 20, 11:43 am)
Re: [PATCH 2/7] CAN: Add PF_CAN core module, Joe Perches, (Thu Sep 20, 1:06 pm)
Re: [PATCH 2/7] CAN: Add PF_CAN core module, Thomas Gleixner, (Thu Sep 20, 1:27 pm)
Re: [PATCH 2/7] CAN: Add PF_CAN core module, Urs Thuermann, (Fri Sep 21, 3:35 am)
Re: [PATCH 2/7] CAN: Add PF_CAN core module, Patrick McHardy, (Fri Sep 21, 5:47 am)
Re: [PATCH 2/7] CAN: Add PF_CAN core module, Joe Perches, (Fri Sep 21, 9:58 am)
Re: [PATCH 2/7] CAN: Add PF_CAN core module, Urs Thuermann, (Fri Sep 21, 11:01 am)
Re: [PATCH 2/7] CAN: Add PF_CAN core module, Patrick McHardy, (Sat Sep 22, 3:53 am)
Re: [PATCH 2/7] CAN: Add PF_CAN core module, Urs Thuermann, (Mon Sep 24, 12:23 pm)