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

Urs Thuermann
2007-09-24T19:25:51Z

Joe Perches <joe@perches.com> writes:

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

I have changed this to a static buffer. Since this is only in
#ifdef CONFIG_CAN_DEBUG_CORE, it shouldn't hurt.

> #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)

The line isn't printed atomically, i.e. it could happen that something
is printed between the fmt+args and the hexdump, i.e inbetween the
line.

> 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)

Here, the consecutive lines aren't printed atomically.

I think sprintf() to a buffer first and the do one printk() is
better. But I will use hex_dump_to_buffer().

urs