Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp370150pxb; Fri, 28 Jan 2022 00:36:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJw14VQqkGPRHFAAZot4qfi86aQ/JOssttaKBNR4vY9j7snIJLGd1cXZpZBowk28+MhbZ5+Q X-Received: by 2002:a17:90b:4a83:: with SMTP id lp3mr18207832pjb.35.1643359007079; Fri, 28 Jan 2022 00:36:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643359007; cv=none; d=google.com; s=arc-20160816; b=ztVQ/RJDdRER80Hw7NR7E/XBAFDQ4yGkivQtHDiycYhO5nQrTKSzJ/hl/XUm95snBE GK8i3tN4RVoeRT1JZwa5NPPFkcS15zjyGcq/+MUuh2Pr9SHBqygEeeU4jqcoyRA/1mZc CL6ZpCsjI4KV+FsmnsSkHPDSTBOJKBsmSiuLmf63fzsuqyVfVc1Uyoobg2ke9gvRBb84 iK39BcECw3GOc6E0t7UcdLTX7WkpXjeyDdyYeB8CdpK5rB9odOsdh0kzRjcWvXQvNEQ9 6+p+bsvKy4wxdhFQ+XZqX3JNEIj6AkvguklwYcOzChrlkceehT9dyRTomg4HxSIgsIc/ G1Xg== 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=4QXbJuTlOIkVcQ8M11m1HskLXalUYTeHbzUXFh3ac+c=; b=yX0YukQxFyGaPqODKwJGGCGQ5DbO6Jp6krTJvmcmR41Yo1XUQZxGigSiRu+xOYFdCF 6DsnVhtEMaDcVToWoxbZoOHqd3gJ29FwtsMmVmU+blETSxmXkSOlzRKlfzd6YXAiGl52 JS0kIf6c0viK35fn0RMUklAyiVJGrEyLO5UOFhDhCXUGXb+/3rk3g4A7XawWl1pQpP2c EatBjkGWHAg51Y9WUfzhKy8Rx/WvYu2i7g9lEt5U6ZqiDvmfO35Vs7WVS28qzObpIWdk ysYnlqhEPdtzZZXi5PRPmkg/Q2UOhT1j/aQ+JMlSNOcSM0n5wL66TS7r04PEaCZETpAN d7HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Dtdb8iy4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si4433564ply.342.2022.01.28.00.36.14; Fri, 28 Jan 2022 00:36:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Dtdb8iy4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237993AbiA0Pmc (ORCPT + 99 others); Thu, 27 Jan 2022 10:42:32 -0500 Received: from mga17.intel.com ([192.55.52.151]:43816 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243056AbiA0Pma (ORCPT ); Thu, 27 Jan 2022 10:42:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643298150; x=1674834150; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VhBiY0AQNvqJyz4dJgtw1Vhd+czfgEBT2l/7YPY4AvU=; b=Dtdb8iy4lJeHa1wpJjoI0HrEOGjanJxnVh0/ga+AV3Kfiz4DAD1b8wXW +Qvym+pa0wD0Jud2rEOZnFKKNSMmXdYwfOqMpMQ6JPlvBXR7NL5mGqLyy lTpf4Lg84u5th9jSjl0nKEe74e/vyqZDaufpwY/XIpagWPIYbV7Zd2LAW NzJrkoTotLtuHVhl7IXRGWy+6bxva4sLERXJiytHlIEQ/4QJgsGVIE4Hd tSSbV0Lb5+/p7xxtuI7zWgaCC6ypnPtFW8/iZD2G+M6kyGaemYqFCXlB0 EzOOCsXhgvryQ3F+HwXzSWEUBz/+JqdXjR+yeSfpol/nBShpA6h55pbyQ w==; X-IronPort-AV: E=McAfee;i="6200,9189,10239"; a="227561000" X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="227561000" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 07:41:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="597866305" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga004.fm.intel.com with ESMTP; 27 Jan 2022 07:41:48 -0800 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 20RFfjOp028674; Thu, 27 Jan 2022 15:41:47 GMT From: Alexander Lobakin To: intel-wired-lan@lists.osuosl.org Cc: Alexander Lobakin , Jesse Brandeburg , Maciej Fijalkowski , Michal Swiatkowski , Martyna Szapar-Mudlaw , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 net-next 2/4] ice: switch: unobscurify bitops loop in ice_fill_adv_dummy_packet() Date: Thu, 27 Jan 2022 16:40:07 +0100 Message-Id: <20220127154009.623304-3-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127154009.623304-1-alexandr.lobakin@intel.com> References: <20220127154009.623304-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 --- 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 7f7e929e73a8..b6b6e8f5d358 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.c +++ b/drivers/net/ethernet/intel/ice/ice_switch.c @@ -5266,13 +5266,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); -- 2.34.1