]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: ath9k: cleanup ath9k_hw_get_nf_hist_mid()
authorDmitry Antipov <dmantipov@yandex.ru>
Thu, 9 Jan 2025 08:07:03 +0000 (11:07 +0300)
committerJeff Johnson <jeff.johnson@oss.qualcomm.com>
Fri, 10 Jan 2025 22:42:51 +0000 (14:42 -0800)
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 <dmantipov@yandex.ru>
Acked-by: Toke Høiland-Jørgensen <toke@toke.dk>
Link: https://patch.msgid.link/20250109080703.106692-1-dmantipov@yandex.ru
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
drivers/net/wireless/ath/ath9k/calib.c

index 4b331c85509cf6148b2b2d9415b2eaf9b393d40d..b4ab85bd7895a188eb98fb6cd3a10c5976e99e40 100644 (file)
 
 #include "hw.h"
 #include "hw-ops.h"
+#include <linux/sort.h>
 #include <linux/export.h>
 
 /* Common calibration code */
 
+static int rcmp_i16(const void *x, const void *y)
+{
+       /* Sort in reverse order. */
+       return *(int16_t *)y - *(int16_t *)x;
+}
 
 static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
 {
-       int16_t nfval;
-       int16_t sort[ATH9K_NF_CAL_HIST_MAX];
-       int i, j;
-
-       for (i = 0; i < ATH9K_NF_CAL_HIST_MAX; i++)
-               sort[i] = nfCalBuffer[i];
+       int16_t nfcal[ATH9K_NF_CAL_HIST_MAX];
 
-       for (i = 0; i < ATH9K_NF_CAL_HIST_MAX - 1; i++) {
-               for (j = 1; j < ATH9K_NF_CAL_HIST_MAX - i; j++) {
-                       if (sort[j] > sort[j - 1])
-                               swap(sort[j], sort[j - 1]);
-               }
-       }
-       nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
+       memcpy(nfcal, nfCalBuffer, sizeof(nfcal));
+       sort(nfcal, ATH9K_NF_CAL_HIST_MAX, sizeof(int16_t), rcmp_i16, NULL);
 
-       return nfval;
+       return nfcal[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
 }
 
 static struct ath_nf_limits *ath9k_hw_get_nf_limits(struct ath_hw *ah,