Commit 7643fd78 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Greg Kroah-Hartman

usb: host: fotg210: Use struct_size() helper in kzalloc()

Make use of the struct_size() helper instead of an open-coded version,
in order to avoid any potential type mistakes or integer overflows that,
in the worst scenario, could lead to heap overflows.

Also, address the following sparse warnings:
drivers/usb/host/fotg210-hcd.c:4017:20: warning: using sizeof on a flexible structure

Link: https://github.com/KSPP/linux/issues/174Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20220120222043.GA33559@embeddedorSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c8968611
......@@ -4014,10 +4014,8 @@ static struct fotg210_iso_sched *iso_sched_alloc(unsigned packets,
gfp_t mem_flags)
{
struct fotg210_iso_sched *iso_sched;
int size = sizeof(*iso_sched);
size += packets * sizeof(struct fotg210_iso_packet);
iso_sched = kzalloc(size, mem_flags);
iso_sched = kzalloc(struct_size(iso_sched, packet, packets), mem_flags);
if (likely(iso_sched != NULL))
INIT_LIST_HEAD(&iso_sched->td_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment