* [patch] staging: vt6655: rewrite CARDvUpdateBasicTopRate()
@ 2010-02-13 8:03 Dan Carpenter
2010-02-13 9:36 ` Jiri Slaby
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-02-13 8:03 UTC (permalink / raw)
To: kernel-janitors
Originally, I wrote a patch to add some missing curly braces, but Walter
Harms suggested that I should just rewrite the whole function to use the
kernel version of ffs().
It is odd to subtract one from the result of ffs() but that was present
in the original code as well (once you add the missing curly braces).
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
This patch replaces my previous patch. I don't have the hardware to
actually test this change. :/
diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
index db78614..3a1f2be 100644
--- a/drivers/staging/vt6655/card.c
+++ b/drivers/staging/vt6655/card.c
@@ -2780,28 +2780,32 @@ void vUpdateIFS (PVOID pDeviceHandler)
VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (BYTE)byMaxMin);
}
+static int top_OFDM_basic_rate(u16 basic_rate)
+{
+ int rate;
+
+ rate = ffs(basic_rate) - 1;
+ if (rate > RATE_54M || rate < RATE_6M)
+ return RATE_24M;
+ return rate;
+}
+
+static int top_CCK(u16 basic_rate)
+{
+ int rate;
+
+ rate = ffs(basic_rate) - 1;
+ if (rate > RATE_11M || rate < 0)
+ return RATE_1M;
+ return rate;
+}
+
void CARDvUpdateBasicTopRate (PVOID pDeviceHandler)
{
- PSDevice pDevice = (PSDevice) pDeviceHandler;
- BYTE byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
- BYTE ii;
-
- //Determines the highest basic rate.
- for (ii = RATE_54M; ii >= RATE_6M; ii --) {
- if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) )
- byTopOFDM = ii;
- break;
- }
- pDevice->byTopOFDMBasicRate = byTopOFDM;
-
- for (ii = RATE_11M;; ii --) {
- if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) )
- byTopCCK = ii;
- break;
- if (ii = RATE_1M)
- break;
- }
- pDevice->byTopCCKBasicRate = byTopCCK;
+ PSDevice pDevice = (PSDevice) pDeviceHandler;
+
+ pDevice->byTopOFDMBasicRate = top_OFDM_basic_rate(pDevice->wBasicRate);
+ pDevice->byTopCCKBasicRate = top_CCK(pDevice->wBasicRate);
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [patch] staging: vt6655: rewrite CARDvUpdateBasicTopRate()
2010-02-13 8:03 [patch] staging: vt6655: rewrite CARDvUpdateBasicTopRate() Dan Carpenter
@ 2010-02-13 9:36 ` Jiri Slaby
2010-02-13 9:44 ` Jiri Slaby
2010-02-13 10:06 ` Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2010-02-13 9:36 UTC (permalink / raw)
To: kernel-janitors
On 02/13/2010 09:03 AM, Dan Carpenter wrote:
> Originally, I wrote a patch to add some missing curly braces, but Walter
> Harms suggested that I should just rewrite the whole function to use the
> kernel version of ffs().
>
> It is odd to subtract one from the result of ffs() but that was present
> in the original code as well (once you add the missing curly braces).
>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
> This patch replaces my previous patch. I don't have the hardware to
> actually test this change. :/
>
> diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
> index db78614..3a1f2be 100644
> --- a/drivers/staging/vt6655/card.c
> +++ b/drivers/staging/vt6655/card.c
> @@ -2780,28 +2780,32 @@ void vUpdateIFS (PVOID pDeviceHandler)
> VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (BYTE)byMaxMin);
> }
>
> +static int top_OFDM_basic_rate(u16 basic_rate)
> +{
> + int rate;
> +
> + rate = ffs(basic_rate) - 1;
> + if (rate > RATE_54M || rate < RATE_6M)
> + return RATE_24M;
> + return rate;
> +}
> +
> +static int top_CCK(u16 basic_rate)
> +{
> + int rate;
> +
> + rate = ffs(basic_rate) - 1;
> + if (rate > RATE_11M || rate < 0)
> + return RATE_1M;
> + return rate;
> +}
> +
> void CARDvUpdateBasicTopRate (PVOID pDeviceHandler)
> {
> - PSDevice pDevice = (PSDevice) pDeviceHandler;
> - BYTE byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
> - BYTE ii;
> -
> - //Determines the highest basic rate.
> - for (ii = RATE_54M; ii >= RATE_6M; ii --) {
> - if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) )
> - byTopOFDM = ii;
> - break;
> - }
> - pDevice->byTopOFDMBasicRate = byTopOFDM;
> -
> - for (ii = RATE_11M;; ii --) {
> - if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) )
> - byTopCCK = ii;
> - break;
> - if (ii = RATE_1M)
> - break;
> - }
Hmm, but this is different from ffs in that it starts from higher bits
and go down and hence finds the highest possible rate (there may be more
basic rates). Your patch selects the lowest possible one.
You cannot use ffs and fls here.
--
js
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] staging: vt6655: rewrite CARDvUpdateBasicTopRate()
2010-02-13 8:03 [patch] staging: vt6655: rewrite CARDvUpdateBasicTopRate() Dan Carpenter
2010-02-13 9:36 ` Jiri Slaby
@ 2010-02-13 9:44 ` Jiri Slaby
2010-02-13 10:06 ` Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2010-02-13 9:44 UTC (permalink / raw)
To: kernel-janitors
On 02/13/2010 10:36 AM, Jiri Slaby wrote:
> You cannot use ffs and fls here.
Actually you can (fls), if you add proper masks there like
fls(pDevice->wBasicRate & ((1 << RATE_24M) - 1) & ~((1 << RATE_6M) -
1)), but with some macro-ification inside. Dunno if it gets better though.
--
js
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] staging: vt6655: rewrite CARDvUpdateBasicTopRate()
2010-02-13 8:03 [patch] staging: vt6655: rewrite CARDvUpdateBasicTopRate() Dan Carpenter
2010-02-13 9:36 ` Jiri Slaby
2010-02-13 9:44 ` Jiri Slaby
@ 2010-02-13 10:06 ` Dan Carpenter
2 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2010-02-13 10:06 UTC (permalink / raw)
To: kernel-janitors
On Sat, Feb 13, 2010 at 10:44:53AM +0100, Jiri Slaby wrote:
> On 02/13/2010 10:36 AM, Jiri Slaby wrote:
> > You cannot use ffs and fls here.
>
> Actually you can (fls), if you add proper masks there like
> fls(pDevice->wBasicRate & ((1 << RATE_24M) - 1) & ~((1 << RATE_6M) -
> 1)), but with some macro-ification inside. Dunno if it gets better though.
>
Ok. I didn't understand how ffs() and fls() worked before. Sorry about that.
Let's just apply my original patch because that is an obvious one.
If I could test my changes, I would feel more comfortable rewriting stuff
but I don't have the hardware.
regards,
dan carpenter
> --
> js
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-02-13 10:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-13 8:03 [patch] staging: vt6655: rewrite CARDvUpdateBasicTopRate() Dan Carpenter
2010-02-13 9:36 ` Jiri Slaby
2010-02-13 9:44 ` Jiri Slaby
2010-02-13 10:06 ` Dan Carpenter
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.