Skip to contentSkip to conversation

staging: r8188eu: convert three functions to bool

PATCH In review Michael Straube 5 participants 7 messages Nov 5, 2022 – Nov 6, 2022 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: r8188eu: convert three functions to bool

The functions

is_client_associated_to_ap()
is_client_associated_to_ibss()
is_IBSS_empty()

return boolean values. Convert their return type to bool and replace _FAIL, which is defined as 0, with false. Another step to get rid of _SUCCESS / _FAIL.

---
 drivers/staging/r8188eu/core/rtw_wlan_util.c   | 18 +++++++++---------
 drivers/staging/r8188eu/include/rtw_mlme_ext.h |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/staging/r8188eu/core/rtw_wlan_util.c +9 -9
index e50631848cab..c95438a12b59 100644
@@ -331,35 +331,35 @@ u16 get_beacon_interval(struct wlan_bssid_ex *bss)
 	return le16_to_cpu(val);
 }
 
-int is_client_associated_to_ap(struct adapter *padapter)
+bool is_client_associated_to_ap(struct adapter *padapter)
 {
 	struct mlme_ext_priv	*pmlmeext;
 	struct mlme_ext_info	*pmlmeinfo;
 
 	if (!padapter)
-		return _FAIL;
+		return false;
 
 	pmlmeext = &padapter->mlmeextpriv;
 	pmlmeinfo = &pmlmeext->mlmext_info;
 
 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
 		return true;
-	else
-		return _FAIL;
+
+	return false;
 }
 
-int is_client_associated_to_ibss(struct adapter *padapter)
+bool is_client_associated_to_ibss(struct adapter *padapter)
 {
 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
 	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
 
 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
 		return true;
-	else
-		return _FAIL;
+
+	return false;
 }
 
-int is_IBSS_empty(struct adapter *padapter)
+bool is_IBSS_empty(struct adapter *padapter)
 {
 	unsigned int i;
 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
@@ -367,7 +367,7 @@ int is_IBSS_empty(struct adapter *padapter)
 
 	for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
 		if (pmlmeinfo->FW_sta_info[i].status == 1)
-			return _FAIL;
+			return false;
 	}
 	return true;
 }
drivers/staging/r8188eu/include/rtw_mlme_ext.h +3 -3
index e234a3b9af6f..7652e72a03f4 100644
@@ -432,9 +432,9 @@ void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
 u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork);
 u16 get_beacon_interval(struct wlan_bssid_ex *bss);
 
-int is_client_associated_to_ap(struct adapter *padapter);
-int is_client_associated_to_ibss(struct adapter *padapter);
-int is_IBSS_empty(struct adapter *padapter);
+bool is_client_associated_to_ap(struct adapter *padapter);
+bool is_client_associated_to_ibss(struct adapter *padapter);
+bool is_IBSS_empty(struct adapter *padapter);
 
 unsigned char check_assoc_AP(u8 *pframe, uint len);
 
Signature · 1 line
2.38.0
#1 lore raw
Quoted 93 lines · Michael Straube

The functions

is_client_associated_to_ap()
is_client_associated_to_ibss()
is_IBSS_empty()

return boolean values. Convert their return type to bool and replace _FAIL, which is defined as 0, with false. Another step to get rid of _SUCCESS / _FAIL.

---
 drivers/staging/r8188eu/core/rtw_wlan_util.c   | 18 +++++++++---------
 drivers/staging/r8188eu/include/rtw_mlme_ext.h |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/staging/r8188eu/core/rtw_wlan_util.c +9 -9
index e50631848cab..c95438a12b59 100644
@@ -331,35 +331,35 @@ u16 get_beacon_interval(struct wlan_bssid_ex *bss)
 	return le16_to_cpu(val);
 }
 
-int is_client_associated_to_ap(struct adapter *padapter)
+bool is_client_associated_to_ap(struct adapter *padapter)
 {
 	struct mlme_ext_priv	*pmlmeext;
 	struct mlme_ext_info	*pmlmeinfo;
 
 	if (!padapter)
-		return _FAIL;
+		return false;
 
 	pmlmeext = &padapter->mlmeextpriv;
 	pmlmeinfo = &pmlmeext->mlmext_info;
 
 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
 		return true;
-	else
-		return _FAIL;
+
+	return false;
 }
 
