aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c14
-rw-r--r--include/linux/if_ether.h8
-rw-r--r--net/core/net-sysfs.c15
-rw-r--r--net/ethernet/eth.c30
4 files changed, 35 insertions, 32 deletions
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index f55b9f7d9396..d3f86646cb08 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -173,18 +173,6 @@ static void qla4xxx_conn_stop(struct iscsi_cls_conn *conn, int flag)
173 printk(KERN_ERR "iscsi: invalid stop flag %d\n", flag); 173 printk(KERN_ERR "iscsi: invalid stop flag %d\n", flag);
174} 174}
175 175
176static ssize_t format_addr(char *buf, const unsigned char *addr, int len)
177{
178 int i;
179 char *cp = buf;
180
181 for (i = 0; i < len; i++)
182 cp += sprintf(cp, "%02x%c", addr[i],
183 i == (len - 1) ? '\n' : ':');
184 return cp - buf;
185}
186
187
188static int qla4xxx_host_get_param(struct Scsi_Host *shost, 176static int qla4xxx_host_get_param(struct Scsi_Host *shost,
189 enum iscsi_host_param param, char *buf) 177 enum iscsi_host_param param, char *buf)
190{ 178{
@@ -193,7 +181,7 @@ static int qla4xxx_host_get_param(struct Scsi_Host *shost,
193 181
194 switch (param) { 182 switch (param) {
195 case ISCSI_HOST_PARAM_HWADDRESS: 183 case ISCSI_HOST_PARAM_HWADDRESS:
196 len = format_addr(buf, ha->my_mac, MAC_ADDR_LEN); 184 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
197 break; 185 break;
198 case ISCSI_HOST_PARAM_IPADDRESS: 186 case ISCSI_HOST_PARAM_IPADDRESS:
199 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0], 187 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h
index cc002cbbdc26..7a1e011b8a2c 100644
--- a/include/linux/if_ether.h
+++ b/include/linux/if_ether.h
@@ -124,12 +124,14 @@ int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr);
124extern struct ctl_table ether_table[]; 124extern struct ctl_table ether_table[];
125#endif 125#endif
126 126
127extern ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len);
128
127/* 129/*
128 * Display a 6 byte device address (MAC) in a readable format. 130 * Display a 6 byte device address (MAC) in a readable format.
129 */ 131 */
130#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x" 132extern char *print_mac(char *buf, const unsigned char *addr);
131extern char *print_mac(char *buf, const u8 *addr); 133#define MAC_BUF_SIZE 18
132#define DECLARE_MAC_BUF(var) char var[18] __maybe_unused 134#define DECLARE_MAC_BUF(var) char var[MAC_BUF_SIZE] __maybe_unused
133 135
134#endif 136#endif
135 137
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index e41f4b9d2e7e..7635d3f72723 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -95,17 +95,6 @@ NETDEVICE_SHOW(type, fmt_dec);
95NETDEVICE_SHOW(link_mode, fmt_dec); 95NETDEVICE_SHOW(link_mode, fmt_dec);
96 96
97/* use same locking rules as GIFHWADDR ioctl's */ 97/* use same locking rules as GIFHWADDR ioctl's */
98static ssize_t format_addr(char *buf, const unsigned char *addr, int len)
99{
100 int i;
101 char *cp = buf;
102
103 for (i = 0; i < len; i++)
104 cp += sprintf(cp, "%02x%c", addr[i],
105 i == (len - 1) ? '\n' : ':');
106 return cp - buf;
107}
108
109static ssize_t show_address(struct device *dev, struct device_attribute *attr, 98static ssize_t show_address(struct device *dev, struct device_attribute *attr,
110 char *buf) 99 char *buf)
111{ 100{
@@ -114,7 +103,7 @@ static ssize_t show_address(struct device *dev, struct device_attribute *attr,
114 103
115 read_lock(&dev_base_lock); 104 read_lock(&dev_base_lock);
116 if (dev_isalive(net)) 105 if (dev_isalive(net))
117 ret = format_addr(buf, net->dev_addr, net->addr_len); 106 ret = sysfs_format_mac(buf, net->dev_addr, net->addr_len);
118 read_unlock(&dev_base_lock); 107 read_unlock(&dev_base_lock);
119 return ret; 108 return ret;
120} 109}
@@ -124,7 +113,7 @@ static ssize_t show_broadcast(struct device *dev,
124{ 113{
125 struct net_device *net = to_net_dev(dev); 114 struct net_device *net = to_net_dev(dev);
126 if (dev_isalive(net)) 115 if (dev_isalive(net))
127 return format_addr(buf, net->broadcast, net->addr_len); 116 return sysfs_format_mac(buf, net->broadcast, net->addr_len);
128 return -EINVAL; 117 return -EINVAL;
129} 118}
130 119
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 6b2e454ae313..a7b417523e9b 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -359,10 +359,34 @@ struct net_device *alloc_etherdev_mq(int sizeof_priv, unsigned int queue_count)
359} 359}
360EXPORT_SYMBOL(alloc_etherdev_mq); 360EXPORT_SYMBOL(alloc_etherdev_mq);
361 361
362char *print_mac(char *buf, const u8 *addr) 362static size_t _format_mac_addr(char *buf, int buflen,
363 const unsigned char *addr, int len)
363{ 364{
364 sprintf(buf, MAC_FMT, 365 int i;
365 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); 366 char *cp = buf;
367
368 for (i = 0; i < len; i++) {
369 cp += scnprintf(cp, buflen - (cp - buf), "%02x", addr[i]);
370 if (i == len - 1)
371 break;
372 cp += strlcpy(cp, ":", buflen - (cp - buf));
373 }
374 return cp - buf;
375}
376
377ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
378{
379 size_t l;
380
381 l = _format_mac_addr(buf, PAGE_SIZE, addr, len);
382 l += strlcpy(buf + l, "\n", PAGE_SIZE - l);
383 return ((ssize_t) l);
384}
385EXPORT_SYMBOL(sysfs_format_mac);
386
387char *print_mac(char *buf, const unsigned char *addr)
388{
389 _format_mac_addr(buf, MAC_BUF_SIZE, addr, ETH_ALEN);
366 return buf; 390 return buf;
367} 391}
368EXPORT_SYMBOL(print_mac); 392EXPORT_SYMBOL(print_mac);