aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bond_sysfs.c
diff options
context:
space:
mode:
authorWagner Ferenc <wferi@niif.hu>2007-12-07 02:40:28 -0500
committerJeff Garzik <jeff@garzik.org>2007-12-07 15:00:18 -0500
commit7bd4650895137760f6c686d06ca2bc174e3c861c (patch)
treeaecdf098f1bb5ef2e16afe9e6b63bfb87617bbfc /drivers/net/bonding/bond_sysfs.c
parent2c5ea0f2d8c7d4883dd0d8ec3c7e3f3640b4f814 (diff)
bonding: Remove trailing NULs from sysfs interface.
From: Wagner Ferenc <wferi@niif.hu> Also remove trailing spaces from multivalued files. This fixes output like for example: $ od -c /sys/class/net/bond0/bonding/slaves 0000000 e t h - l e f t e t h - r i g 0000020 h t \n \0 0000025 It mostly entails deleting '+1'-s after sprintf() calls: the return value of sprintf is the number of characters printed, without the closing NUL, ie. exactly what the sysfs interface requires. The three multivalue cases are different, because they also have to swallow back a trailing space. Signed-off-by: Ferenc Wagner <wferi@niif.hu> Acked-by: Jay Vosburgh <fubar@us.ibm.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/net/bonding/bond_sysfs.c')
-rw-r--r--drivers/net/bonding/bond_sysfs.c66
1 files changed, 30 insertions, 36 deletions
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index b29330d8e309..a3f1b4afb40a 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -86,14 +86,13 @@ static ssize_t bonding_show_bonds(struct class *cls, char *buffer)
86 /* not enough space for another interface name */ 86 /* not enough space for another interface name */
87 if ((PAGE_SIZE - res) > 10) 87 if ((PAGE_SIZE - res) > 10)
88 res = PAGE_SIZE - 10; 88 res = PAGE_SIZE - 10;
89 res += sprintf(buffer + res, "++more++"); 89 res += sprintf(buffer + res, "++more++ ");
90 break; 90 break;
91 } 91 }
92 res += sprintf(buffer + res, "%s ", 92 res += sprintf(buffer + res, "%s ",
93 bond->dev->name); 93 bond->dev->name);
94 } 94 }
95 res += sprintf(buffer + res, "\n"); 95 if (res) buffer[res-1] = '\n'; /* eat the leftover space */
96 res++;
97 up_read(&(bonding_rwsem)); 96 up_read(&(bonding_rwsem));
98 return res; 97 return res;
99} 98}
@@ -235,14 +234,13 @@ static ssize_t bonding_show_slaves(struct device *d,
235 /* not enough space for another interface name */ 234 /* not enough space for another interface name */
236 if ((PAGE_SIZE - res) > 10) 235 if ((PAGE_SIZE - res) > 10)
237 res = PAGE_SIZE - 10; 236 res = PAGE_SIZE - 10;
238 res += sprintf(buf + res, "++more++"); 237 res += sprintf(buf + res, "++more++ ");
239 break; 238 break;
240 } 239 }
241 res += sprintf(buf + res, "%s ", slave->dev->name); 240 res += sprintf(buf + res, "%s ", slave->dev->name);
242 } 241 }
243 read_unlock(&bond->lock); 242 read_unlock(&bond->lock);
244 res += sprintf(buf + res, "\n"); 243 if (res) buf[res-1] = '\n'; /* eat the leftover space */
245 res++;
246 return res; 244 return res;
247} 245}
248 246
@@ -406,7 +404,7 @@ static ssize_t bonding_show_mode(struct device *d,
406 404
407 return sprintf(buf, "%s %d\n", 405 return sprintf(buf, "%s %d\n",
408 bond_mode_tbl[bond->params.mode].modename, 406 bond_mode_tbl[bond->params.mode].modename,
409 bond->params.mode) + 1; 407 bond->params.mode);
410} 408}
411 409
412static ssize_t bonding_store_mode(struct device *d, 410static ssize_t bonding_store_mode(struct device *d,
@@ -463,11 +461,11 @@ static ssize_t bonding_show_xmit_hash(struct device *d,
463 if ((bond->params.mode != BOND_MODE_XOR) && 461 if ((bond->params.mode != BOND_MODE_XOR) &&
464 (bond->params.mode != BOND_MODE_8023AD)) { 462 (bond->params.mode != BOND_MODE_8023AD)) {
465 // Not Applicable 463 // Not Applicable
466 count = sprintf(buf, "NA\n") + 1; 464 count = sprintf(buf, "NA\n");
467 } else { 465 } else {
468 count = sprintf(buf, "%s %d\n", 466 count = sprintf(buf, "%s %d\n",
469 xmit_hashtype_tbl[bond->params.xmit_policy].modename, 467 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
470 bond->params.xmit_policy) + 1; 468 bond->params.xmit_policy);
471 } 469 }
472 470
473 return count; 471 return count;
@@ -527,7 +525,7 @@ static ssize_t bonding_show_arp_validate(struct device *d,
527 525
528 return sprintf(buf, "%s %d\n", 526 return sprintf(buf, "%s %d\n",
529 arp_validate_tbl[bond->params.arp_validate].modename, 527 arp_validate_tbl[bond->params.arp_validate].modename,
530 bond->params.arp_validate) + 1; 528 bond->params.arp_validate);
531} 529}
532 530
533static ssize_t bonding_store_arp_validate(struct device *d, 531static ssize_t bonding_store_arp_validate(struct device *d,
@@ -627,7 +625,7 @@ static ssize_t bonding_show_arp_interval(struct device *d,
627{ 625{
628 struct bonding *bond = to_bond(d); 626 struct bonding *bond = to_bond(d);
629 627
630 return sprintf(buf, "%d\n", bond->params.arp_interval) + 1; 628 return sprintf(buf, "%d\n", bond->params.arp_interval);
631} 629}
632 630
633static ssize_t bonding_store_arp_interval(struct device *d, 631static ssize_t bonding_store_arp_interval(struct device *d,
@@ -711,10 +709,7 @@ static ssize_t bonding_show_arp_targets(struct device *d,
711 res += sprintf(buf + res, "%u.%u.%u.%u ", 709 res += sprintf(buf + res, "%u.%u.%u.%u ",
712 NIPQUAD(bond->params.arp_targets[i])); 710 NIPQUAD(bond->params.arp_targets[i]));
713 } 711 }
714 if (res) 712 if (res) buf[res-1] = '\n'; /* eat the leftover space */
715 res--; /* eat the leftover space */
716 res += sprintf(buf + res, "\n");
717 res++;
718 return res; 713 return res;
719} 714}
720 715
@@ -815,7 +810,7 @@ static ssize_t bonding_show_downdelay(struct device *d,
815{ 810{
816 struct bonding *bond = to_bond(d); 811 struct bonding *bond = to_bond(d);
817 812
818 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon) + 1; 813 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
819} 814}
820 815
821static ssize_t bonding_store_downdelay(struct device *d, 816static ssize_t bonding_store_downdelay(struct device *d,
@@ -872,7 +867,7 @@ static ssize_t bonding_show_updelay(struct device *d,
872{ 867{
873 struct bonding *bond = to_bond(d); 868 struct bonding *bond = to_bond(d);
874 869
875 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon) + 1; 870 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
876 871
877} 872}
878 873
@@ -936,7 +931,7 @@ static ssize_t bonding_show_lacp(struct device *d,
936 931
937 return sprintf(buf, "%s %d\n", 932 return sprintf(buf, "%s %d\n",
938 bond_lacp_tbl[bond->params.lacp_fast].modename, 933 bond_lacp_tbl[bond->params.lacp_fast].modename,
939 bond->params.lacp_fast) + 1; 934 bond->params.lacp_fast);
940} 935}
941 936
942static ssize_t bonding_store_lacp(struct device *d, 937static ssize_t bonding_store_lacp(struct device *d,
@@ -992,7 +987,7 @@ static ssize_t bonding_show_miimon(struct device *d,
992{ 987{
993 struct bonding *bond = to_bond(d); 988 struct bonding *bond = to_bond(d);
994 989
995 return sprintf(buf, "%d\n", bond->params.miimon) + 1; 990 return sprintf(buf, "%d\n", bond->params.miimon);
996} 991}
997 992
998static ssize_t bonding_store_miimon(struct device *d, 993static ssize_t bonding_store_miimon(struct device *d,
@@ -1083,9 +1078,9 @@ static ssize_t bonding_show_primary(struct device *d,
1083 struct bonding *bond = to_bond(d); 1078 struct bonding *bond = to_bond(d);
1084 1079
1085 if (bond->primary_slave) 1080 if (bond->primary_slave)
1086 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name) + 1; 1081 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
1087 else 1082 else
1088 count = sprintf(buf, "\n") + 1; 1083 count = sprintf(buf, "\n");
1089 1084
1090 return count; 1085 return count;
1091} 1086}
@@ -1149,7 +1144,7 @@ static ssize_t bonding_show_carrier(struct device *d,
1149{ 1144{
1150 struct bonding *bond = to_bond(d); 1145 struct bonding *bond = to_bond(d);
1151 1146
1152 return sprintf(buf, "%d\n", bond->params.use_carrier) + 1; 1147 return sprintf(buf, "%d\n", bond->params.use_carrier);
1153} 1148}
1154 1149
1155static ssize_t bonding_store_carrier(struct device *d, 1150static ssize_t bonding_store_carrier(struct device *d,
@@ -1198,9 +1193,9 @@ static ssize_t bonding_show_active_slave(struct device *d,
1198 read_unlock(&bond->curr_slave_lock); 1193 read_unlock(&bond->curr_slave_lock);
1199 1194
1200 if (USES_PRIMARY(bond->params.mode) && curr) 1195 if (USES_PRIMARY(bond->params.mode) && curr)
1201 count = sprintf(buf, "%s\n", curr->dev->name) + 1; 1196 count = sprintf(buf, "%s\n", curr->dev->name);
1202 else 1197 else
1203 count = sprintf(buf, "\n") + 1; 1198 count = sprintf(buf, "\n");
1204 return count; 1199 return count;
1205} 1200}
1206 1201
@@ -1295,7 +1290,7 @@ static ssize_t bonding_show_mii_status(struct device *d,
1295 curr = bond->curr_active_slave; 1290 curr = bond->curr_active_slave;
1296 read_unlock(&bond->curr_slave_lock); 1291 read_unlock(&bond->curr_slave_lock);
1297 1292
1298 return sprintf(buf, "%s\n", (curr) ? "up" : "down") + 1; 1293 return sprintf(buf, "%s\n", (curr) ? "up" : "down");
1299} 1294}
1300static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); 1295static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
1301 1296
@@ -1312,10 +1307,10 @@ static ssize_t bonding_show_ad_aggregator(struct device *d,
1312 1307
1313 if (bond->params.mode == BOND_MODE_8023AD) { 1308 if (bond->params.mode == BOND_MODE_8023AD) {
1314 struct ad_info ad_info; 1309 struct ad_info ad_info;
1315 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.aggregator_id) + 1; 1310 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.aggregator_id);
1316 } 1311 }
1317 else 1312 else
1318 count = sprintf(buf, "\n") + 1; 1313 count = sprintf(buf, "\n");
1319 1314
1320 return count; 1315 return count;
1321} 1316}
@@ -1334,10 +1329,10 @@ static ssize_t bonding_show_ad_num_ports(struct device *d,
1334 1329
1335 if (bond->params.mode == BOND_MODE_8023AD) { 1330 if (bond->params.mode == BOND_MODE_8023AD) {
1336 struct ad_info ad_info; 1331 struct ad_info ad_info;
1337 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0: ad_info.ports) + 1; 1332 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0: ad_info.ports);
1338 } 1333 }
1339 else 1334 else
1340 count = sprintf(buf, "\n") + 1; 1335 count = sprintf(buf, "\n");
1341 1336
1342 return count; 1337 return count;
1343} 1338}
@@ -1356,10 +1351,10 @@ static ssize_t bonding_show_ad_actor_key(struct device *d,
1356 1351
1357 if (bond->params.mode == BOND_MODE_8023AD) { 1352 if (bond->params.mode == BOND_MODE_8023AD) {
1358 struct ad_info ad_info; 1353 struct ad_info ad_info;
1359 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.actor_key) + 1; 1354 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.actor_key);
1360 } 1355 }
1361 else 1356 else
1362 count = sprintf(buf, "\n") + 1; 1357 count = sprintf(buf, "\n");
1363 1358
1364 return count; 1359 return count;
1365} 1360}
@@ -1378,10 +1373,10 @@ static ssize_t bonding_show_ad_partner_key(struct device *d,
1378 1373
1379 if (bond->params.mode == BOND_MODE_8023AD) { 1374 if (bond->params.mode == BOND_MODE_8023AD) {
1380 struct ad_info ad_info; 1375 struct ad_info ad_info;
1381 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.partner_key) + 1; 1376 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.partner_key);
1382 } 1377 }
1383 else 1378 else
1384 count = sprintf(buf, "\n") + 1; 1379 count = sprintf(buf, "\n");
1385 1380
1386 return count; 1381 return count;
1387} 1382}
@@ -1403,12 +1398,11 @@ static ssize_t bonding_show_ad_partner_mac(struct device *d,
1403 struct ad_info ad_info; 1398 struct ad_info ad_info;
1404 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) { 1399 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
1405 count = sprintf(buf,"%s\n", 1400 count = sprintf(buf,"%s\n",
1406 print_mac(mac, ad_info.partner_system)) 1401 print_mac(mac, ad_info.partner_system));
1407 + 1;
1408 } 1402 }
1409 } 1403 }
1410 else 1404 else
1411 count = sprintf(buf, "\n") + 1; 1405 count = sprintf(buf, "\n");
1412 1406
1413 return count; 1407 return count;
1414} 1408}