staging: rtl8723bs: convert xmit init path to standard error codes
PATCH v3 1/1 staging: rtl8723bs: convert xmit init path to standard error codes
Replace the use of _SUCCESS/_FAIL return values with standard kernel return conventions (0 on success, negative errno on failure) in the xmit initialization path.
Specifically:
- rtw_os_xmit_resource_alloc() now returns 0 or -ENOMEM
- rtw_alloc_hwxmits() now returns 0 or -ENOMEM
- _rtw_init_xmit_priv() updated to propagate error codes and use direct truth checks instead of comparing with _FAIL
- caller in os_intfs.c updated accordingly
This improves error propagation and aligns the driver with kernel coding style.
---
v3:
- Rebase onto latest staging-next to resolve conflicts. v2:
- Rework xmit init path to remove _SUCCESS/_FAIL usage
- Convert allocation helpers to return standard error codes
- Update caller to use direct failure checks
- Address review feedback from Ethan Tidmore
--- drivers/staging/rtl8723bs/core/rtw_xmit.c | 32 +++++++++---------- drivers/staging/rtl8723bs/os_dep/os_intfs.c | 2 +- drivers/staging/rtl8723bs/os_dep/xmit_linux.c | 4 +-- 3 files changed, 19 insertions(+), 19 deletions(-)
drivers/staging/rtl8723bs/core/rtw_xmit.c +16 -16
@@ -38,7 +38,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)int i;struct xmit_buf *pxmitbuf;struct xmit_frame *pxframe; -signed int res = _SUCCESS; +signed int res =0 ;spin_lock_init (&pxmitpriv->lock);spin_lock_init (&pxmitpriv->lock_sctx);
@@ -75,7 +75,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)if (!pxmitpriv->pallocated_frame_buf) { pxmitpriv->pxmit_frame_buf =NULL ; - res = _FAIL; + res = -ENOMEM ; goto exit; } pxmitpriv->pxmit_frame_buf = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(pxmitpriv->pallocated_frame_buf),4 );
@@ -112,7 +112,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) pxmitpriv->pallocated_xmitbuf =vzalloc (NR_XMITBUFF *sizeof (struct xmit_buf ) +4 );if (!pxmitpriv->pallocated_xmitbuf) { - res = _FAIL; + res = -ENOMEM ; goto exit; }
@@ -129,10 +129,12 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)/* Tx buf allocation may fail sometimes, so sleep and retry. */ res =rtw_os_xmit_resource_alloc (padapter, pxmitbuf, (MAX_XMITBUF_SZ +XMITBUF_ALIGN_SZ ), true); -if (res == _FAIL) { + +if (res) {fsleep (10 *USEC_PER_MSEC ); + res =rtw_os_xmit_resource_alloc (padapter, pxmitbuf, (MAX_XMITBUF_SZ +XMITBUF_ALIGN_SZ ), true); -if (res == _FAIL) +if (res) goto exit; }
@@ -162,7 +164,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)if (!pxmitpriv->xframe_ext_alloc_addr) { pxmitpriv->xframe_ext =NULL ; - res = _FAIL; + res = -ENOMEM ; goto exit; } pxmitpriv->xframe_ext = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(pxmitpriv->xframe_ext_alloc_addr),4 );
@@ -195,7 +197,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) pxmitpriv->pallocated_xmit_extbuf =vzalloc (NR_XMIT_EXTBUFF *sizeof (struct xmit_buf ) +4 );if (!pxmitpriv->pallocated_xmit_extbuf) { - res = _FAIL; + res = -ENOMEM ; goto exit; }
@@ -211,10 +213,9 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) pxmitbuf->buf_tag =XMITBUF_MGNT ; res =rtw_os_xmit_resource_alloc (padapter, pxmitbuf,MAX_XMIT_EXTBUF_SZ +XMITBUF_ALIGN_SZ , true); -if (res == _FAIL) { - res = _FAIL; + +if (res) goto exit; - } pxmitbuf->phead = pxmitbuf->pbuf; pxmitbuf->pend = pxmitbuf->pbuf +MAX_XMIT_EXTBUF_SZ ;
@@ -243,10 +244,9 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) res =rtw_os_xmit_resource_alloc (padapter, pxmitbuf,MAX_CMDBUF_SZ +XMITBUF_ALIGN_SZ , true); -if (res == _FAIL) { - res = _FAIL; + +if (res) goto exit; - } pxmitbuf->phead = pxmitbuf->pbuf; pxmitbuf->pend = pxmitbuf->pbuf +MAX_CMDBUF_SZ ;
@@ -257,7 +257,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) } res =rtw_alloc_hwxmits (padapter); -if (res == _FAIL) +if (res) goto exit;rtw_init_hwxmits (pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
@@ -1875,7 +1875,7 @@ s32 rtw_alloc_hwxmits(struct adapter *padapter) pxmitpriv->hwxmits =kzalloc_objs (*hwxmits, pxmitpriv->hwxmit_entry,GFP_ATOMIC );if (!pxmitpriv->hwxmits) -return _FAIL; +return -ENOMEM ; hwxmits = pxmitpriv->hwxmits;
@@ -1900,7 +1900,7 @@ s32 rtw_alloc_hwxmits(struct adapter *padapter) }else { } -return _SUCCESS; +return 0 ; }void rtw_free_hwxmits (struct adapter *padapter)
drivers/staging/rtl8723bs/os_dep/os_intfs.c +1 -1
@@ -653,7 +653,7 @@ u8 rtw_init_drv_sw(struct adapter *padapter)init_mlme_ext_priv (padapter); -if (_rtw_init_xmit_priv (&padapter->xmitpriv, padapter) == _FAIL) +if (_rtw_init_xmit_priv (&padapter->xmitpriv, padapter)) goto free_mlme_ext;if (_rtw_init_recv_priv (&padapter->recvpriv, padapter) == _FAIL)
drivers/staging/rtl8723bs/os_dep/xmit_linux.c +2 -2
@@ -51,12 +51,12 @@ int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitbif (alloc_sz >0 ) { pxmitbuf->pallocated_buf =kzalloc (alloc_sz,GFP_KERNEL );if (!pxmitbuf->pallocated_buf) -return _FAIL; +return -ENOMEM ; pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT ((SIZE_PTR )(pxmitbuf->pallocated_buf),XMITBUF_ALIGN_SZ ); } -return _SUCCESS; +return 0 ; }void rtw_os_xmit_resource_free (struct adapter *padapter,struct xmit_buf *pxmitbuf,u32 free_sz,u8 flag)
Signature · 1 line
2.34.1
Quoted 11 lines · Hungyu Lin
Replace the use of _SUCCESS/_FAIL return values with standard kernel return conventions (0 on success, negative errno on failure) in the xmit initialization path.
Specifically:
-rtw_os_xmit_resource_alloc()now returns 0 or-ENOMEM
-rtw_alloc_hwxmits()now returns 0 or-ENOMEM
-_rtw_init_xmit_priv()updated to propagate error codes and use direct truth checks instead of comparing with_FAIL
- caller inos_intfs.cupdated accordingly
Quoted 5 lines
This improves error propagation and aligns the driver with kernel coding style.
Signed-off-by Hungyu Lin <[email protected]>---
Break this up into a bunch of patches:
patch 1: Change _rtw_init_xmit_priv() to use direct returns and get
rid of the exit label.
patch 2: Make rtw_alloc_hwxmits() static
patch 3: Make rtw_alloc_hwxmits() return negative error codes and update
the call site to look like this:
res = rtw_alloc_hwxmits();
if (res)
return _FAIL;
patch 4: Move rtw_os_xmit_resource_alloc() to
drivers/staging/rtl8723bs/core/rtw_xmit.c and make it static.
patch 5: Make rtw_os_xmit_resource_alloc() return -ENOMEM on failure
and update the call sites to look like:
res = rtw_os_xmit_resource_alloc();
if (res)
return _FAIL;patch 6: Change _rtw_init_xmit_priv() to return negative error codes
and update the call sites to look like: res = _rtw_init_xmit_priv(&padapter->xmitpriv, padapter); if (res) goto free_mlme_ext;
Making the functions static makes them easier to review so we don't have to jump around between files. Doing it one function at a time is easier to review because we don't have to remember all the functions which were changed. Direct returns are easier to review because we don't have to scroll to the bottom of the function.
regards,
dan carpenter