diff mbox

[OPW,kernel] staging:rtl8192u: Fix Sparse warning of cast to restricted __le16

Message ID 1414537120-32497-1-git-send-email-dilekuzulmez@gmail.com
State New, archived
Headers show

Commit Message

Dilek Uzulmez Oct. 28, 2014, 10:58 p.m. UTC
This patch fixes the following Sparse warnings in ieee80211_crypt_tkip.c
drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c:185:16: warning: cast to restricted __le16

Signed-off-by: Dilek Uzulmez <dilekuzulmez@gmail.com>
---
 drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Julia Lawall Oct. 28, 2014, 11:11 p.m. UTC | #1
On Wed, 29 Oct 2014, Dilek Uzulmez wrote:

> This patch fixes the following Sparse warnings in ieee80211_crypt_tkip.c
> drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c:185:16: warning: cast to restricted __le16
> 
> Signed-off-by: Dilek Uzulmez <dilekuzulmez@gmail.com>
> ---
>  drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
> index fcc90a5..1e9e4ca 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
> @@ -182,7 +182,7 @@ static inline u16 Mk16(u8 hi, u8 lo)
>  
>  static inline u16 Mk16_le(u16 *v)
>  {
> -	return le16_to_cpu(*v);
> +	return *v;

I don't really understand these le functions, but it looks like that if 
the call to le16_to_cpu is not useful, then the whole function is not 
useful either.

julia
'Greg KH' Oct. 28, 2014, 11:22 p.m. UTC | #2
On Wed, Oct 29, 2014 at 12:58:40AM +0200, Dilek Uzulmez wrote:
> This patch fixes the following Sparse warnings in ieee80211_crypt_tkip.c
> drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c:185:16: warning: cast to restricted __le16
> 
> Signed-off-by: Dilek Uzulmez <dilekuzulmez@gmail.com>
> ---
>  drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
> index fcc90a5..1e9e4ca 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
> @@ -182,7 +182,7 @@ static inline u16 Mk16(u8 hi, u8 lo)
>  
>  static inline u16 Mk16_le(u16 *v)
>  {
> -	return le16_to_cpu(*v);
> +	return *v;

You just changed the logic of the code here, why?

Also, this whole function can just be replaced with le16_to_cpu(), which
will cause other sparse warnings to pop up, and need to be fixed.

thanks,

greg k-h
Arnd Bergmann Oct. 29, 2014, 8:14 a.m. UTC | #3
On Wednesday 29 October 2014 00:11:06 Julia Lawall wrote:
> > @@ -182,7 +182,7 @@ static inline u16 Mk16(u8 hi, u8 lo)
> >  
> >  static inline u16 Mk16_le(u16 *v)
> >  {
> > -     return le16_to_cpu(*v);
> > +     return *v;
> 
> I don't really understand these le functions, but it looks like that if 
> the call to le16_to_cpu is not useful, then the whole function is not 
> useful either.

I think a better way to deal with this function is to replace
all calls to Mk16_le with a direct le16_to_cpu, and then use
the proper types.

FWIW, the purpose of this function is to ensure that all data
passed in has the bytes in little-endian order, meaning that
a number 0x1234 in a register is stored as byte 0x34 followed
by byte 0x12. This is required by the network protocol that is
implemented here. Most CPUs these days use little-endian mode,
while some others use big-endian and store them as 0x12 0x34.
Each network protocol has to decide to do it one way or the
other and have every implementation that is the opposite way
swap the bytes.

	Arnd
diff mbox

Patch

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
index fcc90a5..1e9e4ca 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
@@ -182,7 +182,7 @@  static inline u16 Mk16(u8 hi, u8 lo)
 
 static inline u16 Mk16_le(u16 *v)
 {
-	return le16_to_cpu(*v);
+	return *v;
 }