Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933797AbdGLILg (ORCPT ); Wed, 12 Jul 2017 04:11:36 -0400 Received: from smtprelay0093.hostedemail.com ([216.40.44.93]:53847 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933300AbdGLILb (ORCPT ); Wed, 12 Jul 2017 04:11:31 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:599:966:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:2828:2899:2912:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:4385:5007:6119:7901:7903:8603:8957:10004:10400:10848:11026:11232:11473:11658:11783:11914:12043:12296:12438:12740:12895:13101:13255:13439:13894:14181:14659:14721:21080:21433:21434:21451:21627:30012:30034:30054:30079:30083:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: rifle71_ce07bade295c X-Filterd-Recvd-Size: 3235 Message-ID: <1499847086.4457.27.camel@perches.com> Subject: Re: [PATCH] drivers/staging/wilc1000: fix sparse warning: right shift by bigger than source value From: Joe Perches To: Greg Kroah-Hartman , Rui Teng Cc: devel@driverdev.osuosl.org, Aditya Shankar , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Ganesh Krishna Date: Wed, 12 Jul 2017 01:11:26 -0700 In-Reply-To: <20170712061220.GB11450@kroah.com> References: <20170710085731.28397-1-rui.teng@linux.vnet.ibm.com> <20170711170449.GA30362@kroah.com> <20170712061220.GB11450@kroah.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2069 Lines: 62 On Wed, 2017-07-12 at 08:12 +0200, Greg Kroah-Hartman wrote: > On Wed, Jul 12, 2017 at 10:23:02AM +0800, Rui Teng wrote: > > 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. > > And did you test this to prove that this does matter and is noticable? > How do you know that gcc doesn't just optimize it all away? Is this on > a code path that actually matters? > > Don't ever say "improve performance" without actually being able to > prove it please. Using __be32 would be more intelligible. Maybe something like this: (in any number of patches) o convert u8 *pu8CurrByte to be32 *buf o convert strHostIfSetMulti to smulti o remove useless initialization of result o remove unnecessary parentheses o return directly on kalloc failure o remove label Ending up with: (uncompiled/untested) --- static void Handle_SetMulticastFilter(struct wilc_vif *vif, ??????struct set_multicast *smulti) { s32 result; struct wid wid; __be32 *buf; wid.id = (u16)WID_SETUP_MULTICAST_FILTER; wid.type = WID_BIN; wid.size = sizeof(struct set_multicast) + smulti->cnt * ETH_ALEN; wid.val = kmalloc(wid.size, GFP_KERNEL); if (!wid.val) return; buf = (__force __be32 *)wid.val; *buf++ = cpu_to_be32(smulti->enabled); *buf++ = cpu_to_be32(smulti->cnt); memcpy(buf, wilc_multicast_mac_addr_list, smulti->cnt * ETH_ALEN); result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1, ??????wilc_get_vif_idx(vif)); if (result) netdev_err(vif->ndev, "Failed to send setup multicast\n"); kfree(wid.val); }