netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: change return values in mac_pton() function
@ 2011-07-13  9:30 Arend van Spriel
  2011-07-13 10:09 ` Alexey Dobriyan
  0 siblings, 1 reply; 4+ messages in thread
From: Arend van Spriel @ 2011-07-13  9:30 UTC (permalink / raw)
  To: davem; +Cc: Arend van Spriel, netdev, linux-kernel, Alexey Dobriyan

The original commit adding this function noted a diverge from usual
0=success/-E=fail, but no motivation for it. To stay consistent this
commit adheres to the usual approach. The callers check for result
is changed from 'if(!mac_pton(x, y))' to 'if(mac_pton(x,y) < 0)'.

Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
---
 drivers/net/netconsole.c |    2 +-
 net/core/netpoll.c       |    2 +-
 net/core/pktgen.c        |    4 ++--
 net/core/utils.c         |   10 +++++-----
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index dfc8272..2e8adba 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -437,7 +437,7 @@ static ssize_t store_remote_mac(struct netconsole_target *nt,
 		return -EINVAL;
 	}
 
-	if (!mac_pton(buf, remote_mac))
+	if (mac_pton(buf, remote_mac) < 0)
 		return -EINVAL;
 	if (buf[3 * ETH_ALEN - 1] && buf[3 * ETH_ALEN - 1] != '\n')
 		return -EINVAL;
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index adf84dd..6b70699 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -691,7 +691,7 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
 
 	if (*cur != 0) {
 		/* MAC address */
-		if (!mac_pton(cur, np->remote_mac))
+		if (mac_pton(cur, np->remote_mac) < 0)
 			goto parse_failed;
 	}
 
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index f76079c..f17ab6a 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -1429,7 +1429,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		if (copy_from_user(valstr, &user_buffer[i], len))
 			return -EFAULT;
 
-		if (!mac_pton(valstr, pkt_dev->dst_mac))
+		if (mac_pton(valstr, pkt_dev->dst_mac) < 0)
 			return -EINVAL;
 		/* Set up Dest MAC */
 		memcpy(&pkt_dev->hh[0], pkt_dev->dst_mac, ETH_ALEN);
@@ -1446,7 +1446,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		if (copy_from_user(valstr, &user_buffer[i], len))
 			return -EFAULT;
 
-		if (!mac_pton(valstr, pkt_dev->src_mac))
+		if (mac_pton(valstr, pkt_dev->src_mac) < 0)
 			return -EINVAL;
 		/* Set up Src MAC */
 		memcpy(&pkt_dev->hh[6], pkt_dev->src_mac, ETH_ALEN);
diff --git a/net/core/utils.c b/net/core/utils.c
index 386e263f..73299f1 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -304,20 +304,20 @@ int mac_pton(const char *s, u8 *mac)
 
 	/* XX:XX:XX:XX:XX:XX */
 	if (strlen(s) < 3 * ETH_ALEN - 1)
-		return 0;
+		return -EINVAL;
 
 	/* Don't dirty result unless string is valid MAC. */
 	for (i = 0; i < ETH_ALEN; i++) {
 		if (!strchr("0123456789abcdefABCDEF", s[i * 3]))
-			return 0;
+			return -EINVAL;
 		if (!strchr("0123456789abcdefABCDEF", s[i * 3 + 1]))
-			return 0;
+			return -EINVAL;
 		if (i != ETH_ALEN - 1 && s[i * 3 + 2] != ':')
-			return 0;
+			return -EINVAL;
 	}
 	for (i = 0; i < ETH_ALEN; i++) {
 		mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
 	}
-	return 1;
+	return 0;
 }
 EXPORT_SYMBOL(mac_pton);
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: change return values in mac_pton() function
  2011-07-13  9:30 [PATCH] net: change return values in mac_pton() function Arend van Spriel
@ 2011-07-13 10:09 ` Alexey Dobriyan
  2011-07-13 11:12   ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2011-07-13 10:09 UTC (permalink / raw)
  To: Arend van Spriel; +Cc: davem, netdev, linux-kernel

On Wed, Jul 13, 2011 at 12:30 PM, Arend van Spriel <arend@broadcom.com> wrote:
> The original commit adding this function noted a diverge from usual
> 0=success/-E=fail, but no motivation for it.

I thought it was obvious, but indeed wasn't explicitely
mentioned in changelog. But see inet_pton(3).

> To stay consistent this
> commit adheres to the usual approach. The callers check for result
> is changed from 'if(!mac_pton(x, y))' to 'if(mac_pton(x,y) < 0)'.

> @@ -304,20 +304,20 @@ int mac_pton(const char *s, u8 *mac)
>
>        /* XX:XX:XX:XX:XX:XX */
>        if (strlen(s) < 3 * ETH_ALEN - 1)
> -               return 0;
> +               return -EINVAL;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: change return values in mac_pton() function
  2011-07-13 10:09 ` Alexey Dobriyan
@ 2011-07-13 11:12   ` David Miller
  2011-07-13 11:21     ` Arend van Spriel
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2011-07-13 11:12 UTC (permalink / raw)
  To: adobriyan; +Cc: arend, netdev, linux-kernel

From: Alexey Dobriyan <adobriyan@gmail.com>
Date: Wed, 13 Jul 2011 13:09:03 +0300

> On Wed, Jul 13, 2011 at 12:30 PM, Arend van Spriel <arend@broadcom.com> wrote:
>> The original commit adding this function noted a diverge from usual
>> 0=success/-E=fail, but no motivation for it.
> 
> I thought it was obvious, but indeed wasn't explicitely
> mentioned in changelog. But see inet_pton(3).

Agreed it's better for mac_pton() to be consistent with existing,
similar, interfaces like inet_pton.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: change return values in mac_pton() function
  2011-07-13 11:12   ` David Miller
@ 2011-07-13 11:21     ` Arend van Spriel
  0 siblings, 0 replies; 4+ messages in thread
From: Arend van Spriel @ 2011-07-13 11:21 UTC (permalink / raw)
  To: David Miller
  Cc: adobriyan@gmail.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org

On 07/13/2011 01:12 PM, David Miller wrote:
> From: Alexey Dobriyan<adobriyan@gmail.com>
> Date: Wed, 13 Jul 2011 13:09:03 +0300
>
>> On Wed, Jul 13, 2011 at 12:30 PM, Arend van Spriel<arend@broadcom.com>  wrote:
>>> The original commit adding this function noted a diverge from usual
>>> 0=success/-E=fail, but no motivation for it.
>> I thought it was obvious, but indeed wasn't explicitely
>> mentioned in changelog. But see inet_pton(3).
> Agreed it's better for mac_pton() to be consistent with existing,
> similar, interfaces like inet_pton.

I just liked the general approach of zero indicating success. But even 
in the realm called Linux not everything can be black and white, I guess :-D

Please drop the patch.

Gr. AvS

-- 
Almost nobody dances sober, unless they happen to be insane.
-- H.P. Lovecraft --



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-07-13 11:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-13  9:30 [PATCH] net: change return values in mac_pton() function Arend van Spriel
2011-07-13 10:09 ` Alexey Dobriyan
2011-07-13 11:12   ` David Miller
2011-07-13 11:21     ` Arend van Spriel

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