diff mbox

sysfs_format_mac

Message ID 20130716.162549.1211987183945448630.davem@davemloft.net
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

David Miller July 16, 2013, 11:25 p.m. UTC
From: Joe Perches <joe@perches.com>
Date: Tue, 16 Jul 2013 14:12:49 -0700

> On Tue, 2013-07-16 at 13:58 -0700, David Miller wrote:
>> From: Joe Perches <joe@perches.com>
>> Date: Tue, 16 Jul 2013 13:46:26 -0700
>> > On Tue, 2013-07-16 at 12:56 -0700, David Miller wrote:
> []
>> >> It would make so much more sense to allow specifying a length
>> >> specifier to %pm and friends.
>> > 
>> > scnprintf("%*ph", (int)size, buffer)
>> 
>> Yes, exactly, something like that.
> 
> That works now.

Oh, hehe, indeed.

I'm about to test the following.

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

Comments

Joe Perches July 16, 2013, 11:32 p.m. UTC | #1
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);



--
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
David Miller July 16, 2013, 11:41 p.m. UTC | #2
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);

Good catch.
--
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
diff mbox

Patch

diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 5359560..2307062 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", len, addr);
 }
 EXPORT_SYMBOL(sysfs_format_mac);