From patchwork Fri Mar 18 16:17:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12785660 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 CB541C433EF for ; Fri, 18 Mar 2022 16:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238815AbiCRQWa (ORCPT ); Fri, 18 Mar 2022 12:22:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239052AbiCRQWK (ORCPT ); Fri, 18 Mar 2022 12:22:10 -0400 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E84B517F3CC; Fri, 18 Mar 2022 09:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647620335; x=1679156335; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gw06FbtHD6oupzt/DZZYNvSPrC9S4YxANi+MQO/HMuU=; b=lzGFKp2VAhBVrBWdsr6M1rRbEs7mOD+JP8IVxIw4UQuop28l212TyYmS VnUOYIlo32bNSZmySA9mX/xk14VWTyhwYUuQKk++Pmy6mEccoxT+yF3ta dWl7rJR+CZRVDznN5vX3PdTuisFBsbCAiinNeHKBV/2SF3JN1tu2SApdk f6yIICMZVJYSaX0s/hWinZAsb9ko+nAAPzGRPG2urvAYwmuPZZH9vcr3p q6vMSQG44BP1Ei8c3FQ35KVaHCtZzqQ+kgQusNaQVHejDg+1Y8yitISu8 tPqaDYmg+JSm9bjVXo6QQui03mDQOpR0NCS53Fn4i2vCK5DSLs4JvMX0d Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10290"; a="317882094" X-IronPort-AV: E=Sophos;i="5.90,192,1643702400"; d="scan'208";a="317882094" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2022 09:18:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,192,1643702400"; d="scan'208";a="647525172" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga004.jf.intel.com with ESMTP; 18 Mar 2022 09:18:27 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 22IGIOmE024113; Fri, 18 Mar 2022 16:18:25 GMT From: Alexander Lobakin To: intel-wired-lan@lists.osuosl.org Cc: Alexander Lobakin , Maciej Fijalkowski , Michal Swiatkowski , Wojciech Drewek , Marcin Szycik , Martyna Szapar-Mudlaw , "David S. Miller" , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 net-next 2/5] ice: switch: unobscurify bitops loop in ice_fill_adv_dummy_packet() Date: Fri, 18 Mar 2022 17:17:10 +0100 Message-Id: <20220318161713.680436-3-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220318161713.680436-1-alexandr.lobakin@intel.com> References: <20220318161713.680436-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org A loop performing header modification according to the provided mask in ice_fill_adv_dummy_packet() is very cryptic (and error-prone). Replace two identical cast-deferences with a variable. Replace three struct-member-array-accesses with a variable. Invert the condition, reduce the indentation by one -> eliminate line wraps. Signed-off-by: Alexander Lobakin Reviewed-by: Michal Swiatkowski Tested-by: Marcin Szycik --- drivers/net/ethernet/intel/ice/ice_switch.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c index 075df2474688..0936d39de70c 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.c +++ b/drivers/net/ethernet/intel/ice/ice_switch.c @@ -5810,13 +5810,15 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt, * indicated by the mask to make sure we don't improperly write * over any significant packet data. */ - for (j = 0; j < len / sizeof(u16); j++) - if (lkups[i].m_raw[j]) - ((u16 *)(pkt + offset))[j] = - (((u16 *)(pkt + offset))[j] & - ~lkups[i].m_raw[j]) | - (lkups[i].h_raw[j] & - lkups[i].m_raw[j]); + for (j = 0; j < len / sizeof(u16); j++) { + u16 *ptr = (u16 *)(pkt + offset); + u16 mask = lkups[i].m_raw[j]; + + if (!mask) + continue; + + ptr[j] = (ptr[j] & ~mask) | (lkups[i].h_raw[j] & mask); + } } s_rule->pdata.lkup_tx_rx.hdr_len = cpu_to_le16(pkt_len);