Skip to contentSkip to conversation

ath9k: make array voice_priority static const

PATCH In review Colin Ian King 5 participants 5 messages Feb 22, 2022 – Mar 9, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ath9k: make array voice_priority static const

Don't populate the read-only array voice_priority on the stack but instead make it static const. Also makes the object code a little smaller.

---
 drivers/net/wireless/ath/ath9k/mci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/mci.c +1 -1
index 39d46c203f6b..5e0ae7e6412f 100644
@@ -43,7 +43,7 @@ static bool ath_mci_add_profile(struct ath_common *common,
 				struct ath_mci_profile_info *info)
 {
 	struct ath_mci_profile_info *entry;
-	u8 voice_priority[] = { 110, 110, 110, 112, 110, 110, 114, 116, 118 };
+	static const u8 voice_priority[] = { 110, 110, 110, 112, 110, 110, 114, 116, 118 };
 
 	if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) &&
 	    (info->type == MCI_GPM_COEX_PROFILE_VOICE))
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Colin Ian King

Don't populate the read-only array voice_priority on the stack but instead make it static const. Also makes the object code a little smaller.

---
  drivers/net/wireless/ath/ath9k/mci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/mci.c +0 -0
index 39d46c203f6b..5e0ae7e6412f 100644

drivers/net/wireless/ath/ath9k/mci.c static bool ath_mci_add_profile(struct ath_common *common, · line 49

Quoted 8 lines
drivers/net/wireless/ath/ath9k/mci.c +1 -1
@@ -43,7 +43,7 @@ static bool ath_mci_add_profile(struct ath_common *common,
  				struct ath_mci_profile_info *info)
  {
  	struct ath_mci_profile_info *entry;
-	u8 voice_priority[] = { 110, 110, 110, 112, 110, 110, 114, 116, 118 };
+	static const u8 voice_priority[] = { 110, 110, 110, 112, 110, 110, 114, 116, 118 };
 
  	if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) &&
  	    (info->type == MCI_GPM_COEX_PROFILE_VOICE))

An additional cleanup that could be performed in that function:

		if (info->voice_type < sizeof(voice_priority))

replace sizeof() with ARRAY_SIZE() so that it works correctly if the base type is ever changed from u8

#2 lore raw
Quoted 25 lines · Jeff Johnson
Quoted 14 lines · Colin Ian King

Don't populate the read-only array voice_priority on the stack but instead make it static const. Also makes the object code a little smaller.

---
  drivers/net/wireless/ath/ath9k/mci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/mci.c +0 -0
index 39d46c203f6b..5e0ae7e6412f 100644

drivers/net/wireless/ath/ath9k/mci.c static bool ath_mci_add_profile(struct ath_common *common, · line 48

Quoted 7 lines
drivers/net/wireless/ath/ath9k/mci.c +1 -1
@@ -43,7 +43,7 @@ static bool ath_mci_add_profile(struct ath_common *common,
  				struct ath_mci_profile_info *info)
  {
  	struct ath_mci_profile_info *entry;
-	u8 voice_priority[] = { 110, 110, 110, 112, 110, 110, 114, 116, 118 };
+	static const u8 voice_priority[] = { 110, 110, 110, 112, 110, 110, 114, 116, 118 };
  	if ((mci->num_sco == ATH_MCI_MAX_SCO_PROFILE) &&
  	    (info->type == MCI_GPM_COEX_PROFILE_VOICE))
Quoted 6 lines

An additional cleanup that could be performed in that function:

		if (info->voice_type < sizeof(voice_priority))

replace sizeof() with ARRAY_SIZE() so that it works correctly if the base type is ever changed from u8

You're right that ARRAY_SIZE() is better style but we have a bunch of static analysis to catch the bug if someone changes the type to int or whatever.

regards,
dan carpenter

#4 lore raw
In reply to Colin Ian King
Quoted 8 lines · Colin Ian King

Don't populate the read-only array voice_priority on the stack but instead make it static const. Also makes the object code a little smaller.

Patch applied to ath-next branch of ath.git, thanks.

44d445c02388 ath9k: make array voice_priority static const

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches