Skip to content

Commit 18fc82d

Browse files
Minghao Chi (CGEL ZTE)andersson
authored andcommitted
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: Zeal Robot <zealci@zte.com.cn> Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Link: https://lore.kernel.org/r/20220216030720.1839503-1-chi.minghao@zte.com.cn
1 parent a8f8cc6 commit 18fc82d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/rpmsg/qcom_glink_native.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ static int qcom_glink_rx_defer(struct qcom_glink *glink, size_t extra)
792792
return -ENXIO;
793793
}
794794

795-
dcmd = kzalloc(sizeof(*dcmd) + extra, GFP_ATOMIC);
795+
dcmd = kzalloc(struct_size(dcmd, data, extra), GFP_ATOMIC);
796796
if (!dcmd)
797797
return -ENOMEM;
798798

0 commit comments

Comments
 (0)