From: Joe Perches <joe@perches.com>
To: "Toke Høiland-Jørgensen" <toke@toke.dk>,
"Tan Zhongjun" <tanzhongjun@coolpad.com>,
kvalo@kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com
Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ath9k: Use swap() instead of open coding it
Date: Mon, 04 Jul 2022 09:32:06 -0700 [thread overview]
Message-ID: <c3755af8c14da95ff9cf45f94da7648f3e58e8ae.camel@perches.com> (raw)
In-Reply-To: <87fsjh7wr0.fsf@toke.dk>
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;
}
prev parent reply other threads:[~2022-07-04 16:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c3755af8c14da95ff9cf45f94da7648f3e58e8ae.camel@perches.com \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kvalo@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tanzhongjun@coolpad.com \
--cc=toke@toke.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).