Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3714133imm; Tue, 29 May 2018 12:10:10 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrHyjouXNKlq6j4YAH/j+yRDODhuI/7SjfVVruBMiaN9+6T6AirBQj2owNr78ADahR6x8la X-Received: by 2002:a63:b64f:: with SMTP id v15-v6mr14575710pgt.276.1527621010013; Tue, 29 May 2018 12:10:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527621009; cv=none; d=google.com; s=arc-20160816; b=OdFJYE1W1JE+CrqsbAhto9fW+QiG6AVKX7Hs+xsw8rYNd2m7GZaSQ9PFVhL/e5gu2C r0pwOgcIA6heMSmR3ZPijhBMDYtnf73+UvC77kCcgnrjNbdZxHATgBGKiAHFyVQxQ9wt M+znDJ+R76/pjPms0+9ut05QPNAdI46LV+ImJIeqLZbvXQ6/l2Z+UhiVGKkD8oZNsAPT pQfn9puWV5cettKDyn9BG2muotbmANmaOTxonPr2oj19qW4/quBiTklmACU2RspENLsw MiJA9A9L5+VmQMIrlWOwJJr+RGCcM056SZ3mD8Aw4AS3+X83JKd1to4HWRejPNVHpK0w jOiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Q1eImjtVhibNmSuDPYrloLIzaj2zJaF6GXsFu7YwW6E=; b=c1ceNJnaXPqQ+QC5jsiavETHb+fGe18lMEIs7BiQwW2WG3IPQH5xzPf2/wIEXrlmQ3 H/m0avBICNP40VxeOvsNv1frAVu/a+kDfNmVYLL372NHk+a+L7M+29vBXgSPTQwAqHJi ZAOw/Yy0T4xRY6KsCjt/5BuhUvocKN829htSF9MzRP0iu2h3D91TSyabL8UJu4EO/93y S2cK1q6ucazpI3wiqxHYo1AzHklYprVOnbioi5PSVCf8kAZvi9C/M66fiZmK8YtZqc2A NvWzCMnKVty+NBcgGsW/b7NXDGa33TN0KA5LzxO4eCf68o/yjyo5lWG1RwOm0rCU3AiA 99YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RpxRBZOM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11-v6si2355902pgq.506.2018.05.29.12.09.55; Tue, 29 May 2018 12:10:09 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RpxRBZOM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966159AbeE2TJM (ORCPT + 99 others); Tue, 29 May 2018 15:09:12 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:55750 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965614AbeE2TJL (ORCPT ); Tue, 29 May 2018 15:09:11 -0400 Received: by mail-wm0-f68.google.com with SMTP id a8-v6so43340817wmg.5; Tue, 29 May 2018 12:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Q1eImjtVhibNmSuDPYrloLIzaj2zJaF6GXsFu7YwW6E=; b=RpxRBZOMPRVRgrTroJZuIZ8BY5zAyafEvChlcHuBmx3JAROpBMUp708N8SZxO/gX0P Q3g20Ee9aNmM8bf9OmrReWnX0OTCvj20+3+dXwgZMxC6LkYapUNMCrQACG5YsFwb3sSx l30WFIFWJrWVqzAinhJFoRIOZ2CquhejlOxcirmzDikW5kCFMZKgM0Yo6khyuHsriBPW Bb1MlQjBG8nDxDCJ15jj5CHV64Km6CeXWUrm7ugaVrKeo4fpNbZBA70PqxP30ZWUpyB9 Q6nLDM+OCMZc/QAaqYq+ADBewIbTD3HW0crY7HRsVdc3FCNqme3oZzc+Z1WuQGbuvJzA rJ+Q== 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; bh=Q1eImjtVhibNmSuDPYrloLIzaj2zJaF6GXsFu7YwW6E=; b=qoTIpWY3/1X/CBVGwihvs9iFnF5F63sD0SVOVC+nMiyjNtbIegO/y2y/xa7nI6OX8y tFgPtCsIa4L+IEW26p0XwhwwiSfxoViNlxR/DJuVCq+REXhOnUp8rBhKCKHjUB5XOC2e bRRnnaJF47ohjIy6uaE8XmGbdM8aVRdITyAg7aH0P2SpkdVP6lsXkaDiXmhU1M7TTmjs vmwTzBqsJwtXkS1SDnr30RaGddQWNXhd4a0KVe9qpwd9V7t42TNjjM57rLek9EJlx3mt Mt08qLx7H4gnZ1IPnNfOCGJwET+3flQy7ndhb5G5Tv/2CNjiqIJCAisBPYVF3FWBHD5U 9ewg== X-Gm-Message-State: ALKqPwf7Ih6bKwKyC3br8NU+oo1F/Skgr9cDm2+EpJH7fdgbGzsspJf1 jVjsrNUnbZI5YGUxuN2CkFQ= X-Received: by 2002:a1c:9d49:: with SMTP id g70-v6mr100370wme.134.1527620949480; Tue, 29 May 2018 12:09:09 -0700 (PDT) Received: from L80496.priv.atos.fr (abo-39-222-68.trs.modulonet.fr. [85.68.222.39]) by smtp.gmail.com with ESMTPSA id 90-v6sm33015851wrl.79.2018.05.29.12.09.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 12:09:07 -0700 (PDT) From: Thibaut Robert To: Aditya Shankar , Ganesh Krishna , Greg Kroah-Hartman Cc: linux-wireless@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Thibaut Robert Subject: [PATCH 1/1] staging: wilc1000: Use common structs to parse ip packets Date: Tue, 29 May 2018 21:08:39 +0200 Message-Id: <20180529190839.12818-1-thibaut.robert@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 44 +++++++++++----------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c index d4ebbf67e50b..28c93f3f846e 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" @@ -184,9 +186,9 @@ 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; + const struct ethhdr *eth_hdr_ptr = (const struct ethhdr *)tqe->buffer; + u8 *buffer = tqe->buffer; - unsigned short h_proto; int i; unsigned long flags; struct wilc_vif *vif; @@ -197,37 +199,25 @@ 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; - - ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN]; - protocol = ip_hdr_ptr[9]; + if (eth_hdr_ptr->h_proto == htons(ETH_P_IP)) { + const struct iphdr *ip_hdr_ptr = (const struct iphdr *) + (buffer + ETH_HLEN); - 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 = (const struct tcphdr *) + ((u8 *)ip_hdr_ptr + 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; -- 2.17.0