wcn36xx: use struct_size over open coded arithmetic
authorMinghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
Tue, 8 Feb 2022 01:56:06 +0000 (01:56 +0000)
committerKalle Valo <quic_kvalo@quicinc.com>
Mon, 14 Feb 2022 17:50:57 +0000 (19:50 +0200)
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>
Link: https://lore.kernel.org/r/20220208015606.1514022-1-chi.minghao@zte.com.cn
drivers/net/wireless/ath/wcn36xx/smd.c

index caeb68901326cabb0489d603ddc1bfda3cb3ef2a..59ad332156aed2bb424fd24a8560307a6a8f42c2 100644 (file)
@@ -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);