From: David Miller <davem@davemloft.net>
To: joe@perches.com
Cc: netdev@vger.kernel.org
Subject: Re: sysfs_format_mac
Date: Tue, 16 Jul 2013 17:10:27 -0700 (PDT) [thread overview]
Message-ID: <20130716.171027.644149479332356036.davem@davemloft.net> (raw)
In-Reply-To: <1374017532.1949.57.camel@joe-AO722>
From: Joe Perches <joe@perches.com>
Date: Tue, 16 Jul 2013 16:32:12 -0700
> On Tue, 2013-07-16 at 16:25 -0700, David Miller wrote:
>> diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
> []
>> ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
> []
>> - l = _format_mac_addr(buf, PAGE_SIZE, addr, len);
>> - l += scnprintf(buf + l, PAGE_SIZE - l, "\n");
> []
>> + return scnprintf(buf, PAGE_SIZE, "%*phC", len, addr);
>
> missing newline?
>
> scnprintf(buf, PAGE_ SIZE, "%*phC\n", len, addr);
Thanks again Joe, I just commited the following patch:
--------------------
[PATCH] net: Fix sysfs_format_mac() code duplication.
It's just a duplicate implementation of "%*phC". Thanks to Joe
Perches for showing that we had exactly this support in the
lib/vsprintf.c code already.
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/ethernet/eth.c | 21 +--------------------
1 file changed, 1 insertion(+), 20 deletions(-)
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 5359560..be1f64d 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -401,27 +401,8 @@ struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
}
EXPORT_SYMBOL(alloc_etherdev_mqs);
-static size_t _format_mac_addr(char *buf, int buflen,
- const unsigned char *addr, int len)
-{
- int i;
- char *cp = buf;
-
- for (i = 0; i < len; i++) {
- cp += scnprintf(cp, buflen - (cp - buf), "%02x", addr[i]);
- if (i == len - 1)
- break;
- cp += scnprintf(cp, buflen - (cp - buf), ":");
- }
- return cp - buf;
-}
-
ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
{
- size_t l;
-
- l = _format_mac_addr(buf, PAGE_SIZE, addr, len);
- l += scnprintf(buf + l, PAGE_SIZE - l, "\n");
- return (ssize_t)l;
+ return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);
}
EXPORT_SYMBOL(sysfs_format_mac);
--
1.7.11.7
prev parent reply other threads:[~2013-07-17 0:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-16 19:56 sysfs_format_mac David Miller
2013-07-16 20:46 ` sysfs_format_mac Joe Perches
2013-07-16 20:58 ` sysfs_format_mac David Miller
2013-07-16 21:12 ` sysfs_format_mac Joe Perches
2013-07-16 23:25 ` sysfs_format_mac David Miller
2013-07-16 23:32 ` sysfs_format_mac Joe Perches
2013-07-16 23:41 ` sysfs_format_mac David Miller
2013-07-17 0:10 ` David Miller [this message]
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=20130716.171027.644149479332356036.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=joe@perches.com \
--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).