Skip to contentSkip to conversation

wcn36xx: use struct_size over open coded arithmetic

PATCH Superseded [email protected] 2 participants 4 messages Feb 8, 2022 – Feb 14, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 wcn36xx: use struct_size over open coded arithmetic

From: "Minghao Chi (CGEL ZTE)" <[email protected]>

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.

---
 drivers/net/wireless/ath/wcn36xx/smd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/wcn36xx/smd.c +1 -1
index caeb68901326..59ad332156ae 100644
@@ -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);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 11 lines · [email protected] wrote:

From: "Minghao Chi (CGEL ZTE)" <[email protected]>

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[];
};
Quoted 5 lines

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

What are the changes from v1?

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#2 lore raw

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

#3 lore raw
In reply to [email protected]
Quoted 9 lines · [email protected] 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[];
};
Quoted 6 lines

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

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

be24835f8323 wcn36xx: use struct_size over open coded arithmetic

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches