linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: vt6656: Use BIT_ULL() macro instead of bit shift operation
@ 2020-03-07 10:49 Oscar Carter
  2020-03-08  6:55 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Oscar Carter @ 2020-03-07 10:49 UTC (permalink / raw)
  To: Forest Bond, Greg Kroah-Hartman
  Cc: Quentin Deslandes, Malcolm Priestley, Colin Ian King,
	Gabriela Bittencourt, Oscar Carter, devel, linux-kernel

Replace the bit left shift operation with the BIT_ULL() macro and remove
the unnecessary "and" operation against the bit_nr variable.

Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
---
 drivers/staging/vt6656/main_usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
index 5e48b3ddb94c..f7ca9e97594d 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -21,6 +21,7 @@
  */
 #undef __NO_VERSION__

+#include <linux/bits.h>
 #include <linux/etherdevice.h>
 #include <linux/file.h>
 #include "device.h"
@@ -802,8 +803,7 @@ static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,

 	netdev_hw_addr_list_for_each(ha, mc_list) {
 		bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
-
-		mc_filter |= 1ULL << (bit_nr & 0x3f);
+		mc_filter |= BIT_ULL(bit_nr);
 	}

 	priv->mc_list_count = mc_list->count;
--
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: vt6656: Use BIT_ULL() macro instead of bit shift operation
  2020-03-07 10:49 [PATCH] staging: vt6656: Use BIT_ULL() macro instead of bit shift operation Oscar Carter
@ 2020-03-08  6:55 ` Greg Kroah-Hartman
  2020-03-08 16:13   ` Oscar Carter
  0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2020-03-08  6:55 UTC (permalink / raw)
  To: Oscar Carter
  Cc: Forest Bond, devel, Malcolm Priestley, linux-kernel,
	Gabriela Bittencourt, Colin Ian King