-int is_client_associated_to_ibss(struct adapter *padapter)
+bool is_client_associated_to_ibss(struct adapter *padapter)
 {
 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
 	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
 
 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
 		return true;
-	else
-		return _FAIL;
+
+	return false;
 }
 
-int is_IBSS_empty(struct adapter *padapter)
+bool is_IBSS_empty(struct adapter *padapter)
 {
 	unsigned int i;
 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
@@ -367,7 +367,7 @@ int is_IBSS_empty(struct adapter *padapter)
 
 	for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
 		if (pmlmeinfo->FW_sta_info[i].status == 1)
-			return _FAIL;
+			return false;
 	}
 	return true;
 }
drivers/staging/r8188eu/include/rtw_mlme_ext.h +3 -3
index e234a3b9af6f..7652e72a03f4 100644
@@ -432,9 +432,9 @@ void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
 u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork);
 u16 get_beacon_interval(struct wlan_bssid_ex *bss);
 
-int is_client_associated_to_ap(struct adapter *padapter);
-int is_client_associated_to_ibss(struct adapter *padapter);
-int is_IBSS_empty(struct adapter *padapter);
+bool is_client_associated_to_ap(struct adapter *padapter);
+bool is_client_associated_to_ibss(struct adapter *padapter);
+bool is_IBSS_empty(struct adapter *padapter);
 
 unsigned char check_assoc_AP(u8 *pframe, uint len);
 
Signature · 1 line
2.38.0

Hi Michael,

Thanks for the patch. Just my personal opinion, but I would prefer to keep the return type as int, and have 0 for success and then _FAIL replaced with an appropriate error code depending on the circumstance, (e.g. -ENOMEM). This is generally the convention elsewhere in the kernel. Others may not agree though.

All the best,
Phil

maintainer
#2 lore raw
Quoted 97 lines · Phillip Potter
Quoted 93 lines · Michael Straube

The functions

is_client_associated_to_ap()
is_client_associated_to_ibss()
is_IBSS_empty()

return boolean values. Convert their return type to bool and replace _FAIL, which is defined as 0, with false. Another step to get rid of _SUCCESS / _FAIL.

---
 drivers/staging/r8188eu/core/rtw_wlan_util.c   | 18 +++++++++---------
 drivers/staging/r8188eu/include/rtw_mlme_ext.h |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/staging/r8188eu/core/rtw_wlan_util.c +9 -9
index e50631848cab..c95438a12b59 100644
@@ -331,35 +331,35 @@ u16 get_beacon_interval(struct wlan_bssid_ex *bss)
 	return le16_to_cpu(val);
 }
 
-int is_client_associated_to_ap(struct adapter *padapter)
+bool is_client_associated_to_ap(struct adapter *padapter)
 {
 	struct mlme_ext_priv	*pmlmeext;
 	struct mlme_ext_info	*pmlmeinfo;
 
 	if (!padapter)
-		return _FAIL;
+		return false;
 
 	pmlmeext = &padapter->mlmeextpriv;
 	pmlmeinfo = &pmlmeext->mlmext_info;
 
 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
 		return true;
-	else
-		return _FAIL;
+
+	return false;
 }
 
-int is_client_associated_to_ibss(struct adapter *padapter)
+bool is_client_associated_to_ibss(struct adapter *padapter)
 {
 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
 	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
 
 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
 		return true;
-	else
-		return _FAIL;
+
+	return false;
 }
 
-int is_IBSS_empty(struct adapter *padapter)
+bool is_IBSS_empty(struct adapter *padapter)
 {
 	unsigned int i;
 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
@@ -367,7 +367,7 @@ int is_IBSS_empty(struct adapter *padapter)
 
 	for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
 		if (pmlmeinfo->FW_sta_info[i].status == 1)
-			return _FAIL;
+			return false;
 	}
 	return true;
 }
drivers/staging/r8188eu/include/rtw_mlme_ext.h +3 -3
index e234a3b9af6f..7652e72a03f4 100644
@@ -432,9 +432,9 @@ void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
 u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork);
 u16 get_beacon_interval(struct wlan_bssid_ex *bss);
 
