From: Joe Perches <joe@perches.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: David Miller <davem@davemloft.net>,
harvey.harrison@gmail.com, netdev@vger.kernel.org
Subject: Re: New sparse warning in net/mac80211/debugfs_sta.c
Date: Thu, 21 Feb 2008 09:54:46 -0800 [thread overview]
Message-ID: <1203616486.7181.269.camel@localhost> (raw)
In-Reply-To: <1203589042.17534.145.camel@johannes.berg>
On Thu, 2008-02-21 at 11:17 +0100, Johannes Berg wrote:
> Yeah, I saw that discussion. I think it's fine, it's just something we
> need to be aware of. In fact, I Joe had a patch (that seems to have
> gotten lost?) to make DECLARE_MAC_BUF() declare a structure with the u8
> pointer in it instead to get type checking for the args, which would
> make our code there not even compile, and imho rightfully so. I'll send
> in a patch to fix this (via John) and Joe can resend his patch to get
> typechecking there.
This removes the __pure from print_mac, so reject as appropriate...
Add some type safety to print_mac by using
struct print_mac_buf * instead of char *.
Signed-off-by: Joe Perches <joe@perches.com>
diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h
index 42dc6a3..2f8df76 100644
--- a/include/linux/if_ether.h
+++ b/include/linux/if_ether.h
@@ -129,9 +129,16 @@ extern ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len);
/*
* Display a 6 byte device address (MAC) in a readable format.
*/
-extern __pure char *print_mac(char *buf, const unsigned char *addr);
-#define MAC_BUF_SIZE 18
-#define DECLARE_MAC_BUF(var) char var[MAC_BUF_SIZE] __maybe_unused
+
+struct print_mac_buf {
+ char formatted_mac_addr[18];
+};
+
+#define DECLARE_MAC_BUF(var) \
+ struct print_mac_buf __maybe_unused _##var; \
+ struct print_mac_buf __maybe_unused *var = &_##var
+
+extern char *print_mac(struct print_mac_buf *buf, const unsigned char *addr);
#endif
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index a7b4175..ce607ab 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -384,9 +384,10 @@ ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
}
EXPORT_SYMBOL(sysfs_format_mac);
-char *print_mac(char *buf, const unsigned char *addr)
+char *print_mac(struct print_mac_buf *buf, const unsigned char *addr)
{
- _format_mac_addr(buf, MAC_BUF_SIZE, addr, ETH_ALEN);
- return buf;
+ _format_mac_addr(buf->formatted_mac_addr,
+ sizeof(buf->formatted_mac_addr), addr, ETH_ALEN);
+ return buf->formatted_mac_addr;
}
EXPORT_SYMBOL(print_mac);
next prev parent reply other threads:[~2008-02-21 17:55 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-21 9:34 New sparse warning in net/mac80211/debugfs_sta.c Harvey Harrison
2008-02-21 9:54 ` Johannes Berg
2008-02-21 10:03 ` David Miller
2008-02-21 10:08 ` Harvey Harrison
2008-02-21 10:12 ` David Miller
2008-02-21 10:16 ` Harvey Harrison
2008-02-21 10:22 ` [PATCH] mac80211: fix debugfs_sta print_mac() warning Johannes Berg
[not found] ` <20080221.015743.222059206.davem@davemloft.net>
2008-02-21 10:01 ` New sparse warning in net/mac80211/debugfs_sta.c Harvey Harrison
2008-02-21 10:05 ` David Miller
2008-02-21 10:14 ` Harvey Harrison
2008-02-21 10:17 ` Johannes Berg
2008-02-21 17:54 ` Joe Perches [this message]
2008-02-21 18:00 ` Patrick McHardy
2008-02-21 18:15 ` Patrick McHardy
2008-02-24 4:02 ` David Miller
2008-02-25 9:53 ` Johannes Berg
2008-02-25 16:53 ` Joe Perches
2008-02-25 17:29 ` Johannes Berg
2008-02-25 17:23 ` Johannes Berg
2008-02-25 19:52 ` David Miller
2008-02-25 19:56 ` Johannes Berg
2008-02-25 20:05 ` Johannes Berg
2008-02-25 20:14 ` David Miller
2008-02-25 20:12 ` David Miller
2008-02-25 11:47 ` Patrick McHardy
2008-02-25 19:58 ` Joe Perches
2008-04-08 20:18 ` Patrick McHardy
2008-04-08 21:02 ` Joe Perches
2008-04-08 21:16 ` David Miller
2008-04-08 21:19 ` Patrick McHardy
2008-04-08 22:09 ` Joe Perches
2008-04-08 22:30 ` David Miller
2008-04-08 22:41 ` Joe Perches
2008-04-08 22:32 ` Patrick McHardy
2008-02-21 17:17 ` Joe Perches
2008-02-21 17:45 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1203616486.7181.269.camel@localhost \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=harvey.harrison@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).