Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756325AbdGLCXH (ORCPT ); Tue, 11 Jul 2017 22:23:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38693 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756260AbdGLCXE (ORCPT ); Tue, 11 Jul 2017 22:23:04 -0400 Subject: Re: [PATCH] drivers/staging/wilc1000: fix sparse warning: right shift by bigger than source value To: Greg Kroah-Hartman References: <20170710085731.28397-1-rui.teng@linux.vnet.ibm.com> <20170711170449.GA30362@kroah.com> Cc: Aditya Shankar , Ganesh Krishna , devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org From: Rui Teng Date: Wed, 12 Jul 2017 10:23:02 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170711170449.GA30362@kroah.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17071202-2213-0000-0000-000001F7B243 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007352; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00886287; UDB=6.00442390; IPR=6.00666436; BA=6.00005468; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016189; XFM=3.00000015; UTC=2017-07-12 02:23:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17071202-2214-0000-0000-000056D7CF8C Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-07-11_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707120035 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1969 Lines: 57 On 12/07/2017 1:04 AM, Greg Kroah-Hartman wrote: > On Mon, Jul 10, 2017 at 04:57:31PM +0800, Rui Teng wrote: >> This patch sets memory to zero directly to avoid unnecessary shift and >> bitwise operations on bool type, which can fix a sparse warning and also >> improve performance. > > It does? How did you measure the performance impact? What was now > faster? It can avoid 3 times right shift and 3 times bitwise operations. And once memory set should also faster than 4 times copy operations. And add number 4 once should also faster than 4 times plus plus. > > thanks, > > greg k-h > > >> >> Signed-off-by: Rui Teng >> --- >> drivers/staging/wilc1000/host_interface.c | 7 +++---- >> 1 file changed, 3 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c >> index 2568dfc15181..036c5c19a016 100644 >> --- a/drivers/staging/wilc1000/host_interface.c >> +++ b/drivers/staging/wilc1000/host_interface.c >> @@ -2416,10 +2416,9 @@ static void Handle_SetMulticastFilter(struct wilc_vif *vif, >> goto ERRORHANDLER; >> >> pu8CurrByte = wid.val; >> - *pu8CurrByte++ = (strHostIfSetMulti->enabled & 0xFF); >> - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 8) & 0xFF); >> - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 16) & 0xFF); >> - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 24) & 0xFF); >> + memset(pu8CurrByte, 0, 4); >> + *pu8CurrByte = (strHostIfSetMulti->enabled & 0xFF); >> + pu8CurrByte += 4; > > Are you sure enabled isn't larger than 8 bits? The size of bool may larger than 8 bits. But when we assign any value to bool type, the value of bool type will only be 1 or 0. For example, the following output will be 1 other than 0x100. bool b = 0x100; printf("b: %d\n", b); Or I think it should change 'enabled' type from bool to u32, to make sure that the right shift operation can take effect. > > thanks, > > greg k-h >