-int is_client_associated_to_ap(struct adapter *padapter);
-int is_client_associated_to_ibss(struct adapter *padapter);
-int is_IBSS_empty(struct adapter *padapter);
+bool is_client_associated_to_ap(struct adapter *padapter);
+bool is_client_associated_to_ibss(struct adapter *padapter);
+bool is_IBSS_empty(struct adapter *padapter);
 
 unsigned char check_assoc_AP(u8 *pframe, uint len);
 
Signature · 1 line
2.38.0

Hi Michael,

Quoted 5 lines

Thanks for the patch. Just my personal opinion, but I would prefer to keep the return type as int, and have 0 for success and then _FAIL replaced with an appropriate error code depending on the circumstance, (e.g. -ENOMEM). This is generally the convention elsewhere in the kernel. Others may not agree though.

For functions that are just returning true/false like this (and the function name is something like "is_foo()"), a boolean type is fine and makes more sense as you will only check it in an "if ()" statement block like how these are being used.

However, these function names are horrible for being in the global namespace, but that's a totally different issue that can be fixed up in a later patch.

thanks,

greg k-h

#3 lore raw
Quoted 4 lines · Greg KH

However, these function names are horrible for being in the global namespace, but that's a totally different issue that can be fixed up in a later patch.

I'll send a patch to address that after this patch is accepted.

Thanks,
Michael

Tested-by on v1 1/1
#4 lore raw
In reply to Michael Straube
Quoted 80 lines · Michael Straube

The functions

is_client_associated_to_ap()
is_client_associated_to_ibss()
is_IBSS_empty()

return boolean values. Convert their return type to bool and replace _FAIL, which is defined as 0, with false. Another step to get rid of _SUCCESS / _FAIL.

---
  drivers/staging/r8188eu/core/rtw_wlan_util.c   | 18 +++++++++---------
  drivers/staging/r8188eu/include/rtw_mlme_ext.h |  6 +++---
  2 files changed, 12 insertions(+), 12 deletions(-)
drivers/staging/r8188eu/core/rtw_wlan_util.c +9 -9
index e50631848cab..c95438a12b59 100644
@@ -331,35 +331,35 @@ u16 get_beacon_interval(struct wlan_bssid_ex *bss)
  	return le16_to_cpu(val);
  }
 
-int is_client_associated_to_ap(struct adapter *padapter)
+bool is_client_associated_to_ap(struct adapter *padapter)
  {
  	struct mlme_ext_priv	*pmlmeext;
  	struct mlme_ext_info	*pmlmeinfo;
 
  	if (!padapter)
-		return _FAIL;
+		return false;
 
  	pmlmeext = &padapter->mlmeextpriv;
  	pmlmeinfo = &pmlmeext->mlmext_info;
 
  	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
  		return true;
-	else
-		return _FAIL;
+
+	return false;
  }
 
-int is_client_associated_to_ibss(struct adapter *padapter)
+bool is_client_associated_to_ibss(struct adapter *padapter)
  {
  	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
  	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
 
  	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
  		return true;
-	else
-		return _FAIL;
+
+	return false;
  }
 
-int is_IBSS_empty(struct adapter *padapter)
+bool is_IBSS_empty(struct adapter *padapter)
  {
  	unsigned int i;
  	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
@@ -367,7 +367,7 @@ int is_IBSS_empty(struct adapter *padapter)
 
  	for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
  		if (pmlmeinfo->FW_sta_info[i].status == 1)
-			return _FAIL;
+			return false;
  	}
  	return true;
  }
drivers/staging/r8188eu/include/rtw_mlme_ext.h +0 -0
index e234a3b9af6f..7652e72a03f4 100644
@@ -432,9 +432,9 @@ void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
  u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork);
  u16 get_beacon_interval(struct wlan_bssid_ex *bss);

drivers/staging/r8188eu/include/rtw_mlme_ext.h void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src, · line 440

Quoted 10 lines
drivers/staging/r8188eu/include/rtw_mlme_ext.h +3 -3
 
-int is_client_associated_to_ap(struct adapter *padapter);
-int is_client_associated_to_ibss(struct adapter *padapter);
-int is_IBSS_empty(struct adapter *padapter);
+bool is_client_associated_to_ap(struct adapter *padapter);
+bool is_client_associated_to_ibss(struct adapter *padapter);
+bool is_IBSS_empty(struct adapter *padapter);
 
  unsigned char check_assoc_AP(u8 *pframe, uint len);
 
