Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp625565imm; Tue, 5 Jun 2018 01:34:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI/r/EafXqlZVNL7Q4mk3148BZlPN7BIB8haOrt2KVm5uZHxBgNZsiiLA3UKOzpzbPpRcui X-Received: by 2002:a17:902:bb0d:: with SMTP id l13-v6mr18186093pls.115.1528187664720; Tue, 05 Jun 2018 01:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528187664; cv=none; d=google.com; s=arc-20160816; b=VuT3IV4Ej5RDWRHH8i1LoJqzd6e62+G9ZlStKssPrERt9JiY3YkGozUqccoGtkqfCf h9pIcHK9n764noHWnt63sLKY7xYSUsL50ZWL9pgMexegUbnvDjm45bL0fToyXAj7b4lV 1soomga6zEspfIz7VZEEA/3hxfYqAWtzdtRwB2fNxpqIYiwT1B7rjEmifFYnkKTEz2xA Mc0zXenEO52v39Ad/USnJQMwCFxhcw1Vsz00f8Pd9zOlqwkPRqeMkcMetZzyULNHpsws jCTVTZy6GfcpeaPdzM/ndCMEGDDGCyFDxRhtxXorPCcYqM01VwMWioIlIVG1S2GA/AXC XELg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=f6syVW3j7v9PotqCdCkJPiXx+e5f7w1tRUN8zuFoPrE=; b=xDi2znwdTm7awr1Xwfx7fPOqZ8RLBrXrqswDChl5nQrR0P0nLRx79ctgVroEEfGNR8 oOIiT1mAoKJDManZF/eh365kXnoxDwdBf1ORnr54dCjRodnFcIXFq+dpPUYDZQl5jqr4 GgwvgcMXFG7NGgSeUXPisltVPTv2+H2jlPTmEDiBA548xi9rrMDzyenjwfxu7G00u4QI TIaZwONJbklt7fiZLoGpCezbkLH1cxJT3IuP3I6dwPqHYktrA6jRRPoojq/qxFs1GJW0 YuVNPj2H7/ugLKMUka+7uwjpiPE9og1Mgnwq25ABiw3L0wTyJ85IcgqGBLJpKjtmaJhM S26Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=s9t1LM/U; 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 v18-v6si48467558plo.285.2018.06.05.01.34.10; Tue, 05 Jun 2018 01:34:24 -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=s9t1LM/U; 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 S1751642AbeFEIde (ORCPT + 99 others); Tue, 5 Jun 2018 04:33:34 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:39524 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751590AbeFEIda (ORCPT ); Tue, 5 Jun 2018 04:33:30 -0400 Received: by mail-wm0-f66.google.com with SMTP id p11-v6so3345403wmc.4; Tue, 05 Jun 2018 01:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=f6syVW3j7v9PotqCdCkJPiXx+e5f7w1tRUN8zuFoPrE=; b=s9t1LM/UbnMLohNH4tVpn0ZZiVE3EE2752Yt9ldQ0QSqf2qSrocX/dAsxHKkBLjwyB q24neb7CvqwoTorOyfHa+00wB0WxFhDB19u/DCgTEzAm/PzwDio6D58tA0UdUHs4dCke 2qO4/h7nLVGNSzvO29lyaqVqCPYe+MX9uKCbeDF0AP0NlI4vK0LQXj1RprA9cvHi29j7 H9SYfXXjpqKiiW86y/rqo7vDUVo9wkLZOSqp/ooNEOAy4oUA4w4Jdy/AEBHZ42b9tHHs ZNU7dlpsuhWx1l4N9ayddSjJIQdeV0IDiAJV8UnSx0guvRC8I4mC009a5uHywnMDihiv Cr7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=f6syVW3j7v9PotqCdCkJPiXx+e5f7w1tRUN8zuFoPrE=; b=N9dSVgdZfly2G0wZ1CkVAQ7ZhaGEhdU5Kmr3SCBr/o7BlLLdp7aWUvsn0PzkPw4id1 nQ/BMLqtnQqWf8umh7AzzHQhzLccbc7pZ5OLWExA9fsHjsnoNxbpFrB4AfgI13oHOsvH bhoj4x0JG23X0iSIW7fZm/VLc/6Od8y5VSbNmlQv+ka69wCkz+TjtpBRo/17QWG5liwL 4nfTyWgo0xO9DaupBQPYBgJS3ovNhaGgb9etakp5ilN77u+XNWrZGdVGTzrvcVVE+PoW GrvWt+HuOZ7Mwi72SkIhdOneJJwLB+Jj9ILGF/zbPlkqcIk8+TOy7wRQXkC5fSrFR384 79sA== X-Gm-Message-State: ALKqPwfj2+9BjCnAxqNUIO0m5ZPbaQ9+VYweSJHAZdzjK7B5V5ywBb+k qxNrssMLHU69SFvfbPacFD8= X-Received: by 2002:a50:ec19:: with SMTP id g25-v6mr17872390edr.242.1528187608408; Tue, 05 Jun 2018 01:33:28 -0700 (PDT) Received: from L80496 ([160.92.7.69]) by smtp.gmail.com with ESMTPSA id d13-v6sm7443859edb.18.2018.06.05.01.33.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 01:33:27 -0700 (PDT) Date: Tue, 5 Jun 2018 10:33:25 +0200 From: Thibaut Robert To: Dan Carpenter 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/2] staging: wilc1000: fix some endianness sparse warnings Message-ID: <20180605083325.GA6965@L80496> References: <20180529191143.13081-1-thibaut.robert@gmail.com> <20180530111725.gmigyddsp2i6mgzw@mwanda> <20180604193250.GB32753@L80496> <20180605073631.cvp2iuef4yb636jz@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180605073631.cvp2iuef4yb636jz@mwanda> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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 ? > regards, > dan carpenter > Regards, Thibaut