Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2258891pxp; Mon, 21 Mar 2022 15:10:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxM/2Gir9zarka5r54BZ3iSYd49nlAoRTnr/ZadenPbPaeVc2Yge8hTKGJqF7h2AoXkvPGW X-Received: by 2002:a17:902:ce90:b0:154:3029:97e6 with SMTP id f16-20020a170902ce9000b00154302997e6mr13085488plg.111.1647900650667; Mon, 21 Mar 2022 15:10:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647900650; cv=none; d=google.com; s=arc-20160816; b=grvizSQNpxOzokXK3xSvNopovgPTTZHcq+V3bCtZjcXYkosaKfxsueGb7qoqPpig38 1PUYD/5llokwRYoiDtpTcY887/EbpsAD3RgFnhE/uArQvJH7x6sZH9G7sXoJNvBN+9Yd LmfXFD0+g/jPaUEm9UG/PJWjlyW4+DOYddqjUtHtFHS6qYMhKFq2JfwIZwTUJpB9IOIh yjMBFhXpzW/c/LU6JzIKFy9XhhMRm5TxImep+dRBdtlIcSpb25uHS45RzzfcOao2veWx CI4k8hGIPtmnU9OxZRyq4j44Cp5CSw7jdFT1LIHPnp3vubC1LxDbXM1oPaMPyR6XNSii Dm3g== 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=5odLhHF7thfz3qWx7B4HOhk37pmJRaRJH0oOPieeWug=; b=jr0gXBJizMEPNZQOHPIVJ37YG8st4EAF/U9jIbd4spwyR+tWzGkzeLqot4OHKsO+x4 /kf2MdUtKop4hExo9H65D4lczTZG6uBYDv2tbRSHzcG6p5tsmFZhGjuTjvRA5IDTPH+D m1XUPsW5HUkmbqEvdoxQtrUWgQH0G1/bbo4PIIMlrdR1tZoU3FMbxNfZR5XvUCF9v/K5 ZBpahmh8P6fb7rBoxw6GF/IIX/7uNzFo4NxZVhNZoTkp3rHpl9EoItznvbcLhBFI+S75 r85U1h0aXk+hMUc7pcnGi6H10AhvaOjhsa6WHINxTB95C+e115ZhvdKSlpCJ4K8AAwNt koQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VafVnYUz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g24-20020a1709029f9800b00153b2d1656fsi11328862plq.375.2022.03.21.15.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:10:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VafVnYUz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F30043667D9; Mon, 21 Mar 2022 14:31:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243373AbiCULD0 (ORCPT + 99 others); Mon, 21 Mar 2022 07:03:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346592AbiCULDN (ORCPT ); Mon, 21 Mar 2022 07:03:13 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 603A514FFCF; Mon, 21 Mar 2022 04:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647860505; x=1679396505; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gw06FbtHD6oupzt/DZZYNvSPrC9S4YxANi+MQO/HMuU=; b=VafVnYUzlkYPbv15Z1W85fJ5XTHXRS/SNcr0GKSG8Bc/2F/6l157mNtu cuM5FIghvk3KemKTDzi7T+EVeR+qzCuACqfiuxfr6wLP6a70nHDTSr6Gi zryrsllh45oaaSfLi6X+RWMiLNDag6L3pjMJte/Tix5DIsqWbntzVsWPI 5fy/Iyhn4OaONUm4NuSIihdiqpRmI3G2iYBrd+4QKHEvp+ai44ryYs5o7 hwZLro8x7CWUMNnh0mMuhrGbtFX6vMKdUU7NMvZHf9XoQkxJ1a9Coqdo9 pAil15FjPkaquUDCZ6kLizFyfM+u5qtoOvv0XI+gWHgIDUfZifrW/KwVS w==; X-IronPort-AV: E=McAfee;i="6200,9189,10292"; a="257242543" X-IronPort-AV: E=Sophos;i="5.90,198,1643702400"; d="scan'208";a="257242543" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2022 04:01:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,198,1643702400"; d="scan'208";a="582829300" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga001.jf.intel.com with ESMTP; 21 Mar 2022 04:01:20 -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 22LB1HaD031880; Mon, 21 Mar 2022 11:01:18 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 v4 net-next 2/5] ice: switch: unobscurify bitops loop in ice_fill_adv_dummy_packet() Date: Mon, 21 Mar 2022 11:59:51 +0100 Message-Id: <20220321105954.843154-3-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220321105954.843154-1-alexandr.lobakin@intel.com> References: <20220321105954.843154-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 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); -- 2.35.1