mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 18:21:24 +02:00
staging: rtl8723bs: update _rtw_pktfile_read() to return error codes
The function _rtw_pktfile_read() currently returns a uint and clamps
the requested read length if it exceeds the remaining data. This
behavior makes it impossible to propagate error codes from internal
calls like skb_copy_bits() and leads to incomplete data processing.
This patch updates the function to:
1. Return -EINVAL if the remaining data is less than the requested length,
ensuring callers always get the full amount of data they expect.
2. Propagate the negative error code from skb_copy_bits().
3. Change the return type from uint to int to support these error codes.
To avoid breaking git bisect, this patch also updates all call sites
(set_qos, update_attrib, and rtw_xmitframe_coalesce) in the same commit.
By doing so, the error-producing function and its error-handling callers
remain in sync, preventing runtime failures at this commit point.
Signed-off-by: Minu Jin <s9430939@naver.com>
Link: https://patch.msgid.link/20260127153811.1592900-2-s9430939@naver.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1d264b88ae
commit
bc4df274dc
|
|
@ -600,23 +600,31 @@ u8 qos_acm(u8 acm_mask, u8 priority)
|
||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
|
static int set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
|
||||||
{
|
{
|
||||||
struct ethhdr etherhdr;
|
struct ethhdr etherhdr;
|
||||||
struct iphdr ip_hdr;
|
struct iphdr ip_hdr;
|
||||||
s32 UserPriority = 0;
|
s32 UserPriority = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
_rtw_open_pktfile(ppktfile->pkt, ppktfile);
|
_rtw_open_pktfile(ppktfile->pkt, ppktfile);
|
||||||
_rtw_pktfile_read(ppktfile, (unsigned char *)ðerhdr, ETH_HLEN);
|
ret = _rtw_pktfile_read(ppktfile, (unsigned char *)ðerhdr, ETH_HLEN);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* get UserPriority from IP hdr */
|
/* get UserPriority from IP hdr */
|
||||||
if (pattrib->ether_type == 0x0800) {
|
if (pattrib->ether_type == 0x0800) {
|
||||||
_rtw_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
|
ret = _rtw_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
UserPriority = ip_hdr.tos >> 5;
|
UserPriority = ip_hdr.tos >> 5;
|
||||||
}
|
}
|
||||||
pattrib->priority = UserPriority;
|
pattrib->priority = UserPriority;
|
||||||
pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
|
pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
|
||||||
pattrib->subtype = WIFI_QOS_DATA_TYPE;
|
pattrib->subtype = WIFI_QOS_DATA_TYPE;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct pkt_attrib *pattrib)
|
static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct pkt_attrib *pattrib)
|
||||||
|
|
@ -630,9 +638,12 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
|
||||||
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
|
||||||
struct qos_priv *pqospriv = &pmlmepriv->qospriv;
|
struct qos_priv *pqospriv = &pmlmepriv->qospriv;
|
||||||
signed int res = _SUCCESS;
|
signed int res = _SUCCESS;
|
||||||
|
int ret;
|
||||||
|
|
||||||
_rtw_open_pktfile(pkt, &pktfile);
|
_rtw_open_pktfile(pkt, &pktfile);
|
||||||
_rtw_pktfile_read(&pktfile, (u8 *)ðerhdr, ETH_HLEN);
|
ret = _rtw_pktfile_read(&pktfile, (u8 *)ðerhdr, ETH_HLEN);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
pattrib->ether_type = ntohs(etherhdr.h_proto);
|
pattrib->ether_type = ntohs(etherhdr.h_proto);
|
||||||
|
|
||||||
|
|
@ -659,7 +670,9 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
|
||||||
|
|
||||||
u8 tmp[24];
|
u8 tmp[24];
|
||||||
|
|
||||||
_rtw_pktfile_read(&pktfile, &tmp[0], 24);
|
ret = _rtw_pktfile_read(&pktfile, &tmp[0], 24);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
pattrib->dhcp_pkt = 0;
|
pattrib->dhcp_pkt = 0;
|
||||||
if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */
|
if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */
|
||||||
|
|
@ -742,11 +755,16 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
|
||||||
pattrib->priority = 0;
|
pattrib->priority = 0;
|
||||||
|
|
||||||
if (check_fwstate(pmlmepriv, WIFI_AP_STATE | WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) {
|
if (check_fwstate(pmlmepriv, WIFI_AP_STATE | WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) {
|
||||||
if (pattrib->qos_en)
|
if (pattrib->qos_en) {
|
||||||
set_qos(&pktfile, pattrib);
|
ret = set_qos(&pktfile, pattrib);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pqospriv->qos_option) {
|
if (pqospriv->qos_option) {
|
||||||
set_qos(&pktfile, pattrib);
|
ret = set_qos(&pktfile, pattrib);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (pmlmepriv->acm_mask != 0)
|
if (pmlmepriv->acm_mask != 0)
|
||||||
pattrib->priority = qos_acm(pmlmepriv->acm_mask, pattrib->priority);
|
pattrib->priority = qos_acm(pmlmepriv->acm_mask, pattrib->priority);
|
||||||
|
|
@ -1048,6 +1066,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
|
||||||
|
|
||||||
s32 bmcst = is_multicast_ether_addr(pattrib->ra);
|
s32 bmcst = is_multicast_ether_addr(pattrib->ra);
|
||||||
s32 res = _SUCCESS;
|
s32 res = _SUCCESS;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (!pxmitframe->buf_addr)
|
if (!pxmitframe->buf_addr)
|
||||||
return _FAIL;
|
return _FAIL;
|
||||||
|
|
@ -1063,7 +1082,9 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
|
||||||
}
|
}
|
||||||
|
|
||||||
_rtw_open_pktfile(pkt, &pktfile);
|
_rtw_open_pktfile(pkt, &pktfile);
|
||||||
_rtw_pktfile_read(&pktfile, NULL, pattrib->pkt_hdrlen);
|
ret = _rtw_pktfile_read(&pktfile, NULL, pattrib->pkt_hdrlen);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
frg_inx = 0;
|
frg_inx = 0;
|
||||||
frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */
|
frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */
|
||||||
|
|
@ -1105,6 +1126,9 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
|
||||||
mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len);
|
mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mem_sz < 0)
|
||||||
|
return mem_sz;
|
||||||
|
|
||||||
pframe += mem_sz;
|
pframe += mem_sz;
|
||||||
|
|
||||||
if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
|
if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
|
||||||
|
|
@ -1968,7 +1992,7 @@ s32 rtw_xmit(struct adapter *padapter, struct sk_buff **ppkt)
|
||||||
|
|
||||||
res = update_attrib(padapter, *ppkt, &pxmitframe->attrib);
|
res = update_attrib(padapter, *ppkt, &pxmitframe->attrib);
|
||||||
|
|
||||||
if (res == _FAIL) {
|
if (res != _SUCCESS) {
|
||||||
rtw_free_xmitframe(pxmitpriv, pxmitframe);
|
rtw_free_xmitframe(pxmitpriv, pxmitframe);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -289,10 +289,10 @@ static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv
|
||||||
pxmitframe->buf_addr = pxmitbuf->ptail;
|
pxmitframe->buf_addr = pxmitbuf->ptail;
|
||||||
|
|
||||||
ret = rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
|
ret = rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
|
||||||
if (ret == _FAIL) {
|
if (ret != _SUCCESS) {
|
||||||
netdev_err(padapter->pnetdev,
|
netdev_err(padapter->pnetdev,
|
||||||
"%s: coalesce FAIL!",
|
"%s: coalesce failed with error %d\n",
|
||||||
__func__);
|
__func__, ret);
|
||||||
/* Todo: error handler */
|
/* Todo: error handler */
|
||||||
} else {
|
} else {
|
||||||
k++;
|
k++;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ void rtw_os_xmit_resource_free(struct adapter *padapter, struct xmit_buf *pxmitb
|
||||||
|
|
||||||
extern uint rtw_remainder_len(struct pkt_file *pfile);
|
extern uint rtw_remainder_len(struct pkt_file *pfile);
|
||||||
extern void _rtw_open_pktfile(struct sk_buff *pkt, struct pkt_file *pfile);
|
extern void _rtw_open_pktfile(struct sk_buff *pkt, struct pkt_file *pfile);
|
||||||
extern uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen);
|
int _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen);
|
||||||
extern signed int rtw_endofpktfile(struct pkt_file *pfile);
|
extern signed int rtw_endofpktfile(struct pkt_file *pfile);
|
||||||
|
|
||||||
extern void rtw_os_pkt_complete(struct adapter *padapter, struct sk_buff *pkt);
|
extern void rtw_os_pkt_complete(struct adapter *padapter, struct sk_buff *pkt);
|
||||||
|
|
|
||||||
|
|
@ -21,19 +21,22 @@ void _rtw_open_pktfile(struct sk_buff *pktptr, struct pkt_file *pfile)
|
||||||
pfile->cur_buffer = pfile->buf_start;
|
pfile->cur_buffer = pfile->buf_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
|
int _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
|
||||||
{
|
{
|
||||||
uint len = 0;
|
int ret;
|
||||||
|
|
||||||
len = rtw_remainder_len(pfile);
|
if (rtw_remainder_len(pfile) < rlen)
|
||||||
len = (rlen > len) ? len : rlen;
|
return -EINVAL;
|
||||||
|
|
||||||
if (rmem)
|
if (rmem) {
|
||||||
skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len, rmem, len);
|
ret = skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len, rmem, rlen);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
pfile->cur_addr += len;
|
pfile->cur_addr += rlen;
|
||||||
pfile->pkt_len -= len;
|
pfile->pkt_len -= rlen;
|
||||||
return len;
|
return rlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
signed int rtw_endofpktfile(struct pkt_file *pfile)
|
signed int rtw_endofpktfile(struct pkt_file *pfile)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user