From: Michael Buesch <mb@bu3sch.de>
To: Larry Finger <Larry.Finger@lwfinger.net>
Cc: Steven Noonan <steven@uplinklabs.net>,
LKML <linux-kernel@vger.kernel.org>,
wireless <linux-wireless@vger.kernel.org>
Subject: Re: I need help with a sparse warning
Date: Fri, 12 Sep 2008 17:25:06 +0200 [thread overview]
Message-ID: <200809121725.06870.mb@bu3sch.de> (raw)
In-Reply-To: <48C9DACE.5040308@lwfinger.net>
On Friday 12 September 2008, Larry Finger wrote:
> Steven Noonan wrote:
> > On Thu, Sep 11, 2008 at 7:13 PM, Larry Finger <Larry.Finger@lwfinger.net> wrote:
> >> In file drivers/net/wireless/p54/p54common.c, the statement
> >>
> >> priv->rx_mtu = (size_t) le16_to_cpu((__le16)bootrec->data[10]);
> >>
> >> generates the sparse warning
> >>
> >> .../p54common.c:185:29: warning: cast to restricted __le16
> >>
> >> where bootrec->data is u32, and priv->rx_mtu is u16.
> >>
> >
> > (Whoops, didn't CC the mailing lists. Sorry about the double-message, Larry.)
> >
> > If priv->rx_mtu is u16, I'm surprised it doesn't get noisy about the
> > size_t cast. Unless the machine it's being compiled on is 16-bit, that
> > should throw a truncation warning, because size_t should be a 32-bit
> > integer on 32-bit machines (typically).
> >
> > I think if you change the (__le16) cast to (__le16 __force) it will
> > stop warning you about that particular issue.
>
> This one gets rid of the sparse warning.
>
> priv->rx_mtu = le16_to_cpu((__le16 __force)
> bootrec->data[10]);
I think you should rather fix the type of bootrec->data.
If it is u32, but the data in fact is __le16, please fix the struct instead
of adding dangerous casts.
Note that this is especially dangerous, because you cast between different
typesizes and endianesses at the same time.
next prev parent reply other threads:[~2008-09-12 15:25 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 [this message]
2008-09-12 2:39 ` Roland Dreier
2008-09-12 3:05 ` Larry Finger
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=200809121725.06870.mb@bu3sch.de \
--to=mb@bu3sch.de \
--cc=Larry.Finger@lwfinger.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=steven@uplinklabs.net \
/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).