From patchwork Tue Sep 22 21:30:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Larry Finger X-Patchwork-Id: 7245901 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D264ABEEC1 for ; Tue, 22 Sep 2015 21:31:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CC544209B3 for ; Tue, 22 Sep 2015 21:31:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1FEA2067A for ; Tue, 22 Sep 2015 21:31:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934985AbbIVVbB (ORCPT ); Tue, 22 Sep 2015 17:31:01 -0400 Received: from mail-ob0-f182.google.com ([209.85.214.182]:32994 "EHLO mail-ob0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934883AbbIVVa6 (ORCPT ); Tue, 22 Sep 2015 17:30:58 -0400 Received: by obbbh8 with SMTP id bh8so18894789obb.0; Tue, 22 Sep 2015 14:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=8DkJZO/vmGO8TSoL/VjYco+MxHSmhJjhbGm789+4Cfg=; b=Cvz15SEyOGheN7/t3w0zPyAEmoagPGzgLID9CBFC+MVaNMvEGm+nGlcefom7aTkfrs vMTpM41Qv6H02bHaBjP73XoRdU3drzwhq+pUrFI4svFKNF/IBBSiEgg+p58OzSyxalbV xvbP9ZTJz10XHqilM2qVcVCAqeitobtxnmA087kkEhv2bnZCEiBgO9NFHSBTZrJq3OPq DcSGH1wsO0cTqLKzZWvDtJg1nDXj2rC4zGNxs0VFEe+irKpNmrOqvRFUzE08Uu/fcVux vVx0dLXYWluy2D2qqAVzxo9p3HK+6ptxkwILLYsOiHicq1agrN6jyoNrTvBce38tvW9+ O6pQ== X-Received: by 10.60.44.69 with SMTP id c5mr16478273oem.43.1442957457364; Tue, 22 Sep 2015 14:30:57 -0700 (PDT) Received: from linux.site (cpe-24-31-249-175.kc.res.rr.com. [24.31.249.175]) by smtp.gmail.com with ESMTPSA id k5sm1798476oev.16.2015.09.22.14.30.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Sep 2015 14:30:56 -0700 (PDT) Subject: Re: [PATCH] staging: rtl8723au: Mark type casts to __le32 as intentional To: Lars Svensson References: <1442906641-22824-1-git-send-email-lars1.svensson@sonymobile.com> Cc: Jes.Sorensen@redhat.com, gregkh@linuxfoundation.org, m.v.b@runbox.com, gdonald@gmail.com, joe@perches.com, ruchandani.tina@gmail.com, linux-wireless@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org From: Larry Finger Message-ID: <5601C88E.4010807@lwfinger.net> Date: Tue, 22 Sep 2015 16:30:54 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <1442906641-22824-1-git-send-email-lars1.svensson@sonymobile.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 09/22/2015 02:24 AM, Lars Svensson wrote: > Fixing Sparse warnings about intentional type casts in rtw_security.c > as below. > > CHECK drivers/staging/rtl8723au/core/rtw_security.c > drivers/staging/rtl8723au/core/rtw_security.c:248:22: \ > warning: cast to restricted __le32 > drivers/staging/rtl8723au/core/rtw_security.c:249:24: \ > warning: cast to restricted __le32 > drivers/staging/rtl8723au/core/rtw_security.c:776:22: \ > warning: cast to restricted __le32 > drivers/staging/rtl8723au/core/rtw_security.c:777:24: \ > warning: cast to restricted __le32 > > Signed-off-by: Lars Svensson > --- > drivers/staging/rtl8723au/core/rtw_security.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/drivers/staging/rtl8723au/core/rtw_security.c b/drivers/staging/rtl8723au/core/rtw_security.c > index 3d40bab..311dfc1 100644 > --- a/drivers/staging/rtl8723au/core/rtw_security.c > +++ b/drivers/staging/rtl8723au/core/rtw_security.c > @@ -213,6 +213,7 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter, > { > /* exclude ICV */ > u32 actual_crc, expected_crc; > + __le32 crc_le; > struct arc4context mycontext; > int length; > u32 keylength; > @@ -245,8 +246,10 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter, > arcfour_encrypt(&mycontext, payload, payload, length); > > /* calculate icv and compare the icv */ > - actual_crc = le32_to_cpu(getcrc32(payload, length - 4)); > - expected_crc = le32_to_cpu(get_unaligned_le32(&payload[length - 4])); > + crc_le = (__force __le32)getcrc32(payload, length - 4); > + actual_crc = le32_to_cpu(crc_le); > + crc_le = (__force __le32)get_unaligned_le32(&payload[length - 4]); > + expected_crc = le32_to_cpu(crc_le); > > if (actual_crc != expected_crc) { > RT_TRACE(_module_rtl871x_security_c_, _drv_err_, > @@ -717,6 +720,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter, > u8 rc4key[16]; > u8 ttkey[16]; > u32 actual_crc, expected_crc; > + __le32 crc_le; > struct arc4context mycontext; > int length; > u32 prwskeylen; > @@ -772,9 +776,10 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter, > /* 4 decrypt payload include icv */ > arcfour_init(&mycontext, rc4key, 16); > arcfour_encrypt(&mycontext, payload, payload, length); > - > - actual_crc = le32_to_cpu(getcrc32(payload, length - 4)); > - expected_crc = le32_to_cpu(get_unaligned_le32(&payload[length - 4])); > + crc_le = (__force __le32)getcrc32(payload, length - 4); > + actual_crc = le32_to_cpu(crc_le); > + crc_le = (__force __le32)get_unaligned_le32(&payload[length - 4]); > + expected_crc = le32_to_cpu(crc_le); > > if (actual_crc != expected_crc) { > RT_TRACE(_module_rtl871x_security_c_, _drv_err_, > You may have silenced the Sparse warnings, but the code was not wrong. Your version is also correct; however, you end up with some really ugly casts. Here is my analysis of these two, identical sections: The output of getcrc32() is an unsigned, 4-byte quantity that has the endianess of the cpu. Therefore, the le32_to_cpu() conversion is suspect for a big-endian machine. Those statements should be be a simple "actual_crc = getcrc32(....). The expected crc comes from a byte string that is in little-endian order. For that reason, it needs to be converted on big-endian machines, which is exactly what get_unaligned_le32() does. Thus, the second statement in each block becomes "expected_crc = get_unaligned_le32(....)". Both the original code and your patch byte swap both quantities, thus they get the correct result. at least if all you are doing is to compare the two results. The *complete* patch to fix the Sparse warnings is The above compiles with no Sparse warnings, and I think it would work on both LE and BE architectures; however, it has only been compile tested. Larry --- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: wireless-drivers-next-new/drivers/staging/rtl8723au/core/rtw_security.c =================================================================== --- wireless-drivers-next-new.orig/drivers/staging/rtl8723au/core/rtw_security.c +++ wireless-drivers-next-new/drivers/staging/rtl8723au/core/rtw_security.c @@ -245,8 +245,8 @@ void rtw_wep_decrypt23a(struct rtw_adapt arcfour_encrypt(&mycontext, payload, payload, length); /* calculate icv and compare the icv */ - actual_crc = le32_to_cpu(getcrc32(payload, length - 4)); - expected_crc = le32_to_cpu(get_unaligned_le32(&payload[length - 4])); + actual_crc = getcrc32(payload, length - 4); + expected_crc = get_unaligned_le32(&payload[length - 4]); if (actual_crc != expected_crc) { RT_TRACE(_module_rtl871x_security_c_, _drv_err_, @@ -773,8 +773,8 @@ int rtw_tkip_decrypt23a(struct rtw_adapt arcfour_init(&mycontext, rc4key, 16); arcfour_encrypt(&mycontext, payload, payload, length); - actual_crc = le32_to_cpu(getcrc32(payload, length - 4)); - expected_crc = le32_to_cpu(get_unaligned_le32(&payload[length - 4])); + actual_crc = getcrc32(payload, length - 4); + expected_crc = get_unaligned_le32(&payload[length - 4]); if (actual_crc != expected_crc) { RT_TRACE(_module_rtl871x_security_c_, _drv_err_,