Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp780491imm; Tue, 5 Jun 2018 04:29:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLD//7adYh57rL8njLb0JoTVVZGqVeAx9eiOp4MAuHtTWHesxO8DQXYmrH3mCCp1h0E8URs X-Received: by 2002:a65:63cb:: with SMTP id n11-v6mr20392472pgv.185.1528198192137; Tue, 05 Jun 2018 04:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528198192; cv=none; d=google.com; s=arc-20160816; b=GiY0WTTFXk6dWy4CCEXIkuZntPtsdma4L7eaC8Ohw+D7dGXZrB2ppvI2jsPJ+dXIIo qY2o0mvUtZamTKVqDLquW3WOh/ePJeIxfIazIrFwTzoGljvfHplgjnahO06Own+bta83 oVijdcTY/Fvd2qxgHYg05X3Ar0v+Cn4JebjzoLrqlhEn1l+zFUSvq7n4MvweYnVyZWIV q1AA+1pOY9yrOOzU0ptz+EtTLL5FQ6e6pi7CV4JsRzQdjtAbrupr4feVgLSRNveP0Ara r7sCesAmXaU62fzaDnsvecv1t4UJgZPlxu5orRH6ySvrhamnseyoeTyx44BfLQ1H5AcQ zKUg== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=GHQpSk0YS9zNT06xeRgaKuNlld7FyUeZK9C+nwFwaLM=; b=p2na3JzAQFa4O1VC8Vry1PPMvwSPkYhBuUF3Ij17DHXfO59yKsZH5JqWafjIg5es9h tOtPCW3kMrQtS5uvoDXRzwI6nfOr5qPyB2BhpUOy9/n09BA9RuGbHKUJpVsjxJ8DktBC zTRoJxVcMIKyUGvO5gV31aVqiDlZECpfap6OsHUdraSD0rEWPcmOtMMTcVFXPR8v1Ih6 vDzACaoYBtKoeKkXXFh9RB4olFxKQef9HO3JAZZvpiwJZ/X8s8LSOPAvTmvN1MTULm0X C1c71FkWQV60GOmCkm2rZKCm0cvzQp2d8UZ8ikCLg+e4H+0JYnFBwGO/u/B9wMRsOnpJ WzGw== 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 r11-v6si38113251pgp.235.2018.06.05.04.29.37; Tue, 05 Jun 2018 04:29:52 -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 S1751814AbeFEL2E convert rfc822-to-8bit (ORCPT + 99 others); Tue, 5 Jun 2018 07:28:04 -0400 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:3865 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751653AbeFEL2C (ORCPT ); Tue, 5 Jun 2018 07:28:02 -0400 X-IronPort-AV: E=Sophos;i="5.49,478,1520924400"; d="scan'208";a="14642179" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 05 Jun 2018 04:28:01 -0700 Received: from ajaysk-VirtualBox (10.10.76.4) by chn-sv-exch03.mchp-main.com (10.10.76.49) with Microsoft SMTP Server id 14.3.352.0; Tue, 5 Jun 2018 04:28:00 -0700 Date: Tue, 5 Jun 2018 11:42:20 +0530 From: Ajay Singh To: Thibaut Robert CC: Dan Carpenter , , Greg Kroah-Hartman , , , "Ganesh Krishna" , Aditya Shankar Subject: Re: [PATCH 1/2] staging: wilc1000: fix some endianness sparse warnings Message-ID: <20180605114220.5a893f01@ajaysk-VirtualBox> In-Reply-To: <20180605083325.GA6965@L80496> References: <20180529191143.13081-1-thibaut.robert@gmail.com> <20180530111725.gmigyddsp2i6mgzw@mwanda> <20180604193250.GB32753@L80496> <20180605073631.cvp2iuef4yb636jz@mwanda> <20180605083325.GA6965@L80496> Organization: Microchip Technology X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 5 Jun 2018 10:33:25 +0200 Thibaut Robert wrote: > Le mardi 05 juin 2018 à 10:36:31 (+0300), Dan Carpenter a écrit : > > On Mon, Jun 04, 2018 at 09:32:50PM +0200, Thibaut Robert wrote: > > > Le mercredi 30 mai 2018 à 14:17:25 (+0300), Dan Carpenter a > > > écrit : > > > > On Tue, May 29, 2018 at 09:11:43PM +0200, Thibaut Robert > > > > wrote: > > > > > diff --git > > > > > a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c > > > > > b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c index > > > > > e248702ee519..745bf5ca2622 100644 --- > > > > > a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +++ > > > > > b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c @@ > > > > > -1431,7 +1431,7 @@ void wilc_wfi_p2p_rx(struct net_device > > > > > *dev, u8 *buff, u32 size) freq = > > > > > ieee80211_channel_to_frequency(curr_channel, > > > > > NL80211_BAND_2GHZ); > > > > > - if (!ieee80211_is_action(buff[FRAME_TYPE_ID])) { > > > > > + if > > > > > (!ieee80211_is_action(cpu_to_le16(buff[FRAME_TYPE_ID]))) { > > > > > > > > "buff" comes from the network, it's going to be little endian, > > > > not cpu endian. The rest of the function treats it as CPU > > > > endian but I'm pretty sure it's wrong... > > > buff comes from the network but we are looking at single byte > > > here. ieee80211_is_action expects an le16, so we I added this to > > > extend an u8 to an le16. Is this incorrect ? > > > > > > Or maybe we the buff has the second byte ? but that I can't > > > tell. > > > > You raise a good point that I hadn't seen. The original code is > > clearly buggy. But your fix isn't correct either... The other > > thing to consider is that cpu_to_le16() is basically a cast to u16 > > on x86 so it's a no-op here. > The sparse warning is clearly spotting a real issue. I tried to at > least have big endian handle correctly the 0-255 case. I am willing > to drop the change (since I agree it's not very satisfying and will > mask an issue), but may I ask you to explain how it is wrong ? How > would you correctly expand an u8 to __le16 ? I think in big endian we > need to swap the bytes. > Yes, when sending the data to ieee80211_is_action() it should pass 16bit value instead of 8bit value. It should be corrected. But the buff received from the wifi module is already in little endian format. As the data is already in LE endian format so in my opinion the conversion is not required while calling ieee80211_is_action(). > > > > Really the right thing is to not treat buff as an array of u8 but a > > struct. The code assumes that frame_type is 0-255 but probably it's > > supposed to go up to U16_MAX. > > > > struct whatever { > > __le16 frame_type; > > ... > > > > There probably is already a struct like that, but I don't know what > > it is. I don't know this code at all, I'm just guessing. > > > I was thinking the same. I don't know whether this buf contains a > standard struct or something hw-specific. I'll try to dig further and > submit a separate patch if I can. Maybe Aditya can give more > information ? > The buffer structure contains both some custom information along with standard info. As the frame_control is the first 2 byte in the in buff so casting it can also help to extract frame_control. Please refer the code in mgmt_tx() which use like below const struct ieee80211_mgmt *mgmt; .... mgmt = (const struct ieee80211_mgmt *)buf; ieee80211_is_action(mgmt->frame_control) I think another approach can be by using proper type cast with first 2 bytes of buffer(to extract 16bit value) and pass it to ieee80211_is_action(). Regards, Ajay