* [PATCH] rpmsg: use struct_size over open coded arithmetic
@ 2022-02-16 3:07 cgel.zte
0 siblings, 0 replies; only message in thread
From: cgel.zte @ 2022-02-16 3:07 UTC (permalink / raw)
To: agross
Cc: bjorn.andersson, mathieu.poirier, linux-arm-msm,
linux-remoteproc, 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 glink_defer_cmd {
struct list_head node;
struct glink_msg msg;
u8 data[];
};
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/rpmsg/qcom_glink_native.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c
index 1030cfa80e04..f4f4e392d0d1 100644
--- a/drivers/rpmsg/qcom_glink_native.c
+++ b/drivers/rpmsg/qcom_glink_native.c
@@ -792,7 +792,7 @@ static int qcom_glink_rx_defer(struct qcom_glink *glink, size_t extra)
return -ENXIO;
}
- dcmd = kzalloc(sizeof(*dcmd) + extra, GFP_ATOMIC);
+ dcmd = kzalloc(struct_size(dcmd, data, extra), GFP_ATOMIC);
if (!dcmd)
return -ENOMEM;
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-02-16 3:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 3:07 [PATCH] rpmsg: use struct_size over open coded arithmetic cgel.zte
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).