wifi: wext: avoid extra calls to strlen() in ieee80211_bss()
authorDmitry Antipov <dmantipov@yandex.ru>
Tue, 12 Sep 2023 03:55:16 +0000 (06:55 +0300)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 13 Sep 2023 08:20:49 +0000 (10:20 +0200)
Since 'sprintf()' returns the number of characters emitted, an
extra calls to 'strlen()' in 'ieee80211_bss()' may be dropped.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Link: https://lore.kernel.org/r/20230912035522.15947-1-dmantipov@yandex.ru
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/wireless/scan.c

index 19516073c6d5c7a790a04b0c193d71593a208150..ae4d000009feab31fba7fa2af5fd1c827e98afe5 100644 (file)
@@ -3422,59 +3422,63 @@ ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
                        cfg = (u8 *)ie + 2;
                        memset(&iwe, 0, sizeof(iwe));
                        iwe.cmd = IWEVCUSTOM;
-                       sprintf(buf, "Mesh Network Path Selection Protocol ID: "
-                               "0x%02X", cfg[0]);
-                       iwe.u.data.length = strlen(buf);
+                       iwe.u.data.length = sprintf(buf,
+                                                   "Mesh Network Path Selection Protocol ID: 0x%02X",
+                                                   cfg[0]);
                        current_ev = iwe_stream_add_point_check(info,
                                                                current_ev,
                                                                end_buf,
                                                                &iwe, buf);
                        if (IS_ERR(current_ev))
                                goto unlock;
-                       sprintf(buf, "Path Selection Metric ID: 0x%02X",
-                               cfg[1]);
-                       iwe.u.data.length = strlen(buf);
+                       iwe.u.data.length = sprintf(buf,
+                                                   "Path Selection Metric ID: 0x%02X",
+                                                   cfg[1]);
                        current_ev = iwe_stream_add_point_check(info,
                                                                current_ev,
                                                                end_buf,
                                                                &iwe, buf);
                        if (IS_ERR(current_ev))
                                goto unlock;
-                       sprintf(buf, "Congestion Control Mode ID: 0x%02X",
-                               cfg[2]);
-                       iwe.u.data.length = strlen(buf);
+                       iwe.u.data.length = sprintf(buf,
+                                                   "Congestion Control Mode ID: 0x%02X",
+                                                   cfg[2]);
                        current_ev = iwe_stream_add_point_check(info,
                                                                current_ev,
                                                                end_buf,
                                                                &iwe, buf);
                        if (IS_ERR(current_ev))
                                goto unlock;
-                       sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
-                       iwe.u.data.length = strlen(buf);
+                       iwe.u.data.length = sprintf(buf,
+                                                   "Synchronization ID: 0x%02X",
+                                                   cfg[3]);
                        current_ev = iwe_stream_add_point_check(info,
                                                                current_ev,
                                                                end_buf,
                                                                &iwe, buf);
                        if (IS_ERR(current_ev))
                                goto unlock;
-                       sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
-                       iwe.u.data.length = strlen(buf);
+                       iwe.u.data.length = sprintf(buf,
+                                                   "Authentication ID: 0x%02X",
+                                                   cfg[4]);
                        current_ev = iwe_stream_add_point_check(info,
                                                                current_ev,
                                                                end_buf,
                                                                &iwe, buf);
                        if (IS_ERR(current_ev))
                                goto unlock;
-                       sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
-                       iwe.u.data.length = strlen(buf);
+                       iwe.u.data.length = sprintf(buf,
+                                                   "Formation Info: 0x%02X",
+                                                   cfg[5]);
                        current_ev = iwe_stream_add_point_check(info,
                                                                current_ev,
                                                                end_buf,
                                                                &iwe, buf);
                        if (IS_ERR(current_ev))
                                goto unlock;
-                       sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
-                       iwe.u.data.length = strlen(buf);
+                       iwe.u.data.length = sprintf(buf,
+                                                   "Capabilities: 0x%02X",
+                                                   cfg[6]);
                        current_ev = iwe_stream_add_point_check(info,
                                                                current_ev,
                                                                end_buf,
@@ -3530,17 +3534,16 @@ ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
 
        memset(&iwe, 0, sizeof(iwe));
        iwe.cmd = IWEVCUSTOM;
-       sprintf(buf, "tsf=%016llx", (unsigned long long)(ies->tsf));
-       iwe.u.data.length = strlen(buf);
+       iwe.u.data.length = sprintf(buf, "tsf=%016llx",
+                                   (unsigned long long)(ies->tsf));
        current_ev = iwe_stream_add_point_check(info, current_ev, end_buf,
                                                &iwe, buf);
        if (IS_ERR(current_ev))
                goto unlock;
        memset(&iwe, 0, sizeof(iwe));
        iwe.cmd = IWEVCUSTOM;
-       sprintf(buf, " Last beacon: %ums ago",
-               elapsed_jiffies_msecs(bss->ts));
-       iwe.u.data.length = strlen(buf);
+       iwe.u.data.length = sprintf(buf, " Last beacon: %ums ago",
+                                   elapsed_jiffies_msecs(bss->ts));
        current_ev = iwe_stream_add_point_check(info, current_ev,
                                                end_buf, &iwe, buf);
        if (IS_ERR(current_ev))