Skip to contentSkip to conversation

ath10k: htt_rx: Fix signedness bug in ath10k_update_per_peer_tx_stats

PATCH In review Gustavo A. R. Silva 4 participants 9 messages Oct 5, 2018 – Oct 13, 2018 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ath10k: htt_rx: Fix signedness bug in ath10k_update_per_peer_tx_stats

Currently, the error handling for the call to function ath10k_get_legacy_rate_idx() doesn't work because *rate_idx* is of type u8 (8 bits, unsigned), which makes it impossible for it to hold a value less than 0.

Fix this by changing the type of variable *rate_idx* to s8 (8 bits, signed).

Addresses-Coverity-ID: 1473914 ("Unsigned compared against 0")

Fixes 0189dbd71cbd ("ath10k: get the legacy rate index to update the txrate table")
---
 drivers/net/wireless/ath/ath10k/htt_rx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +2 -1
index f240525..edd0e74 100644
@@ -2753,7 +2753,8 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
 				struct ath10k_per_peer_tx_stats *peer_stats)
 {
 	struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
-	u8 rate = 0, rate_idx = 0, sgi;
+	u8 rate = 0, sgi;
+	s8 rate_idx = 0;
 	struct rate_info txrate;
 
 	lockdep_assert_held(&ar->data_lock);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 8 lines · Gustavo A. R. Silva

Currently, the error handling for the call to function ath10k_get_legacy_rate_idx() doesn't work because *rate_idx* is of type u8 (8 bits, unsigned), which makes it impossible for it to hold a value less than 0.

Fix this by changing the type of variable *rate_idx* to s8 (8 bits, signed).

There are more than 127 rates, are you sure this is doing what you want?

Thanks,
Ben

Quoted 23 lines

Addresses-Coverity-ID: 1473914 ("Unsigned compared against 0")

Fixes 0189dbd71cbd ("ath10k: get the legacy rate index to update the txrate table")
---
 drivers/net/wireless/ath/ath10k/htt_rx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +2 -1
index f240525..edd0e74 100644
@@ -2753,7 +2753,8 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
 				struct ath10k_per_peer_tx_stats *peer_stats)
 {
 	struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
-	u8 rate = 0, rate_idx = 0, sgi;
+	u8 rate = 0, sgi;
+	s8 rate_idx = 0;
 	struct rate_info txrate;
 
 	lockdep_assert_held(&ar->data_lock);
Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
#2 lore raw
Quoted 7 lines · Ben Greear
Quoted 6 lines · Gustavo A. R. Silva

Currently, the error handling for the call to function ath10k_get_legacy_rate_idx() doesn't work because *rate_idx* is of type u8 (8 bits, unsigned), which makes it impossible for it to hold a value less than 0.

Quoted 6 lines
Quoted 2 lines

Fix this by changing the type of variable *rate_idx* to s8 (8 bits, signed).

There are more than 127 rates, are you sure this is doing what you want?

Based on the following function, rate_idx can only hold values from 0 to 11

static inline int ath10k_get_legacy_rate_idx(struct ath10k *ar, u8 rate)

{
        static const u8 legacy_rates[] = {1, 2, 5, 11, 6, 9, 12,
                                          18, 24, 36, 48, 54};
        int i;

        for (i = 0; i < ARRAY_SIZE(legacy_rates); i++) {
                if (rate == legacy_rates[i])
                        return i;
        }

        ath10k_warn(ar, "Invalid legacy rate %hhd peer stats", rate);
        return -EINVAL;
}

Thanks
--
Gustavo

Quoted 28 lines

Thanks,
Ben

Quoted 23 lines

Addresses-Coverity-ID: 1473914 ("Unsigned compared against 0")

Fixes 0189dbd71cbd ("ath10k: get the legacy rate index to update the txrate table")

---
 drivers/net/wireless/ath/ath10k/htt_rx.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +2 -1
index f240525..edd0e74 100644
@@ -2753,7 +2753,8 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
                  struct ath10k_per_peer_tx_stats *peer_stats)
  {
      struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
-    u8 rate = 0, rate_idx = 0, sgi;
+    u8 rate = 0, sgi;
+    s8 rate_idx = 0;
      struct rate_info txrate;
 
      lockdep_assert_held(&ar->data_lock);
#3 lore raw
Quoted 10 lines · Gustavo A. R. Silva
Quoted 7 lines · Ben Greear
Quoted 6 lines · Gustavo A. R. Silva

Currently, the error handling for the call to function ath10k_get_legacy_rate_idx() doesn't work because *rate_idx* is of type u8 (8 bits, unsigned), which makes it impossible for it to hold a value less than 0.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Fix this by changing the type of variable *rate_idx* to s8 (8 bits, signed).

There are more than 127 rates, are you sure this is doing what you want?

Based on the following function, rate_idx can only hold values from 0 to 11

... and of course -EINVAL too

Quoted 47 lines

static inline int ath10k_get_legacy_rate_idx(struct ath10k *ar, u8 rate)

{
        static const u8 legacy_rates[] = {1, 2, 5, 11, 6, 9, 12,
                                          18, 24, 36, 48, 54};
        int i;

        for (i = 0; i < ARRAY_SIZE(legacy_rates); i++) {
                if (rate == legacy_rates[i])
                        return i;
        }

        ath10k_warn(ar, "Invalid legacy rate %hhd peer stats", rate);
        return -EINVAL;
}

Thanks
--
Gustavo

Quoted 28 lines

Thanks,
Ben

Quoted 23 lines

Addresses-Coverity-ID: 1473914 ("Unsigned compared against 0")

Fixes 0189dbd71cbd ("ath10k: get the legacy rate index to update the txrate table")

---
 drivers/net/wireless/ath/ath10k/htt_rx.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +2 -1
index f240525..edd0e74 100644
@@ -2753,7 +2753,8 @@ ath10k_update_per_peer_tx_stats(struct ath10k *ar,
                  struct ath10k_per_peer_tx_stats *peer_stats)
  {
      struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
-    u8 rate = 0, rate_idx = 0, sgi;
+    u8 rate = 0, sgi;
+    s8 rate_idx = 0;
      struct rate_info txrate;
 
      lockdep_assert_held(&ar->data_lock);
#4 lore raw
Quoted 14 lines · Gustavo A. R. Silva
Quoted 13 lines · Gustavo A. R. Silva
Quoted 10 lines · Ben Greear
Quoted 8 lines · Gustavo A. R. Silva

Currently, the error handling for the call to function ath10k_get_legacy_rate_idx() doesn't work because *rate_idx* is of type u8 (8 bits, unsigned), which makes it impossible for it to hold a value less than 0.

Fix this by changing the type of variable *rate_idx* to s8 (8 bits, signed).

Quoted 57 lines
Quoted 6 lines
Quoted 3 lines

There are more than 127 rates, are you sure this is doing what you want?

Based on the following function, rate_idx can only hold values from 0 to 11

... and of course -EINVAL too

Quoted 48 lines

static inline int ath10k_get_legacy_rate_idx(struct ath10k *ar, u8 rate)

{
        static const u8 legacy_rates[] = {1, 2, 5, 11, 6, 9, 12,
                                          18, 24, 36, 48, 54};
        int i;

        for (i = 0; i < ARRAY_SIZE(legacy_rates); i++) {
                if (rate == legacy_rates[i])
                        return i;
        }

        ath10k_warn(ar, "Invalid legacy rate %hhd peer stats", rate);
        return -EINVAL;
}

Thanks
--
Gustavo

Quoted 29 lines

Thanks,
Ben

Quoted 24 lines

Addresses-Coverity-ID: 1473914 ("Unsigned compared against 0")

Fixes 0189dbd71cbd ("ath10k: get the legacy rate index to update the txrate table")

---
 drivers/net/wireless/ath/ath10k/htt_rx.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +2 -1
index f240525..edd0e74 100644
@@ -2753,7 +2753,8 @@ ath10k_update_per_peer_tx_stats(struct ath10k 
 *ar,
                  struct ath10k_per_peer_tx_stats *peer_stats)
  {
      struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
-    u8 rate = 0, rate_idx = 0, sgi;
+    u8 rate = 0, sgi;
+    s8 rate_idx = 0;
      struct rate_info txrate;
 

     lockdep_assert_held(&ar->data_lock);

I have sent a patch to address this,
https://patchwork.kernel.org/patch/10611943/

Thanks
Anil.

#6 lore raw
In reply to Gustavo A. R. Silva
Quoted 6 lines · Gustavo A. R. Silva

Currently, the error handling for the call to function ath10k_get_legacy_rate_idx() doesn't work because *rate_idx* is of type u8 (8 bits, unsigned), which makes it impossible for it to hold a value less than 0.

Quoted 7 lines

Fix this by changing the type of variable *rate_idx* to s8 (8 bits, signed).

Addresses-Coverity-ID: 1473914 ("Unsigned compared against 0")

Fixes 0189dbd71cbd ("ath10k: get the legacy rate index to update the txrate table")

Patch applied to ath-next branch of ath.git, thanks.

9d9cdbf3f9ed ath10k: htt_rx: fix signedness bug in ath10k_update_per_peer_tx_stats

Signature · 3 lines
https://patchwork.kernel.org/patch/10628675/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#7 lore raw
In reply to Gustavo A. R. Silva
Quoted 6 lines · Gustavo A. R. Silva

Currently, the error handling for the call to function ath10k_get_legacy_rate_idx() doesn't work because *rate_idx* is of type u8 (8 bits, unsigned), which makes it impossible for it to hold a value less than 0.

Quoted 7 lines

Fix this by changing the type of variable *rate_idx* to s8 (8 bits, signed).

Addresses-Coverity-ID: 1473914 ("Unsigned compared against 0")

Fixes 0189dbd71cbd ("ath10k: get the legacy rate index to update the txrate table")

Patch applied to ath-next branch of ath.git, thanks.

9d9cdbf3f9ed ath10k: htt_rx: fix signedness bug in ath10k_update_per_peer_tx_stats

Signature · 3 lines
https://patchwork.kernel.org/patch/10628675/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches