diff mbox

[V2] regdb: Generalize the mW to dBm power conversion

Message ID 1401107504-11385-1-git-send-email-chaitanya.mgit@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Krishna Chaitanya May 26, 2014, 12:31 p.m. UTC
Generalize the power conversion from mW to dBm 
using log. This should fix the below compilation
error for country NO which adds a new power value
2000mW which is not handled earlier.

 CC [M]  net/wireless/wext-sme.o
 CC [M]  net/wireless/regdb.o
net/wireless/regdb.c:1130:1: error: Unknown undeclared here (not in
a function)
net/wireless/regdb.c:1130:9: error: expected } before power
make[2]: *** [net/wireless/regdb.o] Error 1
make[1]: *** [net/wireless] Error 2
make: *** [net] Error 2

Reported-By:  John Walker <john@x109.net>
Signed-off-by: Chaitanya T K <chaitanya.mgit@gmail.com>

---
 net/wireless/genregdb.awk |   12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

John W. Linville May 27, 2014, 3:31 p.m. UTC | #1
On Mon, May 26, 2014 at 06:01:44PM +0530, chaitanya.mgit@gmail.com wrote:
> Generalize the power conversion from mW to dBm 
> using log. This should fix the below compilation
> error for country NO which adds a new power value
> 2000mW which is not handled earlier.
> 
>  CC [M]  net/wireless/wext-sme.o
>  CC [M]  net/wireless/regdb.o
> net/wireless/regdb.c:1130:1: error: Unknown undeclared here (not in
> a function)
> net/wireless/regdb.c:1130:9: error: expected } before power
> make[2]: *** [net/wireless/regdb.o] Error 1
> make[1]: *** [net/wireless] Error 2
> make: *** [net] Error 2
> 
> Reported-By:  John Walker <john@x109.net>
> Signed-off-by: Chaitanya T K <chaitanya.mgit@gmail.com>
> 
> ---
>  net/wireless/genregdb.awk |   12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
> index 4119833..949ee38 100644
> --- a/net/wireless/genregdb.awk
> +++ b/net/wireless/genregdb.awk
> @@ -68,17 +68,7 @@ function parse_reg_rule()
>  	sub(/,/, "", units)
>  	dfs_cac = $9
>  	if (units == "mW") {
> -		if (power == 100) {
> -			power = 20
> -		} else if (power == 200) {
> -			power = 23
> -		} else if (power == 500) {
> -			power = 27
> -		} else if (power == 1000) {
> -			power = 30
> -		} else {
> -			print "Unknown power value in database!"
> -		}
> +		power = 10 * (log(power)/log(10))
>  	} else {
>  		dfs_cac = $8
>  	}

I'm not fond of the unnecessary parenthesis.  But otherwise it seems great.

Acked-by: John W. Linville <linville@tuxdriver.com>
Johannes Berg May 27, 2014, 3:57 p.m. UTC | #2
On Mon, 2014-05-26 at 18:01 +0530, chaitanya.mgit@gmail.com wrote:
> Generalize the power conversion from mW to dBm 
> using log. This should fix the below compilation
> error for country NO which adds a new power value
> 2000mW which is not handled earlier.
> 
>  CC [M]  net/wireless/wext-sme.o
>  CC [M]  net/wireless/regdb.o
> net/wireless/regdb.c:1130:1: error: Unknown undeclared here (not in
> a function)
> net/wireless/regdb.c:1130:9: error: expected } before power
> make[2]: *** [net/wireless/regdb.o] Error 1
> make[1]: *** [net/wireless] Error 2
> make: *** [net] Error 2
> 
> Reported-By:  John Walker <john@x109.net>
> Signed-off-by: Chaitanya T K <chaitanya.mgit@gmail.com>
> 
> ---
>  net/wireless/genregdb.awk |   12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
> index 4119833..949ee38 100644
> --- a/net/wireless/genregdb.awk
> +++ b/net/wireless/genregdb.awk
> @@ -68,17 +68,7 @@ function parse_reg_rule()
>  	sub(/,/, "", units)
>  	dfs_cac = $9
>  	if (units == "mW") {
> -		if (power == 100) {
> -			power = 20
> -		} else if (power == 200) {
> -			power = 23
> -		} else if (power == 500) {
> -			power = 27
> -		} else if (power == 1000) {
> -			power = 30
> -		} else {
> -			print "Unknown power value in database!"
> -		}
> +		power = 10 * (log(power)/log(10))

This patch is wrong :-)
Bonus points for those who can figure it out without looking at the one
I'm committing ;-)

johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Krishna Chaitanya May 27, 2014, 4:11 p.m. UTC | #3
On Tue, May 27, 2014 at 9:27 PM, Johannes Berg
<johannes@sipsolutions.net> wrote:
>
> On Mon, 2014-05-26 at 18:01 +0530, chaitanya.mgit@gmail.com wrote:
> > Generalize the power conversion from mW to dBm
> > using log. This should fix the below compilation
> > error for country NO which adds a new power value
> > 2000mW which is not handled earlier.
> >
> >  CC [M]  net/wireless/wext-sme.o
> >  CC [M]  net/wireless/regdb.o
> > net/wireless/regdb.c:1130:1: error: Unknown undeclared here (not in
> > a function)
> > net/wireless/regdb.c:1130:9: error: expected } before power
> > make[2]: *** [net/wireless/regdb.o] Error 1
> > make[1]: *** [net/wireless] Error 2
> > make: *** [net] Error 2
> >
> > Reported-By:  John Walker <john@x109.net>
> > Signed-off-by: Chaitanya T K <chaitanya.mgit@gmail.com>
> >
> > ---
> >  net/wireless/genregdb.awk |   12 +-----------
> >  1 file changed, 1 insertion(+), 11 deletions(-)
> >
> > diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
> > index 4119833..949ee38 100644
> > --- a/net/wireless/genregdb.awk
> > +++ b/net/wireless/genregdb.awk
> > @@ -68,17 +68,7 @@ function parse_reg_rule()
> >       sub(/,/, "", units)
> >       dfs_cac = $9
> >       if (units == "mW") {
> > -             if (power == 100) {
> > -                     power = 20
> > -             } else if (power == 200) {
> > -                     power = 23
> > -             } else if (power == 500) {
> > -                     power = 27
> > -             } else if (power == 1000) {
> > -                     power = 30
> > -             } else {
> > -                     print "Unknown power value in database!"
> > -             }
> > +             power = 10 * (log(power)/log(10))
>
> This patch is wrong :-)
> Bonus points for those who can figure it out without looking at the one
> I'm committing ;-)
>
Forgot to handle the print to the file. (Looked at the commit :-))
Thanks Johannes and John.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johannes Berg May 27, 2014, 4:42 p.m. UTC | #4
On Tue, 2014-05-27 at 21:41 +0530, Krishna Chaitanya wrote:
> On Tue, May 27, 2014 at 9:27 PM, Johannes Berg
> <johannes@sipsolutions.net> wrote:
> >
> > On Mon, 2014-05-26 at 18:01 +0530, chaitanya.mgit@gmail.com wrote:
> > > Generalize the power conversion from mW to dBm
> > > using log. This should fix the below compilation
> > > error for country NO which adds a new power value
> > > 2000mW which is not handled earlier.
> > >
> > >  CC [M]  net/wireless/wext-sme.o
> > >  CC [M]  net/wireless/regdb.o
> > > net/wireless/regdb.c:1130:1: error: Unknown undeclared here (not in
> > > a function)
> > > net/wireless/regdb.c:1130:9: error: expected } before power
> > > make[2]: *** [net/wireless/regdb.o] Error 1
> > > make[1]: *** [net/wireless] Error 2
> > > make: *** [net] Error 2
> > >
> > > Reported-By:  John Walker <john@x109.net>
> > > Signed-off-by: Chaitanya T K <chaitanya.mgit@gmail.com>
> > >
> > > ---
> > >  net/wireless/genregdb.awk |   12 +-----------
> > >  1 file changed, 1 insertion(+), 11 deletions(-)
> > >
> > > diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
> > > index 4119833..949ee38 100644
> > > --- a/net/wireless/genregdb.awk
> > > +++ b/net/wireless/genregdb.awk
> > > @@ -68,17 +68,7 @@ function parse_reg_rule()
> > >       sub(/,/, "", units)
> > >       dfs_cac = $9
> > >       if (units == "mW") {
> > > -             if (power == 100) {
> > > -                     power = 20
> > > -             } else if (power == 200) {
> > > -                     power = 23
> > > -             } else if (power == 500) {
> > > -                     power = 27
> > > -             } else if (power == 1000) {
> > > -                     power = 30
> > > -             } else {
> > > -                     print "Unknown power value in database!"
> > > -             }
> > > +             power = 10 * (log(power)/log(10))
> >
> > This patch is wrong :-)
> > Bonus points for those who can figure it out without looking at the one
> > I'm committing ;-)
> >
> Forgot to handle the print to the file. (Looked at the commit :-))

No, the print worked - the difference is that %.0f rounds, and %d
truncates (so that for power=500 it comes out wrong for %d)

johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
index 4119833..949ee38 100644
--- a/net/wireless/genregdb.awk
+++ b/net/wireless/genregdb.awk
@@ -68,17 +68,7 @@  function parse_reg_rule()
 	sub(/,/, "", units)
 	dfs_cac = $9
 	if (units == "mW") {
-		if (power == 100) {
-			power = 20
-		} else if (power == 200) {
-			power = 23
-		} else if (power == 500) {
-			power = 27
-		} else if (power == 1000) {
-			power = 30
-		} else {
-			print "Unknown power value in database!"
-		}
+		power = 10 * (log(power)/log(10))
 	} else {
 		dfs_cac = $8
 	}