Skip to content

Commit 79ac522

Browse files
andy-shevdavem330
authored andcommitted
net: atm: use %*ph to print small buffer
Use %*ph format to print small buffer as hex string. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent edc7e48 commit 79ac522

File tree

2 files changed

+28
-70
lines changed

2 files changed

+28
-70
lines changed

net/atm/atm_sysfs.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,17 @@ static ssize_t show_atmaddress(struct device *cdev,
3333
unsigned long flags;
3434
struct atm_dev *adev = to_atm_dev(cdev);
3535
struct atm_dev_addr *aaddr;
36-
int bin[] = { 1, 2, 10, 6, 1 }, *fmt = bin;
37-
int i, j, count = 0;
36+
int count = 0;
3837

3938
spin_lock_irqsave(&adev->lock, flags);
4039
list_for_each_entry(aaddr, &adev->local, entry) {
41-
for (i = 0, j = 0; i < ATM_ESA_LEN; ++i, ++j) {
42-
if (j == *fmt) {
43-
count += scnprintf(buf + count,
44-
PAGE_SIZE - count, ".");
45-
++fmt;
46-
j = 0;
47-
}
48-
count += scnprintf(buf + count,
49-
PAGE_SIZE - count, "%02x",
50-
aaddr->addr.sas_addr.prv[i]);
51-
}
52-
count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
40+
count += scnprintf(buf + count, PAGE_SIZE - count,
41+
"%1phN.%2phN.%10phN.%6phN.%1phN\n",
42+
&aaddr->addr.sas_addr.prv[0],
43+
&aaddr->addr.sas_addr.prv[1],
44+
&aaddr->addr.sas_addr.prv[3],
45+
&aaddr->addr.sas_addr.prv[13],
46+
&aaddr->addr.sas_addr.prv[19]);
5347
}
5448
spin_unlock_irqrestore(&adev->lock, flags);
5549

net/atm/lec.c

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -799,14 +799,9 @@ static const char *lec_arp_get_status_string(unsigned char status)
799799

800800
static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
801801
{
802-
int i;
803-
804-
for (i = 0; i < ETH_ALEN; i++)
805-
seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
806-
seq_printf(seq, " ");
807-
for (i = 0; i < ATM_ESA_LEN; i++)
808-
seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
809-
seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
802+
seq_printf(seq, "%pM ", entry->mac_addr);
803+
seq_printf(seq, "%*phN ", ATM_ESA_LEN, entry->atm_addr);
804+
seq_printf(seq, "%s %4.4x", lec_arp_get_status_string(entry->status),
810805
entry->flags & 0xffff);
811806
if (entry->vcc)
812807
seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
@@ -1354,22 +1349,18 @@ static void dump_arp_table(struct lec_priv *priv)
13541349
{
13551350
struct lec_arp_table *rulla;
13561351
char buf[256];
1357-
int i, j, offset;
1352+
int i, offset;
13581353

13591354
pr_info("Dump %p:\n", priv);
13601355
for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
13611356
hlist_for_each_entry(rulla,
13621357
&priv->lec_arp_tables[i], next) {
13631358
offset = 0;
13641359
offset += sprintf(buf, "%d: %p\n", i, rulla);
1365-
offset += sprintf(buf + offset, "Mac: %pM",
1360+
offset += sprintf(buf + offset, "Mac: %pM ",
13661361
rulla->mac_addr);
1367-
offset += sprintf(buf + offset, " Atm:");
1368-
for (j = 0; j < ATM_ESA_LEN; j++) {
1369-
offset += sprintf(buf + offset,
1370-
"%2.2x ",
1371-
rulla->atm_addr[j] & 0xff);
1372-
}
1362+
offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN,
1363+
rulla->atm_addr);
13731364
offset += sprintf(buf + offset,
13741365
"Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
13751366
rulla->vcc ? rulla->vcc->vpi : 0,
@@ -1392,12 +1383,9 @@ static void dump_arp_table(struct lec_priv *priv)
13921383
pr_info("No forward\n");
13931384
hlist_for_each_entry(rulla, &priv->lec_no_forward, next) {
13941385
offset = 0;
1395-
offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1396-
offset += sprintf(buf + offset, " Atm:");
1397-
for (j = 0; j < ATM_ESA_LEN; j++) {
1398-
offset += sprintf(buf + offset, "%2.2x ",
1399-
rulla->atm_addr[j] & 0xff);
1400-
}
1386+
offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr);
1387+
offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN,
1388+
rulla->atm_addr);
14011389
offset += sprintf(buf + offset,
14021390
"Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
14031391
rulla->vcc ? rulla->vcc->vpi : 0,
@@ -1417,12 +1405,9 @@ static void dump_arp_table(struct lec_priv *priv)
14171405
pr_info("Empty ones\n");
14181406
hlist_for_each_entry(rulla, &priv->lec_arp_empty_ones, next) {
14191407
offset = 0;
1420-
offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1421-
offset += sprintf(buf + offset, " Atm:");
1422-
for (j = 0; j < ATM_ESA_LEN; j++) {
1423-
offset += sprintf(buf + offset, "%2.2x ",
1424-
rulla->atm_addr[j] & 0xff);
1425-
}
1408+
offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr);
1409+
offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN,
1410+
rulla->atm_addr);
14261411
offset += sprintf(buf + offset,
14271412
"Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
14281413
rulla->vcc ? rulla->vcc->vpi : 0,
@@ -1442,12 +1427,9 @@ static void dump_arp_table(struct lec_priv *priv)
14421427
pr_info("Multicast Forward VCCs\n");
14431428
hlist_for_each_entry(rulla, &priv->mcast_fwds, next) {
14441429
offset = 0;
1445-
offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1446-
offset += sprintf(buf + offset, " Atm:");
1447-
for (j = 0; j < ATM_ESA_LEN; j++) {
1448-
offset += sprintf(buf + offset, "%2.2x ",
1449-
rulla->atm_addr[j] & 0xff);
1450-
}
1430+
offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr);
1431+
offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN,
1432+
rulla->atm_addr);
14511433
offset += sprintf(buf + offset,
14521434
"Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
14531435
rulla->vcc ? rulla->vcc->vpi : 0,
@@ -1973,17 +1955,8 @@ lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
19731955
* Vcc which we don't want to make default vcc,
19741956
* attach it anyway.
19751957
*/
1976-
pr_debug("LEC_ARP:Attaching data direct, not default: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
1977-
ioc_data->atm_addr[0], ioc_data->atm_addr[1],
1978-
ioc_data->atm_addr[2], ioc_data->atm_addr[3],
1979-
ioc_data->atm_addr[4], ioc_data->atm_addr[5],
1980-
ioc_data->atm_addr[6], ioc_data->atm_addr[7],
1981-
ioc_data->atm_addr[8], ioc_data->atm_addr[9],
1982-
ioc_data->atm_addr[10], ioc_data->atm_addr[11],
1983-
ioc_data->atm_addr[12], ioc_data->atm_addr[13],
1984-
ioc_data->atm_addr[14], ioc_data->atm_addr[15],
1985-
ioc_data->atm_addr[16], ioc_data->atm_addr[17],
1986-
ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
1958+
pr_debug("LEC_ARP:Attaching data direct, not default: %*phN\n",
1959+
ATM_ESA_LEN, ioc_data->atm_addr);
19871960
entry = make_entry(priv, bus_mac);
19881961
if (entry == NULL)
19891962
goto out;
@@ -1999,17 +1972,8 @@ lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
19991972
dump_arp_table(priv);
20001973
goto out;
20011974
}
2002-
pr_debug("LEC_ARP:Attaching data direct, default: %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2003-
ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2004-
ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2005-
ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2006-
ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2007-
ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2008-
ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2009-
ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2010-
ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2011-
ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2012-
ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
1975+
pr_debug("LEC_ARP:Attaching data direct, default: %*phN\n",
1976+
ATM_ESA_LEN, ioc_data->atm_addr);
20131977
for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
20141978
hlist_for_each_entry(entry,
20151979
&priv->lec_arp_tables[i], next) {

0 commit comments

Comments
 (0)