Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2974959rdb; Tue, 12 Sep 2023 19:41:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFrxz8Ztxgmh4qR24qrhgZ2htgUdXCFApeaz178G1CB05Miidi3xec3e+30765K3OGhCVh X-Received: by 2002:a05:620a:46a1:b0:770:6330:40b with SMTP id bq33-20020a05620a46a100b007706330040bmr1323433qkb.50.1694572892875; Tue, 12 Sep 2023 19:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694572892; cv=none; d=google.com; s=arc-20160816; b=hzSbL5jb1t/reVJlv+GElRbdll78ty3TyOoZ9bxM836R+u13gMLWDere5QquFCw9ux LcQJLE43KXCm2236qjybNoUsjkPePZgNXnJJi8rbdY2Y4PSb7dBSXVJ/we4CQI4hy8Fp QibHjNC0yWQJ6d3flA+m1Su84uTuwvnZfVMMMgkZrl5jTPX8QnlHieyIeuEVtuRnI2gp TQSNx6EzaODVKWRFMH/5PzybD2bNKCbImVleaHkFUGfkWQk/wt4jan4xs0FSC/6+sXO9 ouI+TZV4ql3eGsvQeNwG9XS0Jy/6bzxojPDBNh4S9ppg+T06yPtZQxk33BaNZubXKdxh pAKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HQHpdCNxOgavGCACxBEm1fIIDbU9uZjMRsmpfRLKIi0=; fh=WZGjAHbGg538ZOmzRG19w/5QYPk9QMdQGI5nqGmeF5c=; b=T+JeAkpl3vsq2wCSqS5icTj1NAVpSSn9JrDM1ZUeBU5xbNA6C+94OKgx6oipZ9eYCs TQALhHDwvQ6JD88qMzJ8hKj1/DZRkTp6/H5fYl6E2Fq1Mr+sR+ITdB8h1DvZXCJh91FY S3UqK+5eHraQh2HokoUHKg8X1X3p+dgm35PNSG1DMzCGwwvlfS6LvZSWZmdXcpesxk6c EAifTeAaD79NNxaRNvPIe+cCZSZ95yuwatyHEsVFdIS20CUblmMZ+XuxtX5u12s7lOIq qTA3z8U+v3BQxn37RbGB/GttN3+O2YNTnMDf4gcLd7smfPb0YXAlbWOTcr+4Pf+p6mjN Dr/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=vjZCROnj; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e24-20020a63e018000000b005740b47241csi8870982pgh.804.2023.09.12.19.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 19:41:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=vjZCROnj; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D2BAA812DBFF; Mon, 11 Sep 2023 21:25:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbjILD43 (ORCPT + 55 others); Mon, 11 Sep 2023 23:56:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237703AbjILD4Z (ORCPT ); Mon, 11 Sep 2023 23:56:25 -0400 Received: from forward103b.mail.yandex.net (forward103b.mail.yandex.net [178.154.239.150]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BAA01BB for ; Mon, 11 Sep 2023 20:56:20 -0700 (PDT) Received: from mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:3a91:0:640:b9f:0]) by forward103b.mail.yandex.net (Yandex) with ESMTP id 3466A60060; Tue, 12 Sep 2023 06:56:17 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id GuUv4EnDReA0-vacpplch; Tue, 12 Sep 2023 06:56:16 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1694490976; bh=HQHpdCNxOgavGCACxBEm1fIIDbU9uZjMRsmpfRLKIi0=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=vjZCROnjR6LX4GU+SHIiiqtIevD11Tuq2l53ySdBNIwQJNdz2SanpeN9aSN3OqpVh kP5i4qGV5FFUnr3Yact8mFAPtuMDm3bYxKHUOn4FNerAUMxt6030GUX1hIvd+3fMlr xcdSQRlB4pLUIaWFsbZktJk1Gn7F3QvnRs/vZlI8= Authentication-Results: mail-nwsmtp-smtp-production-main-23.myt.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Johannes Berg Cc: linux-wireless@vger.kernel.org, Dmitry Antipov Subject: [PATCH] [v2] wifi: wext: avoid extra calls to strlen() in ieee80211_bss() Date: Tue, 12 Sep 2023 06:55:16 +0300 Message-ID: <20230912035522.15947-1-dmantipov@yandex.ru> X-Mailer: git-send-email 2.41.0 In-Reply-To: <3fe90164dc6fe7471523de1d3a234c88c0e43e46.camel@sipsolutions.net> References: <3fe90164dc6fe7471523de1d3a234c88c0e43e46.camel@sipsolutions.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Sep 2023 21:25:43 -0700 (PDT) Since 'sprintf()' returns the number of characters emitted, an extra calls to 'strlen()' in 'ieee80211_bss()' may be dropped. Signed-off-by: Dmitry Antipov --- v2: fix subject and reformat strings to avoid breaks (Johannes Berg) --- net/wireless/scan.c | 47 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/net/wireless/scan.c b/net/wireless/scan.c index 19516073c6d5..ae4d000009fe 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -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)) -- 2.41.0