Skip to content

Commit

Permalink
rpmsg: use struct_size over open coded arithmetic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Minghao Chi (CGEL ZTE) authored and Bjorn Andersson committed Mar 11, 2022
1 parent a8f8cc6 commit 18fc82d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/rpmsg/qcom_glink_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 18fc82d

Please sign in to comment.