linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Larry Finger <Larry.Finger@lwfinger.net>
To: Roland Dreier <rdreier@cisco.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	wireless <linux-wireless@vger.kernel.org>
Subject: Re: I need help with a sparse warning
Date: Thu, 11 Sep 2008 22:05:00 -0500	[thread overview]
Message-ID: <48C9DC5C.3040109@lwfinger.net> (raw)
In-Reply-To: <ada4p4mm6iy.fsf@cisco.com>

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


  reply	other threads:[~2008-09-12  3:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-12  2:13 I need help with a sparse warning Larry Finger
2008-09-12  2:32 ` Steven Noonan
2008-09-12  2:58   ` Larry Finger
2008-09-12  3:04     ` Roland Dreier
2008-09-12  3:07       ` Larry Finger
2008-09-12 15:25     ` Michael Buesch
2008-09-12  2:39 ` Roland Dreier
2008-09-12  3:05   ` Larry Finger [this message]
2008-09-12 17:12     ` Pavel Roskin
2008-09-12  2:44 ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48C9DC5C.3040109@lwfinger.net \
    --to=larry.finger@lwfinger.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=rdreier@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).