Commit 50859551 authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Felipe Balbi

usb: gadget: Zero ffs_io_data

In some cases the "Allocate & copy" block in ffs_epfile_io() is not
executed. Consequently, in such a case ffs_alloc_buffer() is never called
and struct ffs_io_data is not initialized properly. This in turn leads to
problems when ffs_free_buffer() is called at the end of ffs_epfile_io().

This patch uses kzalloc() instead of kmalloc() in the aio case and memset()
in non-aio case to properly initialize struct ffs_io_data.
Signed-off-by: default avatarAndrzej Pietrasiewicz <andrzej.p@collabora.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 48f5e749
...@@ -1183,11 +1183,12 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from) ...@@ -1183,11 +1183,12 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from)
ENTER(); ENTER();
if (!is_sync_kiocb(kiocb)) { if (!is_sync_kiocb(kiocb)) {
p = kmalloc(sizeof(io_data), GFP_KERNEL); p = kzalloc(sizeof(io_data), GFP_KERNEL);
if (unlikely(!p)) if (unlikely(!p))
return -ENOMEM; return -ENOMEM;
p->aio = true; p->aio = true;
} else { } else {
memset(p, 0, sizeof(*p));
p->aio = false; p->aio = false;
} }
...@@ -1219,11 +1220,12 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to) ...@@ -1219,11 +1220,12 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to)
ENTER(); ENTER();
if (!is_sync_kiocb(kiocb)) { if (!is_sync_kiocb(kiocb)) {
p = kmalloc(sizeof(io_data), GFP_KERNEL); p = kzalloc(sizeof(io_data), GFP_KERNEL);
if (unlikely(!p)) if (unlikely(!p))
return -ENOMEM; return -ENOMEM;
p->aio = true; p->aio = true;
} else { } else {
memset(p, 0, sizeof(*p));
p->aio = false; p->aio = false;
} }
......
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