Skip to contentSkip to conversation

staging: rtlwifi: Fix potential NULL pointer dereference of kzalloc

PATCH Superseded Aditya Pakki 2 participants 2 messages Mar 20, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 staging: rtlwifi: Fix potential NULL pointer dereference of kzalloc

phydm.internal is allocated using kzalloc which is used multiple times without a check for NULL pointer. This patch avoids such a scenario by returning 0, consistent with the failure case.

---
v2: Move the signed off line above
v1: Patch collision with different things, fix as per Greg

---
 drivers/staging/rtlwifi/phydm/rtl_phydm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/rtlwifi/phydm/rtl_phydm.c +2 -0
index 9930ed954abb..4cc77b2016e1 100644
@@ -180,6 +180,8 @@ static int rtl_phydm_init_priv(struct rtl_priv *rtlpriv,
 
 	rtlpriv->phydm.internal =
 		kzalloc(sizeof(struct phy_dm_struct), GFP_KERNEL);
+	if (!rtlpriv->phydm.internal)
+		return 0;
 
 	_rtl_phydm_init_com_info(rtlpriv, ic, params);
 
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 18 lines · Aditya Pakki

phydm.internal is allocated using kzalloc which is used multiple times without a check for NULL pointer. This patch avoids such a scenario by returning 0, consistent with the failure case.

---
v2: Move the signed off line above
v1: Patch collision with different things, fix as per Greg

---
  drivers/staging/rtlwifi/phydm/rtl_phydm.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/staging/rtlwifi/phydm/rtl_phydm.c +0 -0
index 9930ed954abb..4cc77b2016e1 100644

drivers/staging/rtlwifi/phydm/rtl_phydm.c static int rtl_phydm_init_priv(struct rtl_priv *rtlpriv, · line 187

Quoted 8 lines
drivers/staging/rtlwifi/phydm/rtl_phydm.c +2 -0
@@ -180,6 +180,8 @@ static int rtl_phydm_init_priv(struct rtl_priv *rtlpriv,
 
  	rtlpriv->phydm.internal =
  		kzalloc(sizeof(struct phy_dm_struct), GFP_KERNEL);
+	if (!rtlpriv->phydm.internal)
+		return 0;
 
  	_rtl_phydm_init_com_info(rtlpriv, ic, params);
 

Thanks,
Mukesh