Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4827249imm; Tue, 26 Jun 2018 00:57:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLbDaK/fajm9czsSQ6KILsquGRYhinFE7CDL/CS+6CqqoCD9/EswQ5vBG9wpjTSSzOSC131 X-Received: by 2002:a17:902:8601:: with SMTP id f1-v6mr525632plo.196.1529999833248; Tue, 26 Jun 2018 00:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529999833; cv=none; d=google.com; s=arc-20160816; b=zFg9uNPZs9Z7EyouJyo50m5OxsIceuer5z9Tq5lu1jV8WVZJd3a6SIt+0vUqtJMzxF DdNyFA9hSgjcoChUwixJ/PJBm22IxqUgm8jlpkkB8NS4geqTIpwEp0aEMRpYGUqNs/4u SEymGT9/uLkvAH+T8tjwmtgYHFDZvsFrouelo0R/MpO8kxYC3BSMKpwCljo7oD/1M5fv h12FSoLJpt98Sz0tZ9MEpZIijAuoJyMgFU+n9+lZsdvNiZfIy24K4L6BLpq3jtxmFNcQ fPJ7HZ+VD3s/NsB02JSAzBzyEO3SXUYb87zQ+IDygcDB80QNmfZd4zHO/HV4JizqVnvQ SfLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:arc-authentication-results; bh=jIhzeQVmGEvZWyfNLdUYo9cK3i02D+4c7E3El09lDjU=; b=SjGPUVKMuqUFfMx1A3BMKaOkSX0gbyWwDuIw+M2Uho2I4SanRhCT814x8pB/9S1XoX 7SoACB5xXaU42Zhc0wo+7oG48VhvxvXmSwOxPUmo2QEn1uakDSr1XpbE2gKJPHi6FDn9 /tWzsagYeVIIcexc9DUOUQLjvYCVl8bZT8Q0N52i/1BcinfiDgCi8jp/3wrU0SuWrbZ7 +f11/SEBvvmoXeiFMXuiiTmBx0+KmPi82nwPRwwiWeDPp/ObzeJpLN3gKIeNNRA1+qVv fOGudkyJIHwSsMiUw0o9ngnU6VHiJ8o4w5oLteiJBLTNS2fCoBA/Cfg2fnWqCfD7FA1F o69w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17-v6si1013594pfi.102.2018.06.26.00.56.58; Tue, 26 Jun 2018 00:57:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752730AbeFZHzf (ORCPT + 99 others); Tue, 26 Jun 2018 03:55:35 -0400 Received: from esa5.microchip.iphmx.com ([216.71.150.166]:62563 "EHLO esa5.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752169AbeFZHze (ORCPT ); Tue, 26 Jun 2018 03:55:34 -0400 X-IronPort-AV: E=Sophos;i="5.51,274,1526367600"; d="scan'208";a="13456002" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 26 Jun 2018 00:55:34 -0700 Received: from [10.145.6.69] (10.10.76.4) by chn-sv-exch02.mchp-main.com (10.10.76.38) with Microsoft SMTP Server id 14.3.352.0; Tue, 26 Jun 2018 00:55:32 -0700 Subject: Re: [PATCH v2] staging: wilc1000: Use common structs to parse ip packets To: Thibaut Robert , Aditya Shankar , Ganesh Krishna , Greg Kroah-Hartman , , , References: <20180604105549.04031722@ajaysk-VirtualBox> <20180619184419.10304-1-thibaut.robert@gmail.com> From: Claudiu Beznea Message-ID: <333f9414-9541-dc33-9c69-4054b5966eaa@microchip.com> Date: Tue, 26 Jun 2018 10:55:30 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180619184419.10304-1-thibaut.robert@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reviewed-by: Claudiu Beznea On 19.06.2018 21:44, Thibaut Robert wrote: > Use structs ethhdr, iphdr and tcphdr instead of manual parsing in > tcp_process. > This commit fix handling of ip packets containing options. > It also fixes the following sparse warning: > > drivers/staging/wilc1000//wilc_wlan.c:201:19: warning: cast to restricted __be16 > > Signed-off-by: Thibaut Robert > --- > drivers/staging/wilc1000/wilc_wlan.c | 43 ++++++++++------------------ > 1 file changed, 15 insertions(+), 28 deletions(-) > > diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c > index 55755d7fbb30..85af36595e69 100644 > --- a/drivers/staging/wilc1000/wilc_wlan.c > +++ b/drivers/staging/wilc1000/wilc_wlan.c > @@ -1,4 +1,6 @@ > // SPDX-License-Identifier: GPL-2.0 > +#include > +#include > #include "wilc_wfi_netdevice.h" > #include "wilc_wlan_cfg.h" > > @@ -150,9 +152,8 @@ static inline int add_tcp_pending_ack(u32 ack, u32 session_index, > > static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe) > { > - u8 *eth_hdr_ptr; > - u8 *buffer = tqe->buffer; > - unsigned short h_proto; > + void *buffer = tqe->buffer; > + const struct ethhdr *eth_hdr_ptr = buffer; > int i; > unsigned long flags; > struct wilc_vif *vif; > @@ -163,37 +164,23 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe) > > spin_lock_irqsave(&wilc->txq_spinlock, flags); > > - eth_hdr_ptr = &buffer[0]; > - h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12])); > - if (h_proto == ETH_P_IP) { > - u8 *ip_hdr_ptr; > - u8 protocol; > + if (eth_hdr_ptr->h_proto == htons(ETH_P_IP)) { > + const struct iphdr *ip_hdr_ptr = buffer + ETH_HLEN; > > - ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN]; > - protocol = ip_hdr_ptr[9]; > - > - if (protocol == 0x06) { > - u8 *tcp_hdr_ptr; > + if (ip_hdr_ptr->protocol == IPPROTO_TCP) { > + const struct tcphdr *tcp_hdr_ptr; > u32 IHL, total_length, data_offset; > > - tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN]; > - IHL = (ip_hdr_ptr[0] & 0xf) << 2; > - total_length = ((u32)ip_hdr_ptr[2] << 8) + > - (u32)ip_hdr_ptr[3]; > - data_offset = ((u32)tcp_hdr_ptr[12] & 0xf0) >> 2; > + IHL = ip_hdr_ptr->ihl << 2; > + tcp_hdr_ptr = buffer + ETH_HLEN + IHL; > + total_length = ntohs(ip_hdr_ptr->tot_len); > + > + data_offset = tcp_hdr_ptr->doff << 2; > if (total_length == (IHL + data_offset)) { > u32 seq_no, ack_no; > > - seq_no = ((u32)tcp_hdr_ptr[4] << 24) + > - ((u32)tcp_hdr_ptr[5] << 16) + > - ((u32)tcp_hdr_ptr[6] << 8) + > - (u32)tcp_hdr_ptr[7]; > - > - ack_no = ((u32)tcp_hdr_ptr[8] << 24) + > - ((u32)tcp_hdr_ptr[9] << 16) + > - ((u32)tcp_hdr_ptr[10] << 8) + > - (u32)tcp_hdr_ptr[11]; > - > + seq_no = ntohl(tcp_hdr_ptr->seq); > + ack_no = ntohl(tcp_hdr_ptr->ack_seq); > for (i = 0; i < tcp_session; i++) { > u32 j = ack_session_info[i].seq_num; > >