Skip to contentSkip to conversation

staging: rtl8723bs: Use pointer type in vzalloc()

PATCH In review Patryk Gawroński 2 participants 2 messages Jul 22 – Jul 28 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: Use pointer type in vzalloc()

Update the memory allocation in _rtw_init_sta_priv() to use sizeof(*pstapriv->pallocated_stainfo_buf) instead of explicitly passing sizeof(struct sta_info).

This resolves the following checkpatch warning:
"Prefer vzalloc(sizeof(*pstapriv->pallocated_stainfo_buf)...) over vzalloc(sizeof(struct sta_info)...)"

Using the pointer type is preferred in the kernel as it ensures the allocated size remains correct even if the pointer's underlying type changes in the future. The allocation was also split across multiple lines to comply with column length limits.

---
 drivers/staging/rtl8723bs/core/rtw_sta_mgt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +2 -1
index aea660f27959..0758d0540f4b 100644
@@ -54,7 +54,8 @@ u32 _rtw_init_sta_priv(struct	sta_priv *pstapriv)
 	struct sta_info *psta;
 	s32 i;
 
-	pstapriv->pallocated_stainfo_buf = vzalloc(sizeof(struct sta_info) * NUM_STA + 4);
+	pstapriv->pallocated_stainfo_buf =
+		vzalloc(sizeof(*pstapriv->pallocated_stainfo_buf) * NUM_STA + 4);
 
 	if (!pstapriv->pallocated_stainfo_buf)
 		return _FAIL;
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 23 lines · Patryk Gawroński

Update the memory allocation in _rtw_init_sta_priv() to use sizeof(*pstapriv->pallocated_stainfo_buf) instead of explicitly passing sizeof(struct sta_info).

This resolves the following checkpatch warning:
"Prefer vzalloc(sizeof(*pstapriv->pallocated_stainfo_buf)...) over vzalloc(sizeof(struct sta_info)...)"

Using the pointer type is preferred in the kernel as it ensures the allocated size remains correct even if the pointer's underlying type changes in the future. The allocation was also split across multiple lines to comply with column length limits.

---
 drivers/staging/rtl8723bs/core/rtw_sta_mgt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +0 -0
index aea660f27959..0758d0540f4b 100644

drivers/staging/rtl8723bs/core/rtw_sta_mgt.c u32 _rtw_init_sta_priv(struct sta_priv *pstapriv) · line 58

Quoted 6 lines
drivers/staging/rtl8723bs/core/rtw_sta_mgt.c +2 -1
@@ -54,7 +54,8 @@ u32 _rtw_init_sta_priv(struct	sta_priv *pstapriv)
 	struct sta_info *psta;
 	s32 i;
 
-	pstapriv->pallocated_stainfo_buf = vzalloc(sizeof(struct sta_info) * NUM_STA + 4);
+	pstapriv->pallocated_stainfo_buf =
+		vzalloc(sizeof(*pstapriv->pallocated_stainfo_buf) * NUM_STA + 4);

You just broke the driver as the math here is now not the same.

Hint, look at what pallocated_stainfo_buf really is. It's not a pointer to a struct at all, right?

thanks,

greg k-h