Re: I need help with a sparse warning

From: Pavel Roskin
Date: Fri Sep 12 2008 - 13:12:27 EST


On Thu, 2008-09-11 at 22:05 -0500, Larry Finger wrote:
> > 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.

I believe __force should be the last resort. If you want to read a
16-bit little endian value at the given offset, I suggest that you use
le16_to_cpup(), which operates on pointers and does the cast for you.

A better but more elaborate solution would be to define a structure that
would have __le16 rx_mtu at the offset 40. Then you can cast bootrec to
that structure and apply le16_to_cpu() to that field.

--
Regards,
Pavel Roskin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/