net: change return values in mac_pton() function
Subsystems (3)
PATCH 1/1 net: change return values in mac_pton() function
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)'.
--- 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(-)
drivers/net/netconsole.c +1 -1
@@ -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 ;
net/core/netpoll.c +1 -1
@@ -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; }
net/core/pktgen.c +2 -2
@@ -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 );
net/core/utils.c +5 -5
@@ -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);
Signature · 1 line
1.7.4.1
Quoted 2 lines · Arend van Spriel
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).
Quoted 10 lines
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)'.net/core/utils.c +1
-1@@ -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;
David Miller
maintainerFrom: Alexey Dobriyan <[email protected]>
Date: Wed, 13 Jul 2011 13:09:03 +0300
Quoted 6 lines · Arend van Spriel
Quoted 2 lines
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.
Quoted 10 lines · David Miller
From: Alexey Dobriyan<[email protected]>
Date: Wed, 13 Jul 2011 13:09:03 +0300Quoted 5 lines · Arend van Spriel
Quoted 2 lines
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 likeinet_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
Signature · 2 lines
Almost nobody dances sober, unless they happen to be insane. -- H.P. Lovecraft --