Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4370432imm; Wed, 30 May 2018 04:31:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJXzsBguV76vRuiKlPhO+Ip1rdkUBkxuAxBU5yg+cOFpUWcPCzEwV7+xWt802vjQVYZxqzI X-Received: by 2002:a62:fc8d:: with SMTP id e135-v6mr2436372pfh.208.1527679865145; Wed, 30 May 2018 04:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527679865; cv=none; d=google.com; s=arc-20160816; b=MQfRDxmOKazqyn/TR2EPuztAgos9x65nzkpaUGIfxwa/Nv6QByUYniFxYMVURB/Tkr IKbyaE9/K0e2ICLQHnNERtWB3D1JihrIHQVfcSBkKtxbuCFWu07Sw1PCT8samQ9Ry3PE 4u3dTNpg5XnBFUNuQJuZqQGuxL4vThDrkZdCkqvOzcSbdNRmCCaEphH9wQZbcxdpBMMu XHH+ZzYip2V8LS6H0S0S642l26bE+LxBBQ6bEygHh+mw0hbTD2l4HZFDHl4zJoCLeYFv rcBI/EG9FxlFgjrXR+mejD5sfa0TQCN9eCgs5Z5kuVCl/XeDDpBhy5wDG7GR30aO9mYx hM3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=+hpZnTDWKmtlPmKFbOUPfvx+YQUhtBggBixyBk8DwvA=; b=NFd6jQgtWqXRxUrOrRs1pCtdN3JaXnrArbuTHUuX3fzUBozhFBzwy05wb0EMykiWR5 zAFKRjAyd2RkQQEjqXS4J9S1qm921jVXFnbWcfqyuoBwnJLQ2aHSL805l8SaCebgmAGH 3MfGSrEoha8/1+qacIJQoo7VEJ2+dJOpAFUtS7NO/4P+PNf2PLJ7t4lkMNLZ/pylZ/1D kv1qh+5tJ4hyNgtFYalExaSYw6Rk+rwUeFYZvWT7h/QeDeQgTmn+KQQOFOfdZG/jD9nC 8Bg3Q7B54YnLIZ901Px/ASFcaPKu4+jgMasAEeMlHrT191bSza5bj2p0dmoSw1fOrZxl 0Dqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=s8NaAjIr; 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=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y90-v6si7858363pfd.47.2018.05.30.04.30.50; Wed, 30 May 2018 04:31:05 -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=@oracle.com header.s=corp-2017-10-26 header.b=s8NaAjIr; 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=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753067AbeE3LaR (ORCPT + 99 others); Wed, 30 May 2018 07:30:17 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:55716 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753537AbeE3L3Y (ORCPT ); Wed, 30 May 2018 07:29:24 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4UBPqmi041346; Wed, 30 May 2018 11:29:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=+hpZnTDWKmtlPmKFbOUPfvx+YQUhtBggBixyBk8DwvA=; b=s8NaAjIr7QCzgLzZQXAQObegbWzKqw0QAevJaZ3nFBNF4WXDVI+cUlfOSkXGA90KuvWm IA0cgvmhkeC2L+9r4IhCVsjyB8hR3iHZaF/xt9kerd405tkFExlgyKuP6ak0bPKzzjCE bF9mM/5YDeIffZIr+5l2eEuVsqV1NStZa58Z4Ei5eUBexRDNAl0j1uB/IsUNJo4MOnxR NWUAhb8VTzCN7X0dqW6lzjtZbVCQ/FqG9xc8EkDjLw5qLn/E3i3nQ3GeQKLP11Av2AeT 4ra1OXCfFWLHHHpwfyr/Y70/3KYOo6wmsNmjU0FiuYDbhp2bfqMDAicXP6EKGXEEnlq5 Mg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2j9ev81yaa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 May 2018 11:29:13 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4UBTDn7024184 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 May 2018 11:29:13 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w4UBTCRE029917; Wed, 30 May 2018 11:29:12 GMT Received: from mwanda (/197.157.0.20) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 30 May 2018 04:29:12 -0700 Date: Wed, 30 May 2018 14:29:04 +0300 From: Dan Carpenter To: Thibaut Robert Cc: Aditya Shankar , Ganesh Krishna , Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] staging: wilc1000: Use common structs to parse ip packets Message-ID: <20180530112904.x4vcpkdmqhpc7xll@mwanda> References: <20180529190839.12818-1-thibaut.robert@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180529190839.12818-1-thibaut.robert@gmail.com> User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8908 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=628 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1805300132 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 29, 2018 at 09:08:39PM +0200, Thibaut Robert wrote: > 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; No blank line, please. > - 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 you declared buffer as a void pointer you could remove this cast. const struct iphdr *ip_hdr_ptr = buf + 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); This alignment is a bit unfortunate... Perhaps? tcp_hdr_ptr = buf + ETH_HLEN + IHL; regards, dan carpenter