diff mbox series

[V2] wcn36xx: use struct_size over open coded arithmetic

Message ID 20220208015606.1514022-1-chi.minghao@zte.com.cn (mailing list archive)
State Accepted
Commit be24835f83234380ab6a980dc57560f1f97f67f0
Delegated to: Kalle Valo
Headers show
Series [V2] wcn36xx: use struct_size over open coded arithmetic | expand

Commit Message

CGEL Feb. 8, 2022, 1:56 a.m. UTC
From: "Minghao Chi (CGEL ZTE)" <chi.minghao@zte.com.cn>

Replace zero-length array with flexible-array member and make use
of the struct_size() helper in kmalloc(). For example:

struct wcn36xx_hal_ind_msg {
    struct list_head list;
    size_t msg_len;
    u8 msg[];
};

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
---
 drivers/net/wireless/ath/wcn36xx/smd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kalle Valo Feb. 10, 2022, 12:11 p.m. UTC | #1
cgel.zte@gmail.com wrote:

> From: "Minghao Chi (CGEL ZTE)" <chi.minghao@zte.com.cn>
> 
> Replace zero-length array with flexible-array member and make use
> of the struct_size() helper in kmalloc(). For example:
> 
> struct wcn36xx_hal_ind_msg {
>     struct list_head list;
>     size_t msg_len;
>     u8 msg[];
> };
> 
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>

What are the changes from v1?
CGEL Feb. 11, 2022, 1:29 a.m. UTC | #2
change log:

v1: msg_ind = kmalloc(struct_size(*msg_ind, msg, len), GFP_ATOMIC);
v2: msg_ind = kmalloc(struct_size(msg_ind, msg, len), GFP_ATOMIC);

thanks
Minghao
Kalle Valo Feb. 14, 2022, 5:51 p.m. UTC | #3
cgel.zte@gmail.com wrote:

> Replace zero-length array with flexible-array member and make use
> of the struct_size() helper in kmalloc(). For example:
> 
> struct wcn36xx_hal_ind_msg {
>     struct list_head list;
>     size_t msg_len;
>     u8 msg[];
> };
> 
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
> Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>

Patch applied to ath-next branch of ath.git, thanks.

be24835f8323 wcn36xx: use struct_size over open coded arithmetic
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/wcn36xx/smd.c b/drivers/net/wireless/ath/wcn36xx/smd.c
index caeb68901326..59ad332156ae 100644
--- a/drivers/net/wireless/ath/wcn36xx/smd.c
+++ b/drivers/net/wireless/ath/wcn36xx/smd.c
@@ -3347,7 +3347,7 @@  int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
 	case WCN36XX_HAL_DELETE_STA_CONTEXT_IND:
 	case WCN36XX_HAL_PRINT_REG_INFO_IND:
 	case WCN36XX_HAL_SCAN_OFFLOAD_IND:
-		msg_ind = kmalloc(sizeof(*msg_ind) + len, GFP_ATOMIC);
+		msg_ind = kmalloc(struct_size(msg_ind, msg, len), GFP_ATOMIC);
 		if (!msg_ind) {
 			wcn36xx_err("Run out of memory while handling SMD_EVENT (%d)\n",
 				    msg_header->msg_type);