#5 lore raw
In reply to Michael Straube
Quoted 9 lines · Michael Straube

The functions

is_client_associated_to_ap()
is_client_associated_to_ibss()
is_IBSS_empty()

return boolean values. Convert their return type to bool and replace _FAIL, which is defined as 0, with false. Another step to get rid of _SUCCESS / _FAIL.

yay.

drivers/staging/r8188eu/core/rtw_wlan_util.c

Quoted 1 line
drivers/staging/r8188eu/core/rtw_wlan_util.c +0 -0

[]

Quoted 8 lines
drivers/staging/r8188eu/core/rtw_wlan_util.c +2 -1
+bool is_client_associated_to_ap(struct adapter *padapter)
 {
 	struct mlme_ext_priv	*pmlmeext;
 	struct mlme_ext_info	*pmlmeinfo;
 
 	if (!padapter)
-		return _FAIL;
+		return false;

drivers/staging/r8188eu/core/rtw_wlan_util.c u16 get_beacon_interval(struct wlan_bssid_ex *bss) · line 348

Quoted 10 lines
drivers/staging/r8188eu/core/rtw_wlan_util.c +2 -2
 
 	pmlmeext = &padapter->mlmeextpriv;
 	pmlmeinfo = &pmlmeext->mlmext_info;
 
 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
 		return true;
-	else
-		return _FAIL;
+
+	return false;

instead of

	if (foo)
		return true;
	return false;

These could be:

	return (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) &&
	       ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE);

drivers/staging/r8188eu/core/rtw_wlan_util.c u16 get_beacon_interval(struct wlan_bssid_ex *bss) · line 359

Quoted 11 lines
drivers/staging/r8188eu/core/rtw_wlan_util.c +3 -2
+bool is_client_associated_to_ibss(struct adapter *padapter)
 {
 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
 	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
 
 	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
 		return true;
-	else
-		return _FAIL;
+
+	return false;

and

	return (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) &&
	       ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE);
#6 lore raw
Quoted 59 lines · Joe Perches
Quoted 9 lines · Michael Straube

The functions

is_client_associated_to_ap()
is_client_associated_to_ibss()
is_IBSS_empty()

return boolean values. Convert their return type to bool and replace _FAIL, which is defined as 0, with false. Another step to get rid of _SUCCESS / _FAIL.

yay.

drivers/staging/r8188eu/core/rtw_wlan_util.c

Quoted 1 line
drivers/staging/r8188eu/core/rtw_wlan_util.c +0 -0

[]

Quoted 8 lines
drivers/staging/r8188eu/core/rtw_wlan_util.c +2 -1
+bool is_client_associated_to_ap(struct adapter *padapter)
  {
  	struct mlme_ext_priv	*pmlmeext;
  	struct mlme_ext_info	*pmlmeinfo;
 
  	if (!padapter)
-		return _FAIL;
+		return false;

drivers/staging/r8188eu/core/rtw_wlan_util.c u16 get_beacon_interval(struct wlan_bssid_ex *bss) · line 348

Quoted 10 lines
drivers/staging/r8188eu/core/rtw_wlan_util.c +2 -2
 
  	pmlmeext = &padapter->mlmeextpriv;
  	pmlmeinfo = &pmlmeext->mlmext_info;
 
  	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE))
  		return true;
-	else
-		return _FAIL;
+
+	return false;

instead of

	if (foo)
		return true;
	return false;

These could be:

	return (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) &&
	       ((pmlmeinfo->state & 0x03) == WIFI_FW_STATION_STATE);

drivers/staging/r8188eu/core/rtw_wlan_util.c u16 get_beacon_interval(struct wlan_bssid_ex *bss) · line 359

Quoted 11 lines
drivers/staging/r8188eu/core/rtw_wlan_util.c +3 -2
+bool is_client_associated_to_ibss(struct adapter *padapter)
  {
  	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
  	struct mlme_ext_info	*pmlmeinfo = &pmlmeext->mlmext_info;
 
  	if ((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE))
  		return true;
-	else
-		return _FAIL;
+
+	return false;

and

Quoted 4 lines
	return (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) &&
	       ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE);

I'll keep this in mind for a future patch.

Thanks,
Michael