diff mbox

net: change return values in mac_pton() function

Message ID 1310549424-5484-1-git-send-email-arend@broadcom.com
State Rejected, archived
Delegated to: David Miller
Headers show

Commit Message

Arend van Spriel July 13, 2011, 9:30 a.m. UTC
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(-)

Comments

Alexey Dobriyan July 13, 2011, 10:09 a.m. UTC | #1
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;
--
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 13, 2011, 11:12 a.m. UTC | #2
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.
--
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
Arend van Spriel July 13, 2011, 11:21 a.m. UTC | #3
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
diff mbox

Patch

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