linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc/qcom: use struct_size over open coded arithmetic
@ 2022-02-16  3:07 cgel.zte
  0 siblings, 0 replies; 2+ messages in thread
From: cgel.zte @ 2022-02-16  3:07 UTC (permalink / raw)
  To: agross
  Cc: bjorn.andersson, linux-arm-msm, 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 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 <zealci@zte.com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
---
 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


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

* Re: [PATCH] soc/qcom: use struct_size over open coded arithmetic
@ 2022-02-16 15:41 Nathan Chancellor
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Chancellor @ 2022-02-16 15:41 UTC (permalink / raw)
  To: cgel.zte
  Cc: agross, bjorn.andersson, linux-arm-msm, linux-kernel, chi.minghao

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

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

end of thread, other threads:[~2022-02-16 15:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16  3:07 [PATCH] soc/qcom: use struct_size over open coded arithmetic cgel.zte
2022-02-16 15:41 Nathan Chancellor

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