Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp356109pxb; Fri, 28 Jan 2022 00:12:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHFMlw5i+f0p+wRHdgIrs3zJv+NVTyoaaVV4eIAsyQJwIWVbrRj7v0uFlKKbzlpw7kevDN X-Received: by 2002:a17:906:af6a:: with SMTP id os10mr6155334ejb.730.1643357531493; Fri, 28 Jan 2022 00:12:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643357531; cv=none; d=google.com; s=arc-20160816; b=W4JxYUjVJmvO0VdsF9l8p10rxdq98r3tfEvpELxRuxmaRI0F5DxZiybRzNvUL/Sk4T 4pQQbP+tMUV0wa864WLiaDXF5c2u/RfmTmkEbDHngs2WPZi44BQkXPsbjX4FN1L5f+Ua L31m8g+WRK5PnSo4YzJ8Nyd+4p/425C/9MwU0+kgJMBnT2qvpftcGcS/7ZlWvv2z1WtC vk90l8+RoWR8Xs7T5zm9S4/fgCXkpBqmkk8OSkq32lipcqeKbDWhiLqk2CTJqUjOxzz+ benmGFzHF9FFxsrUSKYGPFtdMSTbQonpKexFSgKZfM3121DPL384kXGOBWrPjbXgJprc 77pA== 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=p96/qNlz+iVjynSvzKS656/c1BRi8UlR5XPlAaTFmq4=; b=xoW2QLwu8vdz9tBPSyvfOtQ1LZeAb15ZJ1sBfwyZBizPAunMVCE1RpxDaiglIVv3OO POL5YQ2R/4oPjRbz4Sg9SjoYdauWPKKXn2bEnRUWEC1fjb1dbRZI2fyg340Fguby0JxG co1IoWA5SXFaCyfSeZBBgk2RLYT/xEsB2KrYTZSSRpL8P0U4IJgkIP0emNlbJ4Ui4/Ae 8Eaq6sxeWJZ55k+Fv1XPnQmiYmfJHh5+tnoUBj/VOu8v4DciSS/JdeTwTR7Pd4JUYW7a k/GqFCzChX1rkZz4HCiL+baobPPA8upyNAX60b9kZhaNFEW9HqyomH0t/IPqmXGHOAyP VYvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GvdyPdRn; 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 dr11si2618327ejc.157.2022.01.28.00.11.47; Fri, 28 Jan 2022 00:12:11 -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=GvdyPdRn; 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 S242950AbiA0PmI (ORCPT + 99 others); Thu, 27 Jan 2022 10:42:08 -0500 Received: from mga05.intel.com ([192.55.52.43]:10340 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242186AbiA0PmG (ORCPT ); Thu, 27 Jan 2022 10:42:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643298126; x=1674834126; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QvHNkZHM+nXMWUfTV2y/6TOnJuTv1w5EQNzJgJJApNc=; b=GvdyPdRncpv25nhmXciBUeVbIGLQ3ZLJnpBO/5WqTKK/8XaFE+iBLs/R g+eGb4HFDhxMj1iU9OrHyQkyi1Gego8FRbkBzOAp1DQpXW05E1M/HB5IM gA+IcBnCqApXE32hbGfMlyiooIbqZvrq3Vz1fcOR+WwWlR/djou5GzY2g iMwYm7DYUul1F+y27YqOuMAUqasjCtyN/DR77YCDi5hWMt1DNjF1f5CM5 jzzMt8yevmV0giXtOZgq9XE6EqEgplvo5lt3QWOLPeiYDoq/km/Q95zTa NBXkvXjotgYkoyZmbKsoGQJUGyJq7j8Oo4y3TLnguqSrRUzSKOvB659LZ A==; X-IronPort-AV: E=McAfee;i="6200,9189,10239"; a="333242523" X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="333242523" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 07:41:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="521282146" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga007.jf.intel.com with ESMTP; 27 Jan 2022 07:41:47 -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 20RFfjOo028674; Thu, 27 Jan 2022 15:41:46 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 1/4] ice: switch: add and use u16[] aliases to ice_adv_lkup_elem::{h,m}_u Date: Thu, 27 Jan 2022 16:40:06 +0100 Message-Id: <20220127154009.623304-2-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 ice_adv_lkup_elem fields h_u and m_u are being accessed as raw u16 arrays in several places. To reduce cast and braces burden, add permanent array-of-u16 aliases with the same size as the `union ice_prot_hdr` itself via anonymous unions to the actual struct declaration, and just access them directly. This: - removes the need to cast the union to u16[] and then dereference it each time -> reduces the horizon for potential bugs; - improves -Warray-bounds coverage -- the array size is now known at compilation time; - addresses cppcheck complaints. Signed-off-by: Alexander Lobakin --- drivers/net/ethernet/intel/ice/ice_switch.c | 15 +++++++-------- drivers/net/ethernet/intel/ice/ice_switch.h | 12 ++++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c index d98aa35c0337..7f7e929e73a8 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.c +++ b/drivers/net/ethernet/intel/ice/ice_switch.c @@ -5267,12 +5267,12 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt, * over any significant packet data. */ for (j = 0; j < len / sizeof(u16); j++) - if (((u16 *)&lkups[i].m_u)[j]) + if (lkups[i].m_raw[j]) ((u16 *)(pkt + offset))[j] = (((u16 *)(pkt + offset))[j] & - ~((u16 *)&lkups[i].m_u)[j]) | - (((u16 *)&lkups[i].h_u)[j] & - ((u16 *)&lkups[i].m_u)[j]); + ~lkups[i].m_raw[j]) | + (lkups[i].h_raw[j] & + lkups[i].m_raw[j]); } s_rule->pdata.lkup_tx_rx.hdr_len = cpu_to_le16(pkt_len); @@ -5521,11 +5521,10 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, /* get # of words we need to match */ word_cnt = 0; for (i = 0; i < lkups_cnt; i++) { - u16 j, *ptr; + u16 j; - ptr = (u16 *)&lkups[i].m_u; - for (j = 0; j < sizeof(lkups->m_u) / sizeof(u16); j++) - if (ptr[j] != 0) + for (j = 0; j < ARRAY_SIZE(lkups->m_raw); j++) + if (lkups[i].m_raw[j]) word_cnt++; } diff --git a/drivers/net/ethernet/intel/ice/ice_switch.h b/drivers/net/ethernet/intel/ice/ice_switch.h index 7b42c51a3eb0..950a66e86227 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.h +++ b/drivers/net/ethernet/intel/ice/ice_switch.h @@ -129,8 +129,16 @@ struct ice_update_recipe_lkup_idx_params { struct ice_adv_lkup_elem { enum ice_protocol_type type; - union ice_prot_hdr h_u; /* Header values */ - union ice_prot_hdr m_u; /* Mask of header values to match */ + union { + union ice_prot_hdr h_u; /* Header values */ + /* Used to iterate over the headers */ + u16 h_raw[sizeof(union ice_prot_hdr) / sizeof(u16)]; + }; + union { + union ice_prot_hdr m_u; /* Mask of header values to match */ + /* Used to iterate over header mask */ + u16 m_raw[sizeof(union ice_prot_hdr) / sizeof(u16)]; + }; }; struct ice_sw_act_ctrl { -- 2.34.1