Skip to content
Permalink
Browse files
soc/qcom: 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 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>
  • Loading branch information
Minghao Chi (CGEL ZTE) authored and intel-lab-lkp committed Feb 16, 2022
1 parent c5d9ae2 commit 51dde142db132ac922a62df2932acb6f27528e99
Showing 1 changed file with 1 addition and 1 deletion.
@@ -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;

0 comments on commit 51dde14

Please sign in to comment.