Skip to content

Commit a72eaa1

Browse files
dmantipovJeff Johnson
authored andcommitted
wifi: ath9k: cleanup ath9k_hw_get_nf_hist_mid()
In 'ath9k_hw_get_nf_hist_mid()', prefer 'memcpy()' and 'sort()' over an ad-hoc things. Briefly tested as a separate module. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Dmitry Antipov <[email protected]> Acked-by: Toke Høiland-Jørgensen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jeff Johnson <[email protected]>
1 parent f647dc6 commit a72eaa1

File tree

1 file changed

+10
-14
lines changed
  • drivers/net/wireless/ath/ath9k

1 file changed

+10
-14
lines changed

drivers/net/wireless/ath/ath9k/calib.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,25 @@
1616

1717
#include "hw.h"
1818
#include "hw-ops.h"
19+
#include <linux/sort.h>
1920
#include <linux/export.h>
2021

2122
/* Common calibration code */
2223

24+
static int rcmp_i16(const void *x, const void *y)
25+
{
26+
/* Sort in reverse order. */
27+
return *(int16_t *)y - *(int16_t *)x;
28+
}
2329

2430
static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
2531
{
26-
int16_t nfval;
27-
int16_t sort[ATH9K_NF_CAL_HIST_MAX];
28-
int i, j;
29-
30-
for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++)
31-
sort[i] = nfCalBuffer[i];
32+
int16_t nfcal[ATH9K_NF_CAL_HIST_MAX];
3233

33-
for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) {
34-
for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) {
35-
if (sort[j] > sort[j - 1])
36-
swap(sort[j], sort[j - 1]);
37-
}
38-
}
39-
nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
34+
memcpy(nfcal, nfCalBuffer, sizeof(nfcal));
35+
sort(nfcal, ATH9K_NF_CAL_HIST_MAX, sizeof(int16_t), rcmp_i16, NULL);
4036

41-
return nfval;
37+
return nfcal[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
4238
}
4339

4440
static struct ath_nf_limits *ath9k_hw_get_nf_limits(struct ath_hw *ah,

0 commit comments

Comments
 (0)