Subject: Re: New sparse warning in net/mac80211/debugfs_sta.c

From: Joe Perches <[email-masked]>
Date: Mon, 25 Feb 2008 08:53:49 -0800

On Mon, 2008-02-25 at 10:53 +0100, Johannes Berg wrote:
> Maybe we should just add a new printf modifier like %M for MAC
> addresses? Then we could use sprintf, snprintf, printk and whatever we
> please without any of the macro stuff...

Could gcc validate the printf %M arguments?

Another possibility without changing printf argument validation
is to use a MAC_FMT macro in place of "%s"

#ifdef CONFIG_INLINE_MAC

#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
#define DECLARE_MAC_BUF(var)
#define print_mac(buf, addr) (addr)[0], (addr)[1], (addr)[2], (addr)[3], (addr)[4], (addr)[5]

#else

#define MAC_FMT "%s"
#define DECLARE_MAC_BUF(var) char var[18];
extern char *print_mac(char *buf, const unsigned char *addr);

#endif

use:

DECLARE_MAC_BUF(mac);
printk(KERN_INFO "Mac address is: " MAC_FMT "\n", print_mac(mac, addr));