Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: rtl8712: check for alloc fail in _r8712_init_recv_priv()

The function _r8712_init_recv_priv() and also r8712_init_recv_priv()
just returns silently if they fail to allocate memory. Change their
return type to int and add necessary checks and handling if they return
-ENOMEM

Tested-by: Philipp Hortmann <philipp.g.hortmann@gmail.com>
Signed-off-by: Nam Cao <namcaov@gmail.com>
Link: https://lore.kernel.org/r/506ac35a667e511db568b06b86834fd0ceeba453.1666688642.git.namcaov@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Nam Cao and committed by
Greg Kroah-Hartman
63b5e505 c5a7eecd

+20 -12
+3 -1
drivers/staging/rtl8712/os_intfs.c
··· 309 309 if (ret) 310 310 return ret; 311 311 _r8712_init_xmit_priv(&padapter->xmitpriv, padapter); 312 - _r8712_init_recv_priv(&padapter->recvpriv, padapter); 312 + ret = _r8712_init_recv_priv(&padapter->recvpriv, padapter); 313 + if (ret) 314 + return ret; 313 315 memset((unsigned char *)&padapter->securitypriv, 0, 314 316 sizeof(struct security_priv)); 315 317 timer_setup(&padapter->securitypriv.tkip_timer,
+4 -4
drivers/staging/rtl8712/recv_osdep.h
··· 18 18 #include "drv_types.h" 19 19 #include <linux/skbuff.h> 20 20 21 - void _r8712_init_recv_priv(struct recv_priv *precvpriv, 22 - struct _adapter *padapter); 21 + int _r8712_init_recv_priv(struct recv_priv *precvpriv, 22 + struct _adapter *padapter); 23 23 void _r8712_free_recv_priv(struct recv_priv *precvpriv); 24 24 void r8712_recv_entry(union recv_frame *precv_frame); 25 25 void r8712_recv_indicatepkt(struct _adapter *adapter, 26 26 union recv_frame *precv_frame); 27 27 void r8712_handle_tkip_mic_err(struct _adapter *padapter, u8 bgroup); 28 - void r8712_init_recv_priv(struct recv_priv *precvpriv, 29 - struct _adapter *padapter); 28 + int r8712_init_recv_priv(struct recv_priv *precvpriv, 29 + struct _adapter *padapter); 30 30 void r8712_free_recv_priv(struct recv_priv *precvpriv); 31 31 void r8712_os_recv_resource_alloc(struct _adapter *padapter, 32 32 union recv_frame *precvframe);
+4 -3
drivers/staging/rtl8712/rtl8712_recv.c
··· 30 30 31 31 static void recv_tasklet(struct tasklet_struct *t); 32 32 33 - void r8712_init_recv_priv(struct recv_priv *precvpriv, 34 - struct _adapter *padapter) 33 + int r8712_init_recv_priv(struct recv_priv *precvpriv, 34 + struct _adapter *padapter) 35 35 { 36 36 int i; 37 37 struct recv_buf *precvbuf; ··· 44 44 precvpriv->pallocated_recv_buf = 45 45 kzalloc(NR_RECVBUFF * sizeof(struct recv_buf) + 4, GFP_ATOMIC); 46 46 if (!precvpriv->pallocated_recv_buf) 47 - return; 47 + return -ENOMEM; 48 48 precvpriv->precv_buf = precvpriv->pallocated_recv_buf + 4 - 49 49 ((addr_t)(precvpriv->pallocated_recv_buf) & 3); 50 50 precvbuf = (struct recv_buf *)precvpriv->precv_buf; ··· 75 75 } 76 76 pskb = NULL; 77 77 } 78 + return 0; 78 79 } 79 80 80 81 void r8712_free_recv_priv(struct recv_priv *precvpriv)
+9 -4
drivers/staging/rtl8712/rtl871x_recv.c
··· 42 42 _init_queue(&psta_recvpriv->defrag_q); 43 43 } 44 44 45 - void _r8712_init_recv_priv(struct recv_priv *precvpriv, 46 - struct _adapter *padapter) 45 + int _r8712_init_recv_priv(struct recv_priv *precvpriv, 46 + struct _adapter *padapter) 47 47 { 48 + int ret; 48 49 sint i; 49 50 union recv_frame *precvframe; 50 51 ··· 59 58 sizeof(union recv_frame) + RXFRAME_ALIGN_SZ, 60 59 GFP_ATOMIC); 61 60 if (!precvpriv->pallocated_frame_buf) 62 - return; 61 + return -ENOMEM; 63 62 precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf + 64 63 RXFRAME_ALIGN_SZ - 65 64 ((addr_t)(precvpriv->pallocated_frame_buf) & ··· 74 73 precvframe++; 75 74 } 76 75 precvpriv->rx_pending_cnt = 1; 77 - r8712_init_recv_priv(precvpriv, padapter); 76 + ret = r8712_init_recv_priv(precvpriv, padapter); 77 + if (ret) 78 + kfree(precvpriv->pallocated_frame_buf); 79 + 80 + return ret; 78 81 } 79 82 80 83 void _r8712_free_recv_priv(struct recv_priv *precvpriv)