Revert "usb: gadget: f_fs: Give chance to retry malloc for large size buffer" 95/232895/1
authorDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 8 May 2020 06:50:04 +0000 (15:50 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 8 May 2020 07:15:18 +0000 (16:15 +0900)
This reverts commit 868788459b5403009d82575fd4834efbfe11e7b2.

That commit turns out that causing write (in transfer) failure when
buffer allocation is failed due to memory shortage. So, it reveals
multiple tries is not complete solution.

Change-Id: Ie924272060dd689e378c59fdca1ea2ddfa571fb2
Reported-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
drivers/usb/gadget/function/f_fs.c

index a429ee374921da9f8af5c5dcaa62914fe7566d2d..59c69db43041de8c4971414a94616adfd5e1d2cb 100644 (file)
@@ -948,34 +948,10 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
                        data_len = usb_ep_align_maybe(gadget, ep->ep, data_len);
                spin_unlock_irq(&epfile->ffs->eps_lock);
 
-retry_malloc:
-               data = kmalloc(data_len, GFP_KERNEL | __GFP_NOWARN);
+               data = kmalloc(data_len, GFP_KERNEL);
                if (unlikely(!data)) {
-                       /*
-                        * f_fs daemons usually use large size buffer for
-                        * performance. However, this can cause failure of
-                        * kmalloc() due to buddy fragmentation, even if there
-                        * is available memory and thus it can be compacted by
-                        * by kswapd. Therefore, instead of just returning error
-                        * to daemon in the case of failure of kmalloc(), give
-                        * the second chance to allocate buffer with a half size
-                        * until it really fails due to memory shortage.
-                        */
-                       if (unlikely(data_len <= PAGE_SIZE)) {
-                               ret = -ENOMEM;
-                               goto error_mutex;
-                       }
-
-                       data_len = data_len >> 1;
-
-                       if (io_data->read) {
-                               spin_lock_irq(&epfile->ffs->eps_lock);
-                               data_len = usb_ep_align_maybe(gadget,
-                                                             ep->ep, data_len);
-                               spin_unlock_irq(&epfile->ffs->eps_lock);
-                       }
-
-                       goto retry_malloc;
+                       ret = -ENOMEM;
+                       goto error_mutex;
                }
                if (!io_data->read &&
                    copy_from_iter(data, data_len, &io_data->data) != data_len) {