All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: vt6656: Use fls instead of for loop in vnt_update_top_rates
@ 2020-04-19 10:09 ` Oscar Carter
  0 siblings, 0 replies; 6+ messages in thread
From: Oscar Carter @ 2020-04-19 10:09 UTC (permalink / raw)
  To: Forest Bond, Greg Kroah-Hartman
  Cc: Malcolm Priestley, Quentin Deslandes, Oscar Carter,
	John B . Wyatt IV, Colin Ian King, devel, linux-kernel

Replace the for loops of the vnt_update_top_rates function by the fls
function.

The purpose of the two for loops is to find the most significant bit set
in a range of bits. So, they can be replace by the fls function (find
last set) with a previous mask to define the range.

This way avoid the iteration over unnecessary for loops.

The header "linux/bits.h" can be remove as it is included in the header
"linux/bitops.h".

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

diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index 9bd37e57c727..952a7726fdd3 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -26,7 +26,7 @@
  *
  */

-#include <linux/bits.h>
+#include <linux/bitops.h>
 #include "device.h"
 #include "card.h"
 #include "baseband.h"
@@ -223,29 +223,13 @@ void vnt_update_ifs(struct vnt_private *priv)

 void vnt_update_top_rates(struct vnt_private *priv)
 {
-	u8 top_ofdm = RATE_24M, top_cck = RATE_1M;
-	u8 i;
+	int pos;

-	/*Determines the highest basic rate.*/
-	for (i = RATE_54M; i >= RATE_6M; i--) {
-		if (priv->basic_rates & (u16)(1 << i)) {
-			top_ofdm = i;
-			break;
-		}
-	}
-
-	priv->top_ofdm_basic_rate = top_ofdm;
-
-	for (i = RATE_11M;; i--) {
-		if (priv->basic_rates & (u16)(1 << i)) {
-			top_cck = i;
-			break;
-		}
-		if (i == RATE_1M)
-			break;
-	}
+	pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M));
+	priv->top_ofdm_basic_rate = pos ? pos-- : RATE_24M;

-	priv->top_cck_basic_rate = top_cck;
+	pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M));
+	priv->top_cck_basic_rate = pos ? pos-- : RATE_1M;
 }

 int vnt_ofdm_min_rate(struct vnt_private *priv)
--
2.20.1


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

* [PATCH] staging: vt6656: Use fls instead of for loop in vnt_update_top_rates
@ 2020-04-19 10:09 ` Oscar Carter
  0 siblings, 0 replies; 6+ messages in thread
From: Oscar Carter @ 2020-04-19 10:09 UTC (permalink / raw)
  To: Forest Bond, Greg Kroah-Hartman
  Cc: devel, Oscar Carter, Malcolm Priestley, John B . Wyatt IV,
	linux-kernel, Colin Ian King

Replace the for loops of the vnt_update_top_rates function by the fls
function.

The purpose of the two for loops is to find the most significant bit set
in a range of bits. So, they can be replace by the fls function (find
last set) with a previous mask to define the range.

This way avoid the iteration over unnecessary for loops.

The header "linux/bits.h" can be remove as it is included in the header
"linux/bitops.h".

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

diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index 9bd37e57c727..952a7726fdd3 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -26,7 +26,7 @@
  *
  */

-#include <linux/bits.h>
+#include <linux/bitops.h>
 #include "device.h"
 #include "card.h"
 #include "baseband.h"
@@ -223,29 +223,13 @@ void vnt_update_ifs(struct vnt_private *priv)

 void vnt_update_top_rates(struct vnt_private *priv)
 {
-	u8 top_ofdm = RATE_24M, top_cck = RATE_1M;
-	u8 i;
+	int pos;

-	/*Determines the highest basic rate.*/
-	for (i = RATE_54M; i >= RATE_6M; i--) {
-		if (priv->basic_rates & (u16)(1 << i)) {
-			top_ofdm = i;
-			break;
-		}
-	}
-
-	priv->top_ofdm_basic_rate = top_ofdm;
-
-	for (i = RATE_11M;; i--) {
-		if (priv->basic_rates & (u16)(1 << i)) {
-			top_cck = i;
-			break;
-		}
-		if (i == RATE_1M)
-			break;
-	}
+	pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M));
+	priv->top_ofdm_basic_rate = pos ? pos-- : RATE_24M;

-	priv->top_cck_basic_rate = top_cck;
+	pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M));
+	priv->top_cck_basic_rate = pos ? pos-- : RATE_1M;
 }

 int vnt_ofdm_min_rate(struct vnt_private *priv)
--
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH] staging: vt6656: Use fls instead of for loop in vnt_update_top_rates
  2020-04-19 10:09 ` Oscar Carter
@ 2020-04-20 12:10   ` Dan Carpenter
  -1 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2020-04-20 12:10 UTC (permalink / raw)
  To: Oscar Carter
  Cc: Forest Bond, Greg Kroah-Hartman, devel, Malcolm Priestley,
	John B . Wyatt IV, linux-kernel, Colin Ian King

On Sun, Apr 19, 2020 at 12:09:21PM +0200, Oscar Carter wrote:
> -	for (i = RATE_11M;; i--) {
> -		if (priv->basic_rates & (u16)(1 << i)) {
> -			top_cck = i;
> -			break;
> -		}
> -		if (i == RATE_1M)
> -			break;
> -	}
> +	pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M));
> +	priv->top_ofdm_basic_rate = pos ? pos-- : RATE_24M;
                                          ^^^^^
Argh...  Come on.  I don't want to have to break out the C standard to
see if this is defined behavior and where the sequence points are.  A
pre-op would be clear but the most clear thing is to write it like this:

	priv->top_ofdm_basic_rate = pos ? (pos - 1) : RATE_24M;


