Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vhost_vdpa: switch to vmemdup_user()

Replace opencoded alloc and copy with vmemdup_user()

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
Link: https://lore.kernel.org/r/1605057288-60400-1-git-send-email-tiantao6@hisilicon.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

authored by

Tian Tao and committed by
Michael S. Tsirkin
0ab4b890 3711387a

+3 -7
+3 -7
drivers/vhost/vdpa.c
··· 245 245 return -EFAULT; 246 246 if (vhost_vdpa_config_validate(v, &config)) 247 247 return -EINVAL; 248 - buf = kvzalloc(config.len, GFP_KERNEL); 249 - if (!buf) 250 - return -ENOMEM; 251 248 252 - if (copy_from_user(buf, c->buf, config.len)) { 253 - kvfree(buf); 254 - return -EFAULT; 255 - } 249 + buf = vmemdup_user(c->buf, config.len); 250 + if (IS_ERR(buf)) 251 + return PTR_ERR(buf); 256 252 257 253 ops->set_config(vdpa, config.off, buf, config.len); 258 254