lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Mon, 04 Jul 2022 09:32:06 -0700
From:   Joe Perches <joe@...ches.com>
To:     Toke Høiland-Jørgensen <toke@...e.dk>,
        Tan Zhongjun <tanzhongjun@...lpad.com>, kvalo@...nel.org,
        davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
        pabeni@...hat.com
Cc:     linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ath9k: Use swap() instead of open coding it

On Mon, 2022-07-04 at 16:55 +0200, Toke Høiland-Jørgensen wrote:
> "Tan Zhongjun" <tanzhongjun@...lpad.com> writes:
> 
> > Use swap() instead of open coding it
> > 
> > Signed-off-by: Tan Zhongjun <tanzhongjun@...lpad.com>
> 
> Please don't send HTML email, the mailing lists will drop that. Also, an
> identical patch was submitted back in February and an issue was pointed
> out which your patch also suffers from:
> 
> https://lore.kernel.org/r/a2400dd73f6ea8672bb6e50124cc3041c0c43d6d.1644838854.git.yang.guang5@zte.com.cn

Perhaps instead use sort instead of a bubble sort.

Something like:
---
 drivers/net/wireless/ath/ath9k/calib.c | 35 ++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 0422a33395b77..4e298925049e8 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -17,29 +17,32 @@
 #include "hw.h"
 #include "hw-ops.h"
 #include <linux/export.h>
+#include <linux/sort.h>
 
 /* Common calibration code */
 
+static int cmp_int16_t(const void *a, const void *b)
+{
+	int16_t a1 = *(int16_t *)a;
+	int16_t b1 = *(int16_t *)b;
+
+	if (a1 < b1)
+		return -1;
+	if (a1 > b1)
+		return 1;
+	return 0;
+}
 
 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];
-
-	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]) {
-				nfval = sort[j];
-				sort[j] = sort[j - 1];
-				sort[j - 1] = nfval;
-			}
-		}
-	}
-	nfval = sort[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
+	int16_t sorted[ATH9K_NF_CAL_HIST_MAX];
+
+	memcpy(sorted, nfCalBuffer, sizeof(int16_t) * ATH9K_NF_CAL_HIST_MAX);
+
+	sort(sorted, ARRAY_SIZE(sorted), sizeof(int16_t), cmp_int16_t, NULL);
+
+	nfval = sorted[(ATH9K_NF_CAL_HIST_MAX - 1) >> 1];
 
 	return nfval;
 }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