netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] ath9k: Use swap() instead of open coding it
       [not found] <20220704133205.1294-1-tanzhongjun@coolpad.com>
@ 2022-07-04 14:55 ` Toke Høiland-Jørgensen
  2022-07-04 16:32   ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Toke Høiland-Jørgensen @ 2022-07-04 14:55 UTC (permalink / raw)
  To: Tan Zhongjun, kvalo, davem, edumazet, kuba, pabeni
  Cc: linux-wireless, netdev, linux-kernel, Tan Zhongjun

"Tan Zhongjun" <tanzhongjun@coolpad.com> writes:

> Use swap() instead of open coding it
>
> Signed-off-by: Tan Zhongjun <tanzhongjun@coolpad.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

-Toke

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ath9k: Use swap() instead of open coding it
  2022-07-04 14:55 ` [PATCH] ath9k: Use swap() instead of open coding it Toke Høiland-Jørgensen
@ 2022-07-04 16:32   ` Joe Perches
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2022-07-04 16:32 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen, Tan Zhongjun, kvalo, davem,
	edumazet, kuba, pabeni
  Cc: linux-wireless, netdev, linux-kernel

On Mon, 2022-07-04 at 16:55 +0200, Toke Høiland-Jørgensen wrote:
> "Tan Zhongjun" <tanzhongjun@coolpad.com> writes:
> 
> > Use swap() instead of open coding it
> > 
> > Signed-off-by: Tan Zhongjun <tanzhongjun@coolpad.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;
 }


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-04 16:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20220704133205.1294-1-tanzhongjun@coolpad.com>
2022-07-04 14:55 ` [PATCH] ath9k: Use swap() instead of open coding it Toke Høiland-Jørgensen
2022-07-04 16:32   ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).