usb: gadget: f_fs: Limit data buffer size to a single page 96/232896/1 accepted/tizen/unified/20200510.220449 submit/tizen/20200508.072818
authorDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 8 May 2020 06:30:40 +0000 (15:30 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 8 May 2020 07:15:52 +0000 (16:15 +0900)
Large size request from sdbd usually causes memory allocation failure
in case of memory shortage. The failure is not handled by sdbd
properly and thus it makes sdbd a hung state. To prevent this
situation, this patch limits data buffer size to a single page so as
to guarantee memory allocation success.

Change-Id: I4eada6c8beca337cf93182b6d860209cc80d044d
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
drivers/usb/gadget/function/f_fs.c

index 59c69db43041de8c4971414a94616adfd5e1d2cb..b26b607eb0f28101924f9cb8383c18a1a3c569b5 100644 (file)
@@ -940,6 +940,13 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
                        goto error_lock;
                }
                data_len = iov_iter_count(&io_data->data);
+
+               /*
+                * To prevent memory allocation failure of big size request,
+                * limits data buffer size to a single page.
+                */
+               data_len = (data_len > PAGE_SIZE) ? PAGE_SIZE : data_len;
+
                /*
                 * Controller may require buffer size to be aligned to
                 * maxpacketsize of an out endpoint.