Skip to content

Commit 959c731

Browse files
andrzejtpgregkh
authored andcommitted
usb: gadget: Zero ffs_io_data
[ Upstream commit 5085955 ] 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: Andrzej Pietrasiewicz <andrzej.p@collabora.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 718514c commit 959c731

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • drivers/usb/gadget/function

drivers/usb/gadget/function/f_fs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,11 +912,12 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from)
912912
ENTER();
913913

914914
if (!is_sync_kiocb(kiocb)) {
915-
p = kmalloc(sizeof(io_data), GFP_KERNEL);
915+
p = kzalloc(sizeof(io_data), GFP_KERNEL);
916916
if (unlikely(!p))
917917
return -ENOMEM;
918918
p->aio = true;
919919
} else {
920+
memset(p, 0, sizeof(*p));
920921
p->aio = false;
921922
}
922923

@@ -948,11 +949,12 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to)
948949
ENTER();
949950

950951
if (!is_sync_kiocb(kiocb)) {
951-
p = kmalloc(sizeof(io_data), GFP_KERNEL);
952+
p = kzalloc(sizeof(io_data), GFP_KERNEL);
952953
if (unlikely(!p))
953954
return -ENOMEM;
954955
p->aio = true;
955956
} else {
957+
memset(p, 0, sizeof(*p));
956958
p->aio = false;
957959
}
958960

0 commit comments

Comments
 (0)