ath5k: fix WARNING opportunity for swap.
PATCH 1/1 ath5k: fix WARNING opportunity for swap.
coccinielle reported the following:
./drivers/net/wireless/ath/ath5k/phy.c:1573:25-26: WARNING opportunity for swap()
--- drivers/net/wireless/ath/ath5k/phy.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/wireless/ath/ath5k/phy.c +1 -4
@@ -1562,16 +1562,13 @@ static s16 ath5k_hw_get_median_noise_floor(struct ath5k_hw *ah) {s16 sort[ATH5K_NF_CAL_HIST_MAX ]; -s16 tmp;int i, j;memcpy (sort, ah->ah_nfcal_hist.nfval,sizeof (sort));for (i =0 ; i <ATH5K_NF_CAL_HIST_MAX -1 ; i++) {for (j =1 ; j <ATH5K_NF_CAL_HIST_MAX - i; j++) {if (sort[j] > sort[j -1 ]) { - tmp = sort[j]; - sort[j] = sort[j -1 ]; - sort[j -1 ] = tmp; +swap (sort[j], sort[j -1 ]); } } }
Signature · 1 line
2.34.1
Jiri Slaby
maintainerQuoted 2 lines · Mahmoud Maatuq
coccinielle reported the following:
./drivers/net/wireless/ath/ath5k/phy.c:1573:25-26: WARNING opportunity forswap()
OK, once again:
https://lore.kernel.org/all/[email protected]/
Quoted 27 lines
Signed-off-by Mahmoud Maatuq <[email protected]>--- drivers/net/wireless/ath/ath5k/phy.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/net/wireless/ath/ath5k/phy.c +1
-4@@ -1562,16 +1562,13 @@ static s16 ath5k_hw_get_median_noise_floor(struct ath5k_hw *ah) {s16 sort[ATH5K_NF_CAL_HIST_MAX ]; -s16 tmp;int i, j;memcpy (sort, ah->ah_nfcal_hist.nfval,sizeof (sort));for (i =0 ; i <ATH5K_NF_CAL_HIST_MAX -1 ; i++) {for (j =1 ; j <ATH5K_NF_CAL_HIST_MAX - i; j++) {if (sort[j] > sort[j -1 ]) { - tmp = sort[j]; - sort[j] = sort[j -1 ]; - sort[j -1 ] = tmp; +swap (sort[j], sort[j -1 ]); } } }
Signature · 7 lines
js suse labs _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 7 lines · Jiri Slaby
Quoted 2 lines · Mahmoud Maatuq
coccinielle reported the following:
./drivers/net/wireless/ath/ath5k/phy.c:1573:25-26: WARNING opportunity forswap()OK, once again:
https://lore.kernel.org/all/[email protected]/
I had a look at the commit history, to see why the original developer didn't use sort() function, and name the array variable sort but found nothing.
I have some doubts that he might did that intentionally, so not to call sort() function for such small array and avoid the cost of context switching.
Quoted 18 lines
Quoted 18 lines
Signed-off-by Mahmoud Maatuq <[email protected]>--- drivers/net/wireless/ath/ath5k/phy.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/net/wireless/ath/ath5k/phy.c +0
-1@@ -1562,16 +1562,13 @@ static s16 ath5k_hw_get_median_noise_floor(struct ath5k_hw *ah) {s16 sort[ATH5K_NF_CAL_HIST_MAX ]; -s16 tmp;int i, j;memcpy (sort, ah->ah_nfcal_hist.nfval,sizeof (sort));for (i =0 ; i <ATH5K_NF_CAL_HIST_MAX -1 ; i++) {for (j =1 ; j <ATH5K_NF_CAL_HIST_MAX - i; j++) {
Quoted 12 lines
Quoted 8 lines
drivers/net/wireless/ath/ath5k/phy.c +1
-3if (sort[j] > sort[j -1 ]) { - tmp = sort[j]; - sort[j] = sort[j -1 ]; - sort[j -1 ] = tmp; +swap (sort[j], sort[j -1 ]); } } }Signature · 2 lines
js suse labs
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Jiri Slaby
maintainerQuoted 11 lines · Mahmoud Matook
Quoted 7 lines · Jiri Slaby
Quoted 2 lines · Mahmoud Maatuq
coccinielle reported the following:
./drivers/net/wireless/ath/ath5k/phy.c:1573:25-26: WARNING opportunity forswap()OK, once again:
https://lore.kernel.org/all/[email protected]/
Quoted 5 lines
I had a look at the commit history, to see why the original developer didn't use
sort()function, and name the array variable sort but found nothing.
I have some doubts that he might did that intentionally, so not to callsort()function for such small array
It happens once in 10 s and in a work. No worries about that.
Quoted 1 line
and avoid the cost of context switching.
What context switching?
Quoted 25 lines
Quoted 25 lines
Quoted 21 lines
drivers/net/wireless/ath/ath5k/phy.c +1
-4@@ -1562,16 +1562,13 @@ static s16 ath5k_hw_get_median_noise_floor(struct ath5k_hw *ah) {s16 sort[ATH5K_NF_CAL_HIST_MAX ]; -s16 tmp;int i, j;memcpy (sort, ah->ah_nfcal_hist.nfval,sizeof (sort));for (i =0 ; i <ATH5K_NF_CAL_HIST_MAX -1 ; i++) {for (j =1 ; j <ATH5K_NF_CAL_HIST_MAX - i; j++) {if (sort[j] > sort[j -1 ]) { - tmp = sort[j]; - sort[j] = sort[j -1 ]; - sort[j -1 ] = tmp; +swap (sort[j], sort[j -1 ]); } } }Signature · 2 lines
js suse labs
Signature · 2 lines
js suse labs
Quoted 11 lines · Mahmoud Matook
Quoted 11 lines · Jiri Slaby
Quoted 8 lines
Quoted 6 lines · Mahmoud Maatuq
coccinielle reported the following:
./drivers/net/wireless/ath/ath5k/phy.c:1573:25-26: WARNING opportunity forswap()OK, once again:
https://lore.kernel.org/all/[email protected]/
Quoted 7 lines
Quoted 5 lines
I had a look at the commit history, to see why the original developer didn't use
sort()function, and name the array variable sort but found nothing.
I have some doubts that he might did that intentionally, so not to callsort()function for such small arrayIt happens once in 10 s and in a work. No worries about that.
if it's the case so make sense to use sort(). but should I send the modifications on the same thread? as the subject needs to be changed.
ex: repalce double loop with sort function
replace bubble sort with heap sort.
Quoted 3 lines
Quoted 1 line
and avoid the cost of context switching.
What context switching?
I used the wrong expression, I meant function call overhead e.g store/load registers.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
drivers/net/wireless/ath/ath5k/phy.c +0
-4@@ -1562,16 +1562,13 @@ static s16 ath5k_hw_get_median_noise_floor(struct ath5k_hw *ah) {s16 sort[ATH5K_NF_CAL_HIST_MAX ]; -s16 tmp;int i, j;memcpy (sort, ah->ah_nfcal_hist.nfval,sizeof (sort));for (i =0 ; i <ATH5K_NF_CAL_HIST_MAX -1 ; i++) {for (j =1 ; j <ATH5K_NF_CAL_HIST_MAX - i; j++) {if (sort[j] > sort[j -1 ]) { - tmp = sort[j]; - sort[j] = sort[j -1 ]; - sort[j -1 ] = tmp;
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
drivers/net/wireless/ath/ath5k/phy.c +1
-0+swap (sort[j], sort[j -1 ]); } } }Signature · 2 lines
js suse labsSignature · 2 lines
js suse labs
_______________________________________________
Linux-kernel-mentees mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees