staging: rtl8723bs: convert update_attrib path to errno
v2 cover staging: rtl8723bs: convert update_attrib path to errno
Changes in v2:
- Keep braces around the multi-line if statement in update_attrib()
- Split errno conversion and propagation as suggested by Dan Carpenter
- Change update_attrib_sec_info() and update_attrib() return types to int
Hungyu Lin (4):
staging: rtl8723bs: simplify update_attrib_sec_info control flow
staging: rtl8723bs: simplify update_attrib control flow
staging: rtl8723bs: convert update_attrib_sec_info to return errno
staging: rtl8723bs: convert update_attrib to return errno
drivers/staging/rtl8723bs/core/rtw_xmit.c | 55 +++++++++-------------- 1 file changed, 20 insertions(+), 35 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/4 staging: rtl8723bs: simplify update_attrib_sec_info control flow
Replace goto-based error handling with direct returns and remove the temporary res variable.
No functional change.
--- drivers/staging/rtl8723bs/core/rtw_xmit.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/staging/rtl8723bs/core/rtw_xmit.c +5 -12
@@ -507,7 +507,6 @@ static void update_attrib_phy_info(struct adapter *padapter, struct pkt_attrib *static s32 update_attrib_sec_info (struct adapter *padapter,struct pkt_attrib *pattrib,struct sta_info *psta) { -signed int res = _SUCCESS;struct mlme_priv *pmlmepriv = &padapter->mlmepriv;struct security_priv *psecuritypriv = &padapter->securitypriv;signed int bmcast =is_multicast_ether_addr (pattrib->ra);
@@ -519,10 +518,8 @@ static s32 update_attrib_sec_info(struct adapter *padapter, struct pkt_attrib *pif (psta->ieee8021x_blocked) { pattrib->encrypt =0 ; -if ((pattrib->ether_type !=0x888e ) && !check_fwstate (pmlmepriv,WIFI_MP_STATE )) { - res = _FAIL; - goto exit; - } +if ((pattrib->ether_type !=0x888e ) && !check_fwstate (pmlmepriv,WIFI_MP_STATE )) +return _FAIL; }else {GET_ENCRY_ALGO (psecuritypriv, psta, pattrib->encrypt, bmcast);
@@ -560,10 +557,8 @@ static s32 update_attrib_sec_info(struct adapter *padapter, struct pkt_attrib *p pattrib->iv_len =8 ; pattrib->icv_len =4 ; -if (psecuritypriv->busetkipkey == _FAIL) { - res = _FAIL; - goto exit; - } +if (psecuritypriv->busetkipkey == _FAIL) +return _FAIL;if (bmcast)TKIP_IV (pattrib->iv, psta->dot11txpn, pattrib->key_idx);
@@ -601,9 +596,7 @@ static s32 update_attrib_sec_info(struct adapter *padapter, struct pkt_attrib *pelse pattrib->bswenc = false; -exit: - -return res; +return _SUCCESS; }u8 qos_acm (u8 acm_mask,u8 priority)
Signature · 1 line
2.34.1
PATCH v2 2/4 staging: rtl8723bs: simplify update_attrib control flow
In reply to Hungyu LinReplace goto-based error handling with direct returns and remove the temporary res variable.
No functional change.
--- drivers/staging/rtl8723bs/core/rtw_xmit.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/staging/rtl8723bs/core/rtw_xmit.c +7 -15
@@ -664,7 +664,6 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct pstruct sta_priv *pstapriv = &padapter->stapriv;struct mlme_priv *pmlmepriv = &padapter->mlmepriv;struct qos_priv *pqospriv = &pmlmepriv->qospriv; -signed int res = _SUCCESS;int ret;_rtw_open_pktfile (pkt, &pktfile);
@@ -741,19 +740,15 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p psta =rtw_get_bcmc_stainfo (padapter); }else { psta =rtw_get_stainfo (pstapriv, pattrib->ra); -if (!psta) {/* if we cannot get psta => drop the pkt */ - res = _FAIL; - goto exit; - }else if (check_fwstate (pmlmepriv,WIFI_AP_STATE ) && !(psta->state & _FW_LINKED)) { - res = _FAIL; - goto exit; - } +if (!psta)/* if we cannot get psta => drop the pkt */ +return _FAIL; +else if (check_fwstate (pmlmepriv,WIFI_AP_STATE ) && !(psta->state & _FW_LINKED)) +return _FAIL; }if (!psta) {/* if we cannot get psta => drop the pkt */ - res = _FAIL; - goto exit; +return _FAIL; }if (!(psta->state & _FW_LINKED))
@@ -762,8 +757,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct pspin_lock_bh (&psta->lock);if (update_attrib_sec_info (padapter, pattrib, psta) == _FAIL) {spin_unlock_bh (&psta->lock); - res = _FAIL; - goto exit; +return _FAIL; }update_attrib_phy_info (padapter, pattrib, psta);
@@ -799,9 +793,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p }/* pattrib->priority = 5; force to used VI queue, for testing */ - -exit: -return res; +return _SUCCESS; }static s32 xmitframe_addmic (struct adapter *padapter,struct xmit_frame *pxmitframe)
Signature · 1 line
2.34.1
PATCH v2 3/4 staging: rtl8723bs: convert update_attrib_sec_info to return errno
In reply to Hungyu LinConvert update_attrib_sec_info() to return 0 on success and a negative errno on failure.
No functional change intended.
--- drivers/staging/rtl8723bs/core/rtw_xmit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/rtl8723bs/core/rtw_xmit.c +4 -4
@@ -505,7 +505,7 @@ static void update_attrib_phy_info(struct adapter *padapter, struct pkt_attrib * pattrib->retry_ctrl = false; } -static s32 update_attrib_sec_info (struct adapter *padapter,struct pkt_attrib *pattrib,struct sta_info *psta) +static int update_attrib_sec_info (struct adapter *padapter,struct pkt_attrib *pattrib,struct sta_info *psta) {struct mlme_priv *pmlmepriv = &padapter->mlmepriv;struct security_priv *psecuritypriv = &padapter->securitypriv;
@@ -519,7 +519,7 @@ static s32 update_attrib_sec_info(struct adapter *padapter, struct pkt_attrib *p pattrib->encrypt =0 ;if ((pattrib->ether_type !=0x888e ) && !check_fwstate (pmlmepriv,WIFI_MP_STATE )) -return _FAIL; +return -EINVAL ; }else {GET_ENCRY_ALGO (psecuritypriv, psta, pattrib->encrypt, bmcast);
@@ -558,7 +558,7 @@ static s32 update_attrib_sec_info(struct adapter *padapter, struct pkt_attrib *p pattrib->icv_len =4 ;if (psecuritypriv->busetkipkey == _FAIL) -return _FAIL; +return -EINVAL ;if (bmcast)TKIP_IV (pattrib->iv, psta->dot11txpn, pattrib->key_idx);
@@ -596,7 +596,7 @@ static s32 update_attrib_sec_info(struct adapter *padapter, struct pkt_attrib *pelse pattrib->bswenc = false; -return _SUCCESS; +return 0 ; }u8 qos_acm (u8 acm_mask,u8 priority)
Signature · 1 line
2.34.1
Re: [PATCH v2 3/4] staging: rtl8723bs: convert update_attrib_sec_info to return errno
Quoted 15 lines · Hungyu Lin
Convert
update_attrib_sec_info()to return 0 on success and a negative errno on failure.No functional change intended.
Signed-off-by Hungyu Lin <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_xmit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/staging/rtl8723bs/core/rtw_xmit.c +0
-0
drivers/staging/rtl8723bs/core/rtw_xmit.c static void update_attrib_phy_info(struct adapter *padapter, struct pkt_attrib * · line 509
Quoted 6 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +1
-1@@ -505,7 +505,7 @@ static void update_attrib_phy_info(struct adapter *padapter, struct pkt_attrib * pattrib->retry_ctrl = false; } -static s32 update_attrib_sec_info (struct adapter *padapter,struct pkt_attrib *pattrib,struct sta_info *psta) +static int update_attrib_sec_info (struct adapter *padapter,struct pkt_attrib *pattrib,struct sta_info *psta) {
Sorry, I was unclear. You tried to follow my directions and then v2 introduced a bug as a result when actually v1 worked... What I want here is to update the check in the caller but not what it returns.
1 Bad:
if (update_attrib_sec_info() == _FAIL) return _FAIL;
2 Not yet:
ret = update_attrib_sec_info(); if (ret) return ret;
3 Good:
ret = update_attrib_sec_info(); if (ret) return _FAIL;
And then in the next patch change all the return _FAIL sites in the caller. So we'll eventually move to option 2, but in a two step process.
regards,
dan carpenter
PATCH v2 4/4 staging: rtl8723bs: convert update_attrib to return errno
In reply to Hungyu LinConvert update_attrib() to return 0 on success and a negative errno on failure. Update rtw_xmit() to handle the returned error code.
No functional change intended.
--- drivers/staging/rtl8723bs/core/rtw_xmit.c | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/staging/rtl8723bs/core/rtw_xmit.c +12 -12
@@ -654,7 +654,7 @@ static int set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)return 0 ; } -static s32 update_attrib (struct adapter *padapter,struct sk_buff *pkt,struct pkt_attrib *pattrib) +static int update_attrib (struct adapter *padapter,struct sk_buff *pkt,struct pkt_attrib *pattrib) {struct pkt_file pktfile;struct sta_info *psta =NULL ;
@@ -741,23 +741,24 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p }else { psta =rtw_get_stainfo (pstapriv, pattrib->ra);if (!psta)/* if we cannot get psta => drop the pkt */ -return _FAIL; +return -EINVAL ;else if (check_fwstate (pmlmepriv,WIFI_AP_STATE ) && !(psta->state & _FW_LINKED)) -return _FAIL; +return -EINVAL ; }if (!psta) {/* if we cannot get psta => drop the pkt */ -return _FAIL; +return -EINVAL ; }if (!(psta->state & _FW_LINKED)) -return _FAIL; +return -EINVAL ;spin_lock_bh (&psta->lock); -if (update_attrib_sec_info (padapter, pattrib, psta) == _FAIL) { + ret =update_attrib_sec_info (padapter, pattrib, psta); +if (ret) {spin_unlock_bh (&psta->lock); -return _FAIL; +return ret; }update_attrib_phy_info (padapter, pattrib, psta);
@@ -793,7 +794,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p }/* pattrib->priority = 5; force to used VI queue, for testing */ -return _SUCCESS; +return 0 ; }static s32 xmitframe_addmic (struct adapter *padapter,struct xmit_frame *pxmitframe)
@@ -1954,7 +1955,7 @@ s32 rtw_xmit(struct adapter *padapter, struct sk_buff **ppkt)struct xmit_priv *pxmitpriv = &padapter->xmitpriv;struct xmit_frame *pxmitframe =NULL ; -s32 res; +int ret;if (start ==0 ) start = jiffies;
@@ -1967,9 +1968,8 @@ s32 rtw_xmit(struct adapter *padapter, struct sk_buff **ppkt)if (!pxmitframe)return -1 ; - res =update_attrib (padapter, *ppkt, &pxmitframe->attrib); - -if (res != _SUCCESS) { + ret =update_attrib (padapter, *ppkt, &pxmitframe->attrib); +if (ret) {rtw_free_xmitframe (pxmitpriv, pxmitframe);return -1 ; }
Signature · 1 line
2.34.1