> 
> -	priv->top_cck_basic_rate = top_cck;
> +	pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M));
> +	priv->top_cck_basic_rate = pos ? pos-- : RATE_1M;
                                         ^^^^^
Same.

regards,
dan carpenter


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

* Re: [PATCH] staging: vt6656: Use fls instead of for loop in vnt_update_top_rates
@ 2020-04-20 12:10   ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2020-04-20 12:10 UTC (permalink / raw)
  To: Oscar Carter
  Cc: devel, John B . Wyatt IV, Malcolm Priestley, Greg Kroah-Hartman,
	linux-kernel, Forest Bond, Colin Ian King

On Sun, Apr 19, 2020 at 12:09:21PM +0200, Oscar Carter wrote:
> -	for (i = RATE_11M;; i--) {
> -		if (priv->basic_rates & (u16)(1 << i)) {
> -			top_cck = i;
> -			break;
> -		}
> -		if (i == RATE_1M)
> -			break;
> -	}
> +	pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M));
> +	priv->top_ofdm_basic_rate = pos ? pos-- : RATE_24M;
                                          ^^^^^
Argh...  Come on.  I don't want to have to break out the C standard to
see if this is defined behavior and where the sequence points are.  A
pre-op would be clear but the most clear thing is to write it like this:

	priv->top_ofdm_basic_rate = pos ? (pos - 1) : RATE_24M;


> 
> -	priv->top_cck_basic_rate = top_cck;
> +	pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M));
> +	priv->top_cck_basic_rate = pos ? pos-- : RATE_1M;
                                         ^^^^^
Same.

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH] staging: vt6656: Use fls instead of for loop in vnt_update_top_rates
  2020-04-20 12:10   ` Dan Carpenter
@ 2020-04-20 15:02     ` Oscar Carter
  -1 siblings, 0 replies; 6+ messages in thread
From: Oscar Carter @ 2020-04-20 15:02 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Oscar Carter, Forest Bond, Greg Kroah-Hartman, devel,
	Malcolm Priestley, John B . Wyatt IV, linux-kernel,
	Colin Ian King

On Mon, Apr 20, 2020 at 03:10:59PM +0300, Dan Carpenter wrote:
> On Sun, Apr 19, 2020 at 12:09:21PM +0200, Oscar Carter wrote:
> > -	for (i = RATE_11M;; i--) {
> > -		if (priv->basic_rates & (u16)(1 << i)) {
> > -			top_cck = i;
> > -			break;
> > -		}
> > -		if (i == RATE_1M)
> > -			break;
> > -	}
> > +	pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M));
> > +	priv->top_ofdm_basic_rate = pos ? pos-- : RATE_24M;
>                                           ^^^^^
> Argh...  Come on.  I don't want to have to break out the C standard to
> see if this is defined behavior and where the sequence points are.  A
> pre-op would be clear but the most clear thing is to write it like this:
>
> 	priv->top_ofdm_basic_rate = pos ? (pos - 1) : RATE_24M;
>
Ok, I do the modification as you suggested and resend a new version.
>
> >
> > -	priv->top_cck_basic_rate = top_cck;
> > +	pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M));
> > +	priv->top_cck_basic_rate = pos ? pos-- : RATE_1M;
>                                          ^^^^^
> Same.
>
> regards,
> dan carpenter
>
thanks,
oscar carter

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

* Re: [PATCH] staging: vt6656: Use fls instead of for loop in vnt_update_top_rates
@ 2020-04-20 15:02     ` Oscar Carter
  0 siblings, 0 replies; 6+ messages in thread
From: Oscar Carter @ 2020-04-20 15:02 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: devel, John B . Wyatt IV, Oscar Carter, Malcolm Priestley,
	Greg Kroah-Hartman, linux-kernel, Forest Bond, Colin Ian King

On Mon, Apr 20, 2020 at 03:10:59PM +0300, Dan Carpenter wrote:
> On Sun, Apr 19, 2020 at 12:09:21PM +0200, Oscar Carter wrote:
> > -	for (i = RATE_11M;; i--) {
> > -		if (priv->basic_rates & (u16)(1 << i)) {
> > -			top_cck = i;
> > -			break;
> > -		}
> > -		if (i == RATE_1M)
> > -			break;
> > -	}
> > +	pos = fls(priv->basic_rates & GENMASK(RATE_54M, RATE_6M));
> > +	priv->top_ofdm_basic_rate = pos ? pos-- : RATE_24M;
>                                           ^^^^^
> Argh...  Come on.  I don't want to have to break out the C standard to
> see if this is defined behavior and where the sequence points are.  A
> pre-op would be clear but the most clear thing is to write it like this:
>
> 	priv->top_ofdm_basic_rate = pos ? (pos - 1) : RATE_24M;
>
Ok, I do the modification as you suggested and resend a new version.
>
> >
> > -	priv->top_cck_basic_rate = top_cck;
> > +	pos = fls(priv->basic_rates & GENMASK(RATE_11M, RATE_1M));
> > +	priv->top_cck_basic_rate = pos ? pos-- : RATE_1M;
>                                          ^^^^^
> Same.
>
> regards,
> dan carpenter
>
thanks,
oscar carter
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-19 10:09 [PATCH] staging: vt6656: Use fls instead of for loop in vnt_update_top_rates Oscar Carter
2020-04-19 10:09 ` Oscar Carter
2020-04-20 12:10 ` Dan Carpenter
2020-04-20 12:10   ` Dan Carpenter
2020-04-20 15:02   ` Oscar Carter
2020-04-20 15:02     ` Oscar Carter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.