Skip to content

Commit d224e93

Browse files
Michal Hockotorvalds
authored andcommitted
drivers/md/dm-ioctl.c: use kvmalloc rather than opencoded variant
copy_params uses kmalloc with vmalloc fallback. We already have a helper for that - kvmalloc. This caller requires GFP_NOIO semantic so it hasn't been converted with many others by previous patches. All we need to achieve this semantic is to use the scope memalloc_noio_{save,restore} around kvmalloc. Link: http://lkml.kernel.org/r/20170306103327.2766-4-mhocko@kernel.org Signed-off-by: Michal Hocko <mhocko@suse.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Mikulas Patocka <mpatocka@redhat.com> Cc: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent da6bc57 commit d224e93

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

drivers/md/dm-ioctl.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,7 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern
16911691
struct dm_ioctl *dmi;
16921692
int secure_data;
16931693
const size_t minimum_data_size = offsetof(struct dm_ioctl, data);
1694+
unsigned noio_flag;
16941695

16951696
if (copy_from_user(param_kernel, user, minimum_data_size))
16961697
return -EFAULT;
@@ -1713,15 +1714,9 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl *param_kern
17131714
* Use kmalloc() rather than vmalloc() when we can.
17141715
*/
17151716
dmi = NULL;
1716-
if (param_kernel->data_size <= KMALLOC_MAX_SIZE)
1717-
dmi = kmalloc(param_kernel->data_size, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
1718-
1719-
if (!dmi) {
1720-
unsigned noio_flag;
1721-
noio_flag = memalloc_noio_save();
1722-
dmi = __vmalloc(param_kernel->data_size, GFP_NOIO | __GFP_HIGH | __GFP_HIGHMEM, PAGE_KERNEL);
1723-
memalloc_noio_restore(noio_flag);
1724-
}
1717+
noio_flag = memalloc_noio_save();
1718+
dmi = kvmalloc(param_kernel->data_size, GFP_KERNEL);
1719+
memalloc_noio_restore(noio_flag);
17251720

17261721
if (!dmi) {
17271722
if (secure_data && clear_user(user, param_kernel->data_size))

0 commit comments

Comments
 (0)