LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Aakash Hemadri' <aakashhemadri123@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Shuah Khan <skhan@linuxfoundation.org>,
	Bjorn Helgaas <bjorn@helgaas.com>,
	"linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 2/2] staging: rtl8723bs: fix cast to restricted __le32
Date: Thu, 19 Aug 2021 09:43:37 +0000	[thread overview]
Message-ID: <eb38f6e0ae60489ca396de32d64f0513@AcuMS.aculab.com> (raw)
In-Reply-To: <1be80f0196bed681bf55bfe3155f564b4ebf3b76.1629135143.git.aakashhemadri123@gmail.com>

From: Aakash Hemadri
> Sent: 16 August 2021 18:35
> 
> Fix sparse warning:
> warning: cast to restricted __le32

How many different copies of this crappy copy are there?
> 
...
> diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c
> b/drivers/staging/rtl8723bs/core/rtw_security.c
> index 381deeea99d0..5320b1a46dfb 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_security.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_security.c
> @@ -122,7 +122,7 @@ void rtw_wep_decrypt(struct adapter  *padapter, u8 *precvframe)
>  		arc4_crypt(ctx, payload, payload,  length);
> 
>  		/* calculate icv and compare the icv */
> -		*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
> +		*((u32 *)crc) = ~crc32_le(~0, payload, length - 4);

You've removed a byteswap which is needed on BE architectures.

>  	}
>  }
> @@ -621,7 +621,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
>  			arc4_setkey(ctx, rc4key, 16);
>  			arc4_crypt(ctx, payload, payload, length);
> 
> -			*((u32 *)crc) = le32_to_cpu(~crc32_le(~0, payload, length - 4));
> +			*((u32 *)crc) = ~crc32_le(~0, payload, length - 4);
> 
>  			if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] ||
>  			    crc[1] != payload[length - 3] || crc[0] != payload[length - 4])

As above - crc32_le() does a 'little-endian crc' but returns a host-ordered value.
The (horrid) array cast means you need to store a LE value.

There are a dozen better ways to do this - I'm bored of quoting them.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  reply	other threads:[~2021-08-19  9:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-16 17:35 [PATCH 0/2] staging: rtl8732bs: Fix sparse warnings Aakash Hemadri
2021-08-16 17:35 ` [PATCH 1/2] staging: rtl8732bs: incorrect type in assignment Aakash Hemadri
2021-08-16 22:43   ` kernel test robot
2021-08-16 17:35 ` [PATCH 2/2] staging: rtl8723bs: fix cast to restricted __le32 Aakash Hemadri
2021-08-19  9:43   ` David Laight [this message]
2021-08-16 18:48 ` [PATCH 0/2] staging: rtl8732bs: Fix sparse warnings Fabio M. De Francesco
2021-08-18  5:58   ` Fabio M. De Francesco
  -- strict thread matches above, loose matches on Subject: below --
2021-08-16 17:30 Aakash Hemadri
2021-08-16 17:30 ` [PATCH 2/2] staging: rtl8723bs: fix cast to restricted __le32 Aakash Hemadri

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=eb38f6e0ae60489ca396de32d64f0513@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=aakashhemadri123@gmail.com \
    --cc=bjorn@helgaas.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=skhan@linuxfoundation.org \
    --subject='RE: [PATCH 2/2] staging: rtl8723bs: fix cast to restricted __le32' \
    /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

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).