Return-path: Received: from mtiwmhc11.worldnet.att.net ([204.127.131.115]:51747 "EHLO mtiwmhc11.worldnet.att.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756817AbYILDFC (ORCPT ); Thu, 11 Sep 2008 23:05:02 -0400 Message-ID: <48C9DC5C.3040109@lwfinger.net> (sfid-20080912_050528_446723_4D64905A) Date: Thu, 11 Sep 2008 22:05:00 -0500 From: Larry Finger MIME-Version: 1.0 To: Roland Dreier CC: LKML , wireless Subject: Re: I need help with a sparse warning References: <48C9D040.8010107@lwfinger.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Sender: linux-wireless-owner@vger.kernel.org List-ID: Roland Dreier wrote: > > In file drivers/net/wireless/p54/p54common.c, the statement > > > > priv->rx_mtu = (size_t) le16_to_cpu((__le16)bootrec->data[10]); > > [I don't see this code in Linus's tree] It is in wireless-testing. > > the code in question looks buggy to me. Since bootrec->data[10] is u32, > casting it to a 16-bit type is going to take a different 2 bytes out of > the 4 bytes depending on the endianness of the system the driver is > built for. And I assume you are parsing some fixed-layout thing that > the firmware is giving you or something like that. > > I would guess you want something like: > > priv->rx_mtu = le16_to_cpu(((__force __le16 *) bootrec->data)[20]); > > (__force is what shuts up sparse, and as far as I can see, the size_t > cast is useless, since the result will be promoted anyway) Yes, that one works. As you suspected, this section is parsing data from the firmware. When I started, there were 18 sparse warnings, and a number of them were accesses of little-endian variables without an appropriate leXX_to_cpu() conversion. Obviously, this code has never been tested on a big-endian machine. Thanks, Larry