On Sat, Mar 07, 2020 at 11:49:29AM +0100, Oscar Carter wrote:
> Replace the bit left shift operation with the BIT_ULL() macro and remove
> the unnecessary "and" operation against the bit_nr variable.
> 
> Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
> ---
>  drivers/staging/vt6656/main_usb.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
> index 5e48b3ddb94c..f7ca9e97594d 100644
> --- a/drivers/staging/vt6656/main_usb.c
> +++ b/drivers/staging/vt6656/main_usb.c
> @@ -21,6 +21,7 @@
>   */
>  #undef __NO_VERSION__
> 
> +#include <linux/bits.h>
>  #include <linux/etherdevice.h>
>  #include <linux/file.h>
>  #include "device.h"
> @@ -802,8 +803,7 @@ static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
> 
>  	netdev_hw_addr_list_for_each(ha, mc_list) {
>  		bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
> -
> -		mc_filter |= 1ULL << (bit_nr & 0x3f);
> +		mc_filter |= BIT_ULL(bit_nr);

Are you sure this does the same thing?  You are not masking off bit_nr
anymore, why not?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: vt6656: Use BIT_ULL() macro instead of bit shift operation
  2020-03-08  6:55 ` Greg Kroah-Hartman
@ 2020-03-08 16:13   ` Oscar Carter
  2020-03-08 19:22     ` Malcolm Priestley
  0 siblings, 1 reply; 6+ messages in thread
From: Oscar Carter @ 2020-03-08 16:13 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Forest Bond, devel, Malcolm Priestley, linux-kernel,
	Gabriela Bittencourt, Colin Ian King, Oscar Carter

On Sun, Mar 08, 2020 at 07:55:38AM +0100, Greg Kroah-Hartman wrote:
> On Sat, Mar 07, 2020 at 11:49:29AM +0100, Oscar Carter wrote:
> > Replace the bit left shift operation with the BIT_ULL() macro and remove
> > the unnecessary "and" operation against the bit_nr variable.
> >
> > Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
> > ---
> >  drivers/staging/vt6656/main_usb.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
> > index 5e48b3ddb94c..f7ca9e97594d 100644
> > --- a/drivers/staging/vt6656/main_usb.c
> > +++ b/drivers/staging/vt6656/main_usb.c
> > @@ -21,6 +21,7 @@
> >   */
> >  #undef __NO_VERSION__
> >
> > +#include <linux/bits.h>
> >  #include <linux/etherdevice.h>
> >  #include <linux/file.h>
> >  #include "device.h"
> > @@ -802,8 +803,7 @@ static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
> >
> >  	netdev_hw_addr_list_for_each(ha, mc_list) {
> >  		bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
> > -
> > -		mc_filter |= 1ULL << (bit_nr & 0x3f);
> > +		mc_filter |= BIT_ULL(bit_nr);
>
> Are you sure this does the same thing?  You are not masking off bit_nr
> anymore, why not?

My reasons are exposed below:

The ether_crc function returns an u32 type (unsigned of 32 bits). Then the right
shift operand discards the 26 lsb bits (the bits shifted off the right side are
discarded). The 6 msb bits of the u32 returned by the ether_crc function are
positioned in bit 5 to bit 0 of the variable bit_nr. Due to the right shift
happens over an unsigned type, the 26 new bits added on the left side will be 0.

In summary, after the right bit shift operation we obtain in the variable bit_nr
(unsigned of 32 bits) the value represented by the 6 msb bits of the value
returned by the ether_crc function. So, only the 6 lsb bits of the variable
bit_nr are important. The 26 msb bits of this variable are 0.

In this situation, the "and" operation with the mask 0x3f (mask of 6 lsb bits)
is unnecessary due to its purpose is to reset (set to 0 value) the 26 msb bits
that are yet 0.
>
> thanks,
>
> greg k-h

thanks,

Oscar

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: vt6656: Use BIT_ULL() macro instead of bit shift operation
  2020-03-08 16:13   ` Oscar Carter
@ 2020-03-08 19:22     ` Malcolm Priestley
  2020-03-10  9:50       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 6+ messages in thread
From: Malcolm Priestley @ 2020-03-08 19:22 UTC (permalink / raw)
  To: Oscar Carter, Greg Kroah-Hartman
  Cc: Forest Bond, devel, linux-kernel, Gabriela Bittencourt, Colin Ian King

>>>   */
>>>  #undef __NO_VERSION__
>>>
>>> +#include <linux/bits.h>
>>>  #include <linux/etherdevice.h>
>>>  #include <linux/file.h>
>>>  #include "device.h"
>>> @@ -802,8 +803,7 @@ static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
>>>
>>>  	netdev_hw_addr_list_for_each(ha, mc_list) {
>>>  		bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
>>> -
>>> -		mc_filter |= 1ULL << (bit_nr & 0x3f);
>>> +		mc_filter |= BIT_ULL(bit_nr);
>>
>> Are you sure this does the same thing?  You are not masking off bit_nr
>> anymore, why not?
> 
> My reasons are exposed below:
> 
> The ether_crc function returns an u32 type (unsigned of 32 bits). Then the right
> shift operand discards the 26 lsb bits (the bits shifted off the right side are
> discarded). The 6 msb bits of the u32 returned by the ether_crc function are
> positioned in bit 5 to bit 0 of the variable bit_nr. Due to the right shift
> happens over an unsigned type, the 26 new bits added on the left side will be 0.
> 
> In summary, after the right bit shift operation we obtain in the variable bit_nr
> (unsigned of 32 bits) the value represented by the 6 msb bits of the value
> returned by the ether_crc function. So, only the 6 lsb bits of the variable
> bit_nr are important. The 26 msb bits of this variable are 0.
> 
> In this situation, the "and" operation with the mask 0x3f (mask of 6 lsb bits)
> is unnecessary due to its purpose is to reset (set to 0 value) the 26 msb bits
> that are yet 0.

The mask is only there out of legacy originally it was 31(0x1f) and the
bit_nr spread across two mc_filter u32 arrays.

The mask is not needed now it is u64.

The patch is fine.

Regards

Malcolm



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: vt6656: Use BIT_ULL() macro instead of bit shift operation
  2020-03-08 19:22     ` Malcolm Priestley
@ 2020-03-10  9:50       ` Greg Kroah-Hartman
  2020-03-14 15:06         ` Oscar Carter
  0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2020-03-10  9:50 UTC (permalink / raw)
  To: Malcolm Priestley
  Cc: Oscar Carter, devel, Colin Ian King, Forest Bond,
	Gabriela Bittencourt, linux-kernel

On Sun, Mar 08, 2020 at 07:22:07PM +0000, Malcolm Priestley wrote:
> >>>   */
> >>>  #undef __NO_VERSION__
> >>>
> >>> +#include <linux/bits.h>
> >>>  #include <linux/etherdevice.h>
> >>>  #include <linux/file.h>
> >>>  #include "device.h"
> >>> @@ -802,8 +803,7 @@ static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
> >>>
> >>>  	netdev_hw_addr_list_for_each(ha, mc_list) {
> >>>  		bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
> >>> -
> >>> -		mc_filter |= 1ULL << (bit_nr & 0x3f);
> >>> +		mc_filter |= BIT_ULL(bit_nr);
> >>
> >> Are you sure this does the same thing?  You are not masking off bit_nr
> >> anymore, why not?
> > 
> > My reasons are exposed below:
> > 
> > The ether_crc function returns an u32 type (unsigned of 32 bits). Then the right
> > shift operand discards the 26 lsb bits (the bits shifted off the right side are
> > discarded). The 6 msb bits of the u32 returned by the ether_crc function are
> > positioned in bit 5 to bit 0 of the variable bit_nr. Due to the right shift
> > happens over an unsigned type, the 26 new bits added on the left side will be 0.
> > 
> > In summary, after the right bit shift operation we obtain in the variable bit_nr
> > (unsigned of 32 bits) the value represented by the 6 msb bits of the value
> > returned by the ether_crc function. So, only the 6 lsb bits of the variable
> > bit_nr are important. The 26 msb bits of this variable are 0.
> > 
> > In this situation, the "and" operation with the mask 0x3f (mask of 6 lsb bits)
> > is unnecessary due to its purpose is to reset (set to 0 value) the 26 msb bits
> > that are yet 0.
> 
> The mask is only there out of legacy originally it was 31(0x1f) and the
> bit_nr spread across two mc_filter u32 arrays.
> 
> The mask is not needed now it is u64.
> 
> The patch is fine.

Ok, then the changelog needs to be fixed up to explain all of this and
resent.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: vt6656: Use BIT_ULL() macro instead of bit shift operation
  2020-03-10  9:50       ` Greg Kroah-Hartman
@ 2020-03-14 15:06         ` Oscar Carter
  0 siblings, 0 replies; 6+ messages in thread
From: Oscar Carter @ 2020-03-14 15:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Malcolm Priestley, devel, Colin Ian King, Forest Bond,
	Gabriela Bittencourt, linux-kernel, Oscar Carter

On Tue, Mar 10, 2020 at 10:50:11AM +0100, Greg Kroah-Hartman wrote:
> On Sun, Mar 08, 2020 at 07:22:07PM +0000, Malcolm Priestley wrote:
> > >>>   */
> > >>>  #undef __NO_VERSION__
> > >>>
> > >>> +#include <linux/bits.h>
> > >>>  #include <linux/etherdevice.h>
> > >>>  #include <linux/file.h>
> > >>>  #include "device.h"
> > >>> @@ -802,8 +803,7 @@ static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
> > >>>
> > >>>  	netdev_hw_addr_list_for_each(ha, mc_list) {
> > >>>  		bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
> > >>> -
> > >>> -		mc_filter |= 1ULL << (bit_nr & 0x3f);
> > >>> +		mc_filter |= BIT_ULL(bit_nr);
> > >>
> > >> Are you sure this does the same thing?  You are not masking off bit_nr
> > >> anymore, why not?
> > >
> > > My reasons are exposed below:
> > >
> > > The ether_crc function returns an u32 type (unsigned of 32 bits). Then the right
> > > shift operand discards the 26 lsb bits (the bits shifted off the right side are
> > > discarded). The 6 msb bits of the u32 returned by the ether_crc function are
> > > positioned in bit 5 to bit 0 of the variable bit_nr. Due to the right shift
> > > happens over an unsigned type, the 26 new bits added on the left side will be 0.
> > >
> > > In summary, after the right bit shift operation we obtain in the variable bit_nr
> > > (unsigned of 32 bits) the value represented by the 6 msb bits of the value
> > > returned by the ether_crc function. So, only the 6 lsb bits of the variable
> > > bit_nr are important. The 26 msb bits of this variable are 0.
> > >
> > > In this situation, the "and" operation with the mask 0x3f (mask of 6 lsb bits)
> > > is unnecessary due to its purpose is to reset (set to 0 value) the 26 msb bits
> > > that are yet 0.
> >
> > The mask is only there out of legacy originally it was 31(0x1f) and the
> > bit_nr spread across two mc_filter u32 arrays.
> >
> > The mask is not needed now it is u64.
> >
> > The patch is fine.
>
> Ok, then the changelog needs to be fixed up to explain all of this and
> resent.

Ok, I will create a new version patch with all of this information and I will
resend it.

>
> thanks,
>
> greg k-h

thanks,

Oscar

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-15  4:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-07 10:49 [PATCH] staging: vt6656: Use BIT_ULL() macro instead of bit shift operation Oscar Carter
2020-03-08  6:55 ` Greg Kroah-Hartman
2020-03-08 16:13   ` Oscar Carter
2020-03-08 19:22     ` Malcolm Priestley
2020-03-10  9:50       ` Greg Kroah-Hartman
2020-03-14 15:06         ` Oscar Carter

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