linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] wcn36xx: use struct_size over open coded arithmetic
@ 2022-02-08  1:56 cgel.zte
  2022-02-10 12:11 ` Kalle Valo
  2022-02-14 17:51 ` Kalle Valo
  0 siblings, 2 replies; 4+ messages in thread
From: cgel.zte @ 2022-02-08  1:56 UTC (permalink / raw)
  To: kvalo
  Cc: davem, kuba, wcn36xx, linux-wireless, netdev, linux-kernel,
	Minghao Chi (CGEL ZTE),
	Zeal Robot

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(-)

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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] wcn36xx: use struct_size over open coded arithmetic
  2022-02-08  1:56 [PATCH V2] wcn36xx: use struct_size over open coded arithmetic cgel.zte
@ 2022-02-10 12:11 ` Kalle Valo
  2022-02-11  1:29   ` cgel.zte
  2022-02-14 17:51 ` Kalle Valo
  1 sibling, 1 reply; 4+ messages in thread
From: Kalle Valo @ 2022-02-10 12:11 UTC (permalink / raw)
  To: cgel.zte
  Cc: davem, kuba, wcn36xx, linux-wireless, netdev, linux-kernel,
	Minghao Chi (CGEL ZTE),
	Zeal Robot

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?

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20220208015606.1514022-1-chi.minghao@zte.com.cn/

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] wcn36xx: use struct_size over open coded arithmetic
  2022-02-10 12:11 ` Kalle Valo
@ 2022-02-11  1:29   ` cgel.zte
  0 siblings, 0 replies; 4+ messages in thread
From: cgel.zte @ 2022-02-11  1:29 UTC (permalink / raw)
  To: kvalo
  Cc: cgel.zte, chi.minghao, davem, kuba, linux-kernel, linux-wireless,
	netdev, wcn36xx, zealci

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] wcn36xx: use struct_size over open coded arithmetic
  2022-02-08  1:56 [PATCH V2] wcn36xx: use struct_size over open coded arithmetic cgel.zte
  2022-02-10 12:11 ` Kalle Valo
@ 2022-02-14 17:51 ` Kalle Valo
  1 sibling, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2022-02-14 17:51 UTC (permalink / raw)
  To: cgel.zte
  Cc: davem, kuba, wcn36xx, linux-wireless, netdev, linux-kernel,
	Minghao Chi (CGEL ZTE),
	Zeal Robot

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

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/20220208015606.1514022-1-chi.minghao@zte.com.cn/

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-14 17:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08  1:56 [PATCH V2] wcn36xx: use struct_size over open coded arithmetic cgel.zte
2022-02-10 12:11 ` Kalle Valo
2022-02-11  1:29   ` cgel.zte
2022-02-14 17:51 ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).