From patchwork Mon Mar 15 18:49:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 400528 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3673812jai; Mon, 15 Mar 2021 11:50:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAo4kWJACZLMyrBxGNDlxWP+s6k+Nl5bdwTlKLPZtLr2EKoaXhDNHIXIjznLWZ7iRdncMk X-Received: by 2002:a17:906:c24b:: with SMTP id bl11mr25782111ejb.80.1615834238914; Mon, 15 Mar 2021 11:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615834238; cv=none; d=google.com; s=arc-20160816; b=LzI8u1QnRwMxX5bzgnP7+3CPu60dAJK7dHY7skJ5t+PgVOdi8bv15uvtCyoCdLL1e1 7BaZgKGPppui/afc5e0e/hhZE1YbqC7LigkNpDKheHOr0cvsr6Az3Ti4Z5fd1LkiEX9r XZ4N2ReA0y6uPA9VHhT0cQVX06QFEhfYAIB3jWCbkKUns6WxS87VU83zTcRY0fgWh7Vq qSTCXtlk1CXTM4+bkTLx7ma0MKh/Vy360ms/LcxxAbZNVH1uj8RQZhUug6v4NQzqrgQ6 QGmqBiI/J//YcvoKwD9On/9BGeBFE0vbJqvNQ/rbNaXioftv0y7BvfXw++KsSHA6T7pW XoLw== 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=rVEslqQM6fsvVZ7LiAEkE3ccCznmfly+zx9t6yJZNsM=; b=ChiloiZGlA2zQXvZCRB/pktdbz1pm57UhPz4b0l9NTsA8XLTVYBifB+qn8A51638st KFBHNLFyi7I0PKL0MKECFlVUMMwRyHP8EDFrFP7W4ZrdMxNSzuCES2+IJJO6LHP5PqEW 78fC16nG6B5T+b1yEVprfNHsWBnrqOev3IcGPiu07delMse3XDxn/9NICsSxqGaDsiOL PAtVtDSXXoJklM0nXoi+m1Gv1AY+WggrupienPX8Xk0u+g0r4kJSl2YJgM4ys0b+hmy3 Yd2iQkUXe1E4D7jq0wi4LH9qG9+inxoXhhCMAdc515wo+rWmS2p5uOYoUqnWS1FFKQUV rnww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yUDI23OY; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x27si11624279ejb.603.2021.03.15.11.50.38; Mon, 15 Mar 2021 11:50:38 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-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=@linaro.org header.s=google header.b=yUDI23OY; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232577AbhCOSuG (ORCPT + 8 others); Mon, 15 Mar 2021 14:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231891AbhCOSth (ORCPT ); Mon, 15 Mar 2021 14:49:37 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 974A1C06174A for ; Mon, 15 Mar 2021 11:49:36 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id i18so10308060ilq.13 for ; Mon, 15 Mar 2021 11:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rVEslqQM6fsvVZ7LiAEkE3ccCznmfly+zx9t6yJZNsM=; b=yUDI23OYNIhkInkPACeIRm6oTCYvArJ1DWfEBHdqn9lrVkf1BiRmV7avyO3i2MeQhk 6VbDct0tvBlipbjt1Mb+YJmVvRm/Xdc4RkQ7bYEuzFQB+Ythiwb7jPsYpeBjE64Akgwi NjPrfcZbVhbjaqKLIq1GUxQ/dzqoQZUi6/6sXBN3nPIMUTX1sjEsQ/EQsQTenN//7BEp WFXK+P6iO5qkw5GDh2nTDlXu+BRssJ3kHLLn6Rgl6t2lH5mP0e71cpHq9ElkAHJiPHa4 5pbSsL73kLDgOgZiFBBNsVW3bllt+atlZUV9Glhlfw+8gwcyqojK6/UXRGzPGjZhWPY3 S8UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rVEslqQM6fsvVZ7LiAEkE3ccCznmfly+zx9t6yJZNsM=; b=PfXHs6NdRsi9jztJ2JFkeWZ3lLJIfw6Ux/jdUHXmztPy576BR1AxpPvUh+QlTaQRRk tRZExXB8kMS6gg7LQGrOvO3sAHjxNRT8XlnjiwgciZdgNtkVm6f8TWnNdS5pnJesZ8Ec cGpmhXi3JhmT2UMZNgBvVU/4UaMH8c2CXRI+bDvsav/II29EaFk/empjHC0OMm4Xm1bW QzQ/dVeZnmrYNH4/+KPn9z0XMs5MvBoA3ev7cU9CMpdT4bq+futekb+h/Se6ByliApFH gY1rE3PJ6u/JXe0/W4IWsN2LJ29lGbfxOGnQKrvDbVGjV0JfzSXXUgrtucJsZxK2KLxH +dJQ== X-Gm-Message-State: AOAM532M1KN4SsGKvsR/GHAL24U0BGhSrgmfwVoTnWFqOH9ZGDJXWWZA 5+Ffokp6zZ5LFL0r81J8x2w9Sg== X-Received: by 2002:a92:d909:: with SMTP id s9mr858869iln.120.1615834176027; Mon, 15 Mar 2021 11:49:36 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id a5sm8212162ilk.14.2021.03.15.11.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 11:49:35 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, olteanv@gmail.com, alexander.duyck@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck Subject: [PATCH net-next v5 3/6] net: qualcomm: rmnet: kill RMNET_MAP_GET_*() accessor macros Date: Mon, 15 Mar 2021 13:49:25 -0500 Message-Id: <20210315184928.2913264-4-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315184928.2913264-1-elder@linaro.org> References: <20210315184928.2913264-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The following macros, defined in "rmnet_map.h", assume a socket buffer is provided as an argument without any real indication this is the case. RMNET_MAP_GET_MUX_ID() RMNET_MAP_GET_CD_BIT() RMNET_MAP_GET_PAD() RMNET_MAP_GET_CMD_START() RMNET_MAP_GET_LENGTH() What they hide is pretty trivial accessing of fields in a structure, and it's much clearer to see this if we do these accesses directly. So rather than using these accessor macros, assign a local variable of the map header pointer type to the socket buffer data pointer, and derereference that pointer variable. In "rmnet_map_data.c", use sizeof(object) rather than sizeof(type) in one spot. Also, there's no need to byte swap 0; it's all zeros irrespective of endianness. Signed-off-by: Alex Elder Reviewed-by: Bjorn Andersson Reviewed-by: Alexander Duyck --- drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c | 10 ++++++---- drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h | 12 ------------ .../net/ethernet/qualcomm/rmnet/rmnet_map_command.c | 11 ++++++++--- drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c | 4 ++-- 4 files changed, 16 insertions(+), 21 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c index 3d00b32323084..2a6b2a609884c 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c @@ -56,20 +56,22 @@ static void __rmnet_map_ingress_handler(struct sk_buff *skb, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_endpoint *ep; u16 len, pad; u8 mux_id; - if (RMNET_MAP_GET_CD_BIT(skb)) { + if (map_header->cd_bit) { + /* Packet contains a MAP command (not data) */ if (port->data_format & RMNET_FLAGS_INGRESS_MAP_COMMANDS) return rmnet_map_command(skb, port); goto free_skb; } - mux_id = RMNET_MAP_GET_MUX_ID(skb); - pad = RMNET_MAP_GET_PAD(skb); - len = RMNET_MAP_GET_LENGTH(skb) - pad; + mux_id = map_header->mux_id; + pad = map_header->pad_len; + len = ntohs(map_header->pkt_len) - pad; if (mux_id >= RMNET_MAX_LOGICAL_EP) goto free_skb; diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h index 576501db2a0bc..2aea153f42473 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h @@ -32,18 +32,6 @@ enum rmnet_map_commands { RMNET_MAP_COMMAND_ENUM_LENGTH }; -#define RMNET_MAP_GET_MUX_ID(Y) (((struct rmnet_map_header *) \ - (Y)->data)->mux_id) -#define RMNET_MAP_GET_CD_BIT(Y) (((struct rmnet_map_header *) \ - (Y)->data)->cd_bit) -#define RMNET_MAP_GET_PAD(Y) (((struct rmnet_map_header *) \ - (Y)->data)->pad_len) -#define RMNET_MAP_GET_CMD_START(Y) ((struct rmnet_map_control_command *) \ - ((Y)->data + \ - sizeof(struct rmnet_map_header))) -#define RMNET_MAP_GET_LENGTH(Y) (ntohs(((struct rmnet_map_header *) \ - (Y)->data)->pkt_len)) - #define RMNET_MAP_COMMAND_REQUEST 0 #define RMNET_MAP_COMMAND_ACK 1 #define RMNET_MAP_COMMAND_UNSUPPORTED 2 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c index beaee49621287..add0f5ade2e61 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c @@ -12,12 +12,13 @@ static u8 rmnet_map_do_flow_control(struct sk_buff *skb, struct rmnet_port *port, int enable) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_endpoint *ep; struct net_device *vnd; u8 mux_id; int r; - mux_id = RMNET_MAP_GET_MUX_ID(skb); + mux_id = map_header->mux_id; if (mux_id >= RMNET_MAX_LOGICAL_EP) { kfree_skb(skb); @@ -49,6 +50,7 @@ static void rmnet_map_send_ack(struct sk_buff *skb, unsigned char type, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_map_control_command *cmd; struct net_device *dev = skb->dev; @@ -58,7 +60,8 @@ static void rmnet_map_send_ack(struct sk_buff *skb, skb->protocol = htons(ETH_P_MAP); - cmd = RMNET_MAP_GET_CMD_START(skb); + /* Command data immediately follows the MAP header */ + cmd = (struct rmnet_map_control_command *)(map_header + 1); cmd->cmd_type = type & 0x03; netif_tx_lock(dev); @@ -71,11 +74,13 @@ static void rmnet_map_send_ack(struct sk_buff *skb, */ void rmnet_map_command(struct sk_buff *skb, struct rmnet_port *port) { + struct rmnet_map_header *map_header = (void *)skb->data; struct rmnet_map_control_command *cmd; unsigned char command_name; unsigned char rc = 0; - cmd = RMNET_MAP_GET_CMD_START(skb); + /* Command data immediately follows the MAP header */ + cmd = (struct rmnet_map_control_command *)(map_header + 1); command_name = cmd->command_name; switch (command_name) { diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 0bfe69698b278..3af68368fc315 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -315,7 +315,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, return NULL; maph = (struct rmnet_map_header *)skb->data; - packet_len = ntohs(maph->pkt_len) + sizeof(struct rmnet_map_header); + packet_len = ntohs(maph->pkt_len) + sizeof(*maph); if (port->data_format & RMNET_FLAGS_INGRESS_MAP_CKSUMV4) packet_len += sizeof(struct rmnet_map_dl_csum_trailer); @@ -324,7 +324,7 @@ struct sk_buff *rmnet_map_deaggregate(struct sk_buff *skb, return NULL; /* Some hardware can send us empty frames. Catch them */ - if (ntohs(maph->pkt_len) == 0) + if (!maph->pkt_len) return NULL; skbn = alloc_skb(packet_len + RMNET_MAP_DEAGGR_SPACING, GFP_ATOMIC);