From patchwork Fri Jun 3 16:44:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12869219 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AEA9C433EF for ; Fri, 3 Jun 2022 16:44:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344040AbiFCQoS (ORCPT ); Fri, 3 Jun 2022 12:44:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344039AbiFCQoR (ORCPT ); Fri, 3 Jun 2022 12:44:17 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5447E517DE; Fri, 3 Jun 2022 09:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654274656; x=1685810656; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=xsNqvl0vWM4js1N6rZvuJ6nvPTp8oPY0FhSTTjdvN+0=; b=MDoNLHzlAJSNmi16A00dcPQ140S1oPVucpBjnCHEfRnem9ZdheuXVK5f oxXMBP09C/Q6gtQ6WI+JnmYl83UYAQ6OWjVq3f9VfKuQRa2ZPqxH4Wm/h baDAg2B0ShOmaiZkHD+wcaJs0LdBsLCgCmfvVP0bgwpdOGFVA3mTsDoi/ vlVh58a2aPkOcRDQ6lWEg1KDm40bRsIwq5/khpur/22Q54nggyQgbc0zl D4kJ4/JG5U/kVb1uoEnuG1Vbu6xeyJSy/kWiM0rY3RQCv1LV+kPzGw8F3 6KtG3zaPMH4QPCSwnynHPQz19E89jtYcXwqdH4TwqA1U7v7T9Z46SWwpo Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10367"; a="258378053" X-IronPort-AV: E=Sophos;i="5.91,275,1647327600"; d="scan'208";a="258378053" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2022 09:44:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,275,1647327600"; d="scan'208";a="905526826" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 03 Jun 2022 09:44:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id BA87CF8; Fri, 3 Jun 2022 19:44:15 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v1 1/2] wireless: ray_cs: Utilize strnlen() in parse_addr() Date: Fri, 3 Jun 2022 19:44:13 +0300 Message-Id: <20220603164414.48436-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Instead of doing simple operations and using an additional variable on stack, utilize strnlen() and reuse len variable. Signed-off-by: Andy Shevchenko --- drivers/net/wireless/ray_cs.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c index 87e98ab068ed..9ac371d6cd6c 100644 --- a/drivers/net/wireless/ray_cs.c +++ b/drivers/net/wireless/ray_cs.c @@ -1643,31 +1643,29 @@ static void authenticate_timeout(struct timer_list *t) /*===========================================================================*/ static int parse_addr(char *in_str, UCHAR *out) { + int i, k; int len; - int i, j, k; int status; if (in_str == NULL) return 0; - if ((len = strlen(in_str)) < 2) + len = strnlen(in_str, ADDRLEN * 2 + 1) - 1; + if (len < 1) return 0; memset(out, 0, ADDRLEN); status = 1; - j = len - 1; - if (j > 12) - j = 12; i = 5; - while (j > 0) { - if ((k = hex_to_bin(in_str[j--])) != -1) + while (len > 0) { + if ((k = hex_to_bin(in_str[len--])) != -1) out[i] = k; else return 0; - if (j == 0) + if (len == 0) break; - if ((k = hex_to_bin(in_str[j--])) != -1) + if ((k = hex_to_bin(in_str[len--])) != -1) out[i] += k << 4; else return 0; From patchwork Fri Jun 3 16:44:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12869220 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA735C433EF for ; Fri, 3 Jun 2022 16:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344057AbiFCQoT (ORCPT ); Fri, 3 Jun 2022 12:44:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237520AbiFCQoR (ORCPT ); Fri, 3 Jun 2022 12:44:17 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA0A6517E3; Fri, 3 Jun 2022 09:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654274656; x=1685810656; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5dZ0TAoqzidlvbyB70vmcetMzuDC9HuzxlinyJlmwKs=; b=f5z0B86gzQkGBSVzmLw7orrZhSTh73rhiGDx2N/p5TTK1q3Sm3no+kLr /8SLllvhfTaB7XfDAOX4KzMWgdiGZIc2NjUMudywkasvqOWS69Sb96dWV qbe+ETBUDW6a2k6TXU84aBe34NUlLlo0pA8tECl5CzfuGEM+L0H/JqLue 4MDIPah6rhLqGZLDPetn7jM9W/v3KscAxnnmGppdMBWSWwUdpPpIRSFWt FiQ7wRSUAxu4040dFW7NuLEvn+yVNR6cyMSPrluznXVW1I5B0wlyz8AsV ivW9/47+luhrTjrLIJTcoo2PQpEEtwYq59ncqxVqFz8kx8MsFyg1xMtQ8 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10367"; a="276040912" X-IronPort-AV: E=Sophos;i="5.91,275,1647327600"; d="scan'208";a="276040912" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2022 09:44:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,275,1647327600"; d="scan'208";a="668520232" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 03 Jun 2022 09:44:13 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 72D625D3; Fri, 3 Jun 2022 19:44:16 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v1 2/2] wireless: ray_cs: Drop useless status variable in parse_addr() Date: Fri, 3 Jun 2022 19:44:14 +0300 Message-Id: <20220603164414.48436-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220603164414.48436-1-andriy.shevchenko@linux.intel.com> References: <20220603164414.48436-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The status variable assigned only once and used also only once. Replace it's usage by actual value. Signed-off-by: Andy Shevchenko --- drivers/net/wireless/ray_cs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c index 9ac371d6cd6c..1f57a0055bbd 100644 --- a/drivers/net/wireless/ray_cs.c +++ b/drivers/net/wireless/ray_cs.c @@ -1645,7 +1645,6 @@ static int parse_addr(char *in_str, UCHAR *out) { int i, k; int len; - int status; if (in_str == NULL) return 0; @@ -1654,7 +1653,6 @@ static int parse_addr(char *in_str, UCHAR *out) return 0; memset(out, 0, ADDRLEN); - status = 1; i = 5; while (len > 0) { @@ -1672,7 +1670,7 @@ static int parse_addr(char *in_str, UCHAR *out) if (!i--) break; } - return status; + return 1; } /*===========================================================================*/