Skip to content

Commit 22446b7

Browse files
dmantipovjmberg-intel
authored andcommitted
wifi: wext: avoid extra calls to strlen() in ieee80211_bss()
Since 'sprintf()' returns the number of characters emitted, an extra calls to 'strlen()' in 'ieee80211_bss()' may be dropped. Signed-off-by: Dmitry Antipov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent 8c73d52 commit 22446b7

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

net/wireless/scan.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,59 +3422,63 @@ ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
34223422
cfg = (u8 *)ie + 2;
34233423
memset(&iwe, 0, sizeof(iwe));
34243424
iwe.cmd = IWEVCUSTOM;
3425-
sprintf(buf, "Mesh Network Path Selection Protocol ID: "
3426-
"0x%02X", cfg[0]);
3427-
iwe.u.data.length = strlen(buf);
3425+
iwe.u.data.length = sprintf(buf,
3426+
"Mesh Network Path Selection Protocol ID: 0x%02X",
3427+
cfg[0]);
34283428
current_ev = iwe_stream_add_point_check(info,
34293429
current_ev,
34303430
end_buf,
34313431
&iwe, buf);
34323432
if (IS_ERR(current_ev))
34333433
goto unlock;
3434-
sprintf(buf, "Path Selection Metric ID: 0x%02X",
3435-
cfg[1]);
3436-
iwe.u.data.length = strlen(buf);
3434+
iwe.u.data.length = sprintf(buf,
3435+
"Path Selection Metric ID: 0x%02X",
3436+
cfg[1]);
34373437
current_ev = iwe_stream_add_point_check(info,
34383438
current_ev,
34393439
end_buf,
34403440
&iwe, buf);
34413441
if (IS_ERR(current_ev))
34423442
goto unlock;
3443-
sprintf(buf, "Congestion Control Mode ID: 0x%02X",
3444-
cfg[2]);
3445-
iwe.u.data.length = strlen(buf);
3443+
iwe.u.data.length = sprintf(buf,
3444+
"Congestion Control Mode ID: 0x%02X",
3445+
cfg[2]);
34463446
current_ev = iwe_stream_add_point_check(info,
34473447
current_ev,
34483448
end_buf,
34493449
&iwe, buf);
34503450
if (IS_ERR(current_ev))
34513451
goto unlock;
3452-
sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
3453-
iwe.u.data.length = strlen(buf);
3452+
iwe.u.data.length = sprintf(buf,
3453+
"Synchronization ID: 0x%02X",
3454+
cfg[3]);
34543455
current_ev = iwe_stream_add_point_check(info,
34553456
current_ev,
34563457
end_buf,
34573458
&iwe, buf);
34583459
if (IS_ERR(current_ev))
34593460
goto unlock;
3460-
sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
3461-
iwe.u.data.length = strlen(buf);
3461+
iwe.u.data.length = sprintf(buf,
3462+
"Authentication ID: 0x%02X",
3463+
cfg[4]);
34623464
current_ev = iwe_stream_add_point_check(info,
34633465
current_ev,
34643466
end_buf,
34653467
&iwe, buf);
34663468
if (IS_ERR(current_ev))
34673469
goto unlock;
3468-
sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
3469-
iwe.u.data.length = strlen(buf);
3470+
iwe.u.data.length = sprintf(buf,
3471+
"Formation Info: 0x%02X",
3472+
cfg[5]);
34703473
current_ev = iwe_stream_add_point_check(info,
34713474
current_ev,
34723475
end_buf,
34733476
&iwe, buf);
34743477
if (IS_ERR(current_ev))
34753478
goto unlock;
3476-
sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
3477-
iwe.u.data.length = strlen(buf);
3479+
iwe.u.data.length = sprintf(buf,
3480+
"Capabilities: 0x%02X",
3481+
cfg[6]);
34783482
current_ev = iwe_stream_add_point_check(info,
34793483
current_ev,
34803484
end_buf,
@@ -3530,17 +3534,16 @@ ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
35303534

35313535
memset(&iwe, 0, sizeof(iwe));
35323536
iwe.cmd = IWEVCUSTOM;
3533-
sprintf(buf, "tsf=%016llx", (unsigned long long)(ies->tsf));
3534-
iwe.u.data.length = strlen(buf);
3537+
iwe.u.data.length = sprintf(buf, "tsf=%016llx",
3538+
(unsigned long long)(ies->tsf));
35353539
current_ev = iwe_stream_add_point_check(info, current_ev, end_buf,
35363540
&iwe, buf);
35373541
if (IS_ERR(current_ev))
35383542
goto unlock;
35393543
memset(&iwe, 0, sizeof(iwe));
35403544
iwe.cmd = IWEVCUSTOM;
3541-
sprintf(buf, " Last beacon: %ums ago",
3542-
elapsed_jiffies_msecs(bss->ts));
3543-
iwe.u.data.length = strlen(buf);
3545+
iwe.u.data.length = sprintf(buf, " Last beacon: %ums ago",
3546+
elapsed_jiffies_msecs(bss->ts));
35443547
current_ev = iwe_stream_add_point_check(info, current_ev,
35453548
end_buf, &iwe, buf);
35463549
if (IS_ERR(current_ev))

0 commit comments

Comments
 (0)