mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rui Teng <rui.teng@linux.vnet.ibm.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Aditya Shankar <aditya.shankar@microchip.com>,
	Ganesh Krishna <ganesh.krishna@microchip.com>,
	devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drivers/staging/wilc1000: fix sparse warning: right shift by bigger than source value
Date: Wed, 12 Jul 2017 10:23:02 +0800	[thread overview]
Message-ID: <f31c5818-7ba3-4708-3fda-5bfbe0c4c1da@linux.vnet.ibm.com> (raw)
In-Reply-To: <20170711170449.GA30362@kroah.com>

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 <rui.teng@linux.vnet.ibm.com>
>> ---
>>  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
>

  reply	other threads:[~2017-07-12  2:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-10  8:57 Rui Teng
2017-07-11 17:04 ` Greg Kroah-Hartman
2017-07-12  2:23   ` Rui Teng [this message]
2017-07-12  6:12     ` Greg Kroah-Hartman
2017-07-12  8:11       ` Joe Perches

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=f31c5818-7ba3-4708-3fda-5bfbe0c4c1da@linux.vnet.ibm.com \
    --to=rui.teng@linux.vnet.ibm.com \
    --cc=aditya.shankar@microchip.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=ganesh.krishna@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®