Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: atm: use %*ph to print small buffer

Use %*ph format to print small buffer as hex string.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Andy Shevchenko and committed by
David S. Miller
79ac5224 edc7e489

+28 -70
+8 -14
net/atm/atm_sysfs.c
··· 33 33 unsigned long flags; 34 34 struct atm_dev *adev = to_atm_dev(cdev); 35 35 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; 38 37 39 38 spin_lock_irqsave(&adev->lock, flags); 40 39 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]); 53 47 } 54 48 spin_unlock_irqrestore(&adev->lock, flags); 55 49
+20 -56
net/atm/lec.c
··· 799 799 800 800 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry) 801 801 { 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), 810 805 entry->flags & 0xffff); 811 806 if (entry->vcc) 812 807 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci); ··· 1349 1354 { 1350 1355 struct lec_arp_table *rulla; 1351 1356 char buf[256]; 1352 - int i, j, offset; 1357 + int i, offset; 1353 1358 1354 1359 pr_info("Dump %p:\n", priv); 1355 1360 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { ··· 1357 1362 &priv->lec_arp_tables[i], next) { 1358 1363 offset = 0; 1359 1364 offset += sprintf(buf, "%d: %p\n", i, rulla); 1360 - offset += sprintf(buf + offset, "Mac: %pM", 1365 + offset += sprintf(buf + offset, "Mac: %pM ", 1361 1366 rulla->mac_addr); 1362 - offset += sprintf(buf + offset, " Atm:"); 1363 - for (j = 0; j < ATM_ESA_LEN; j++) { 1364 - offset += sprintf(buf + offset, 1365 - "%2.2x ", 1366 - rulla->atm_addr[j] & 0xff); 1367 - } 1367 + offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN, 1368 + rulla->atm_addr); 1368 1369 offset += sprintf(buf + offset, 1369 1370 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", 1370 1371 rulla->vcc ? rulla->vcc->vpi : 0, ··· 1383 1392 pr_info("No forward\n"); 1384 1393 hlist_for_each_entry(rulla, &priv->lec_no_forward, next) { 1385 1394 offset = 0; 1386 - offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr); 1387 - offset += sprintf(buf + offset, " Atm:"); 1388 - for (j = 0; j < ATM_ESA_LEN; j++) { 1389 - offset += sprintf(buf + offset, "%2.2x ", 1390 - rulla->atm_addr[j] & 0xff); 1391 - } 1395 + offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr); 1396 + offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN, 1397 + rulla->atm_addr); 1392 1398 offset += sprintf(buf + offset, 1393 1399 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", 1394 1400 rulla->vcc ? rulla->vcc->vpi : 0, ··· 1405 1417 pr_info("Empty ones\n"); 1406 1418 hlist_for_each_entry(rulla, &priv->lec_arp_empty_ones, next) { 1407 1419 offset = 0; 1408 - offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr); 1409 - offset += sprintf(buf + offset, " Atm:"); 1410 - for (j = 0; j < ATM_ESA_LEN; j++) { 1411 - offset += sprintf(buf + offset, "%2.2x ", 1412 - rulla->atm_addr[j] & 0xff); 1413 - } 1420 + offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr); 1421 + offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN, 1422 + rulla->atm_addr); 1414 1423 offset += sprintf(buf + offset, 1415 1424 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", 1416 1425 rulla->vcc ? rulla->vcc->vpi : 0, ··· 1427 1442 pr_info("Multicast Forward VCCs\n"); 1428 1443 hlist_for_each_entry(rulla, &priv->mcast_fwds, next) { 1429 1444 offset = 0; 1430 - offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr); 1431 - offset += sprintf(buf + offset, " Atm:"); 1432 - for (j = 0; j < ATM_ESA_LEN; j++) { 1433 - offset += sprintf(buf + offset, "%2.2x ", 1434 - rulla->atm_addr[j] & 0xff); 1435 - } 1445 + offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr); 1446 + offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN, 1447 + rulla->atm_addr); 1436 1448 offset += sprintf(buf + offset, 1437 1449 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ", 1438 1450 rulla->vcc ? rulla->vcc->vpi : 0, ··· 1955 1973 * Vcc which we don't want to make default vcc, 1956 1974 * attach it anyway. 1957 1975 */ 1958 - 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", 1959 - ioc_data->atm_addr[0], ioc_data->atm_addr[1], 1960 - ioc_data->atm_addr[2], ioc_data->atm_addr[3], 1961 - ioc_data->atm_addr[4], ioc_data->atm_addr[5], 1962 - ioc_data->atm_addr[6], ioc_data->atm_addr[7], 1963 - ioc_data->atm_addr[8], ioc_data->atm_addr[9], 1964 - ioc_data->atm_addr[10], ioc_data->atm_addr[11], 1965 - ioc_data->atm_addr[12], ioc_data->atm_addr[13], 1966 - ioc_data->atm_addr[14], ioc_data->atm_addr[15], 1967 - ioc_data->atm_addr[16], ioc_data->atm_addr[17], 1968 - ioc_data->atm_addr[18], ioc_data->atm_addr[19]); 1976 + pr_debug("LEC_ARP:Attaching data direct, not default: %*phN\n", 1977 + ATM_ESA_LEN, ioc_data->atm_addr); 1969 1978 entry = make_entry(priv, bus_mac); 1970 1979 if (entry == NULL) 1971 1980 goto out; ··· 1972 1999 dump_arp_table(priv); 1973 2000 goto out; 1974 2001 } 1975 - 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", 1976 - ioc_data->atm_addr[0], ioc_data->atm_addr[1], 1977 - ioc_data->atm_addr[2], ioc_data->atm_addr[3], 1978 - ioc_data->atm_addr[4], ioc_data->atm_addr[5], 1979 - ioc_data->atm_addr[6], ioc_data->atm_addr[7], 1980 - ioc_data->atm_addr[8], ioc_data->atm_addr[9], 1981 - ioc_data->atm_addr[10], ioc_data->atm_addr[11], 1982 - ioc_data->atm_addr[12], ioc_data->atm_addr[13], 1983 - ioc_data->atm_addr[14], ioc_data->atm_addr[15], 1984 - ioc_data->atm_addr[16], ioc_data->atm_addr[17], 1985 - ioc_data->atm_addr[18], ioc_data->atm_addr[19]); 2002 + pr_debug("LEC_ARP:Attaching data direct, default: %*phN\n", 2003 + ATM_ESA_LEN, ioc_data->atm_addr); 1986 2004 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) { 1987 2005 hlist_for_each_entry(entry, 1988 2006 &priv->lec_arp_tables[i], next) {