提交 18fc82d6 编写于 作者: M Minghao Chi (CGEL ZTE) 提交者: Bjorn Andersson

rpmsg: use struct_size over open coded arithmetic

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: NZeal Robot <zealci@zte.com.cn>
Signed-off-by: NMinghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
Signed-off-by: NBjorn Andersson <bjorn.andersson@linaro.org>
Link: https://lore.kernel.org/r/20220216030720.1839503-1-chi.minghao@zte.com.cn
上级 a8f8cc6b
...@@ -792,7 +792,7 @@ static int qcom_glink_rx_defer(struct qcom_glink *glink, size_t extra) ...@@ -792,7 +792,7 @@ static int qcom_glink_rx_defer(struct qcom_glink *glink, size_t extra)
return -ENXIO; return -ENXIO;
} }
dcmd = kzalloc(sizeof(*dcmd) + extra, GFP_ATOMIC); dcmd = kzalloc(struct_size(dcmd, data, extra), GFP_ATOMIC);
if (!dcmd) if (!dcmd)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册