2022-02-16 07:34:49

by CGEL

[permalink] [raw]
Subject: [PATCH] soc/qcom: 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 kzalloc(). For example:

struct apr_rx_buf {
struct list_head node;
int len;
uint8_t buf[];
};

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 <[email protected]>
Signed-off-by: Minghao Chi (CGEL ZTE) <[email protected]>
---
drivers/soc/qcom/apr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
index 82ca12c9328a..0813dbc5e462 100644
--- a/drivers/soc/qcom/apr.c
+++ b/drivers/soc/qcom/apr.c
@@ -171,7 +171,7 @@ static int apr_callback(struct rpmsg_device *rpdev, void *buf,
return -EINVAL;
}

- abuf = kzalloc(sizeof(*abuf) + len, GFP_ATOMIC);
+ abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC);
if (!abuf)
return -ENOMEM;

--
2.25.1


2022-02-16 18:02:26

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] soc/qcom: use struct_size over open coded arithmetic

Hi,

I am forwarding along this build report from the kernel test robot due
to a bug in their system. As I am sure you will figure out soon enough,
this patch was not even build tested.

Cheers,
Nathan