diff options
author | weongyo <weongyo@FreeBSD.org> | 2010-03-01 23:51:13 +0000 |
---|---|---|
committer | weongyo <weongyo@FreeBSD.org> | 2010-03-01 23:51:13 +0000 |
commit | d30d21206f71e5dcf376f55806e6ba7d1bf7cc22 (patch) | |
tree | c4d25e45d29a5fa564407c69353de441f4a535d1 /sys/dev/bwn | |
parent | 2f0c753d6eef4f26617a511e6456ccf01da91b88 (diff) | |
download | FreeBSD-src-d30d21206f71e5dcf376f55806e6ba7d1bf7cc22.zip FreeBSD-src-d30d21206f71e5dcf376f55806e6ba7d1bf7cc22.tar.gz |
calculates the integer square root if a positive integer X is larger
than 256 instead of using sqrt_table.
Reported by: Joe Marcus Clarke <marcus at freebsd dot org>
Diffstat (limited to 'sys/dev/bwn')
-rw-r--r-- | sys/dev/bwn/if_bwn.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/sys/dev/bwn/if_bwn.c b/sys/dev/bwn/if_bwn.c index 482683a..7d1e663 100644 --- a/sys/dev/bwn/if_bwn.c +++ b/sys/dev/bwn/if_bwn.c @@ -12846,7 +12846,6 @@ bwn_phy_lp_clear_deaf(struct bwn_mac *mac, uint8_t user) static unsigned int bwn_sqrt(struct bwn_mac *mac, unsigned int x) { - struct bwn_softc *sc = mac->mac_sc; /* Table holding (10 * sqrt(x)) for x between 1 and 256. */ static uint8_t sqrt_table[256] = { 10, 14, 17, 20, 22, 24, 26, 28, @@ -12886,9 +12885,11 @@ bwn_sqrt(struct bwn_mac *mac, unsigned int x) if (x == 0) return (0); if (x >= 256) { - device_printf(sc->sc_dev, - "out of bounds of the square-root table (%d)\n", x); - return (16); + unsigned int tmp; + + for (tmp = 0; x >= (2 * tmp) + 1; x -= (2 * tmp++) + 1) + /* do nothing */ ; + return (tmp); } return (sqrt_table[x - 1] / 10); } |