Skip to content

Commit

Permalink
xen/privcmd: Use memdup_array_user() in alloc_ioreq()
Browse files Browse the repository at this point in the history
* The function “memdup_array_user” was added with the
  commit 313ebe4 ("string.h: add
  array-wrappers for (v)memdup_user()").
  Thus use it accordingly.

  This issue was detected by using the Coccinelle software.

* Delete a label which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Reviewed-by: Juergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/41e333f7-1f3a-41b6-a121-a3c0ae54e36f@web.de
Signed-off-by: Juergen Gross <jgross@suse.com>
  • Loading branch information
Markus Elfring authored and Juergen Gross committed Feb 13, 2024
1 parent 3693bb4 commit b2c52b8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions drivers/xen/privcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,18 +1223,13 @@ struct privcmd_kernel_ioreq *alloc_ioreq(struct privcmd_ioeventfd *ioeventfd)
kioreq->ioreq = (struct ioreq *)(page_to_virt(pages[0]));
mmap_write_unlock(mm);

size = sizeof(*ports) * kioreq->vcpus;
ports = kzalloc(size, GFP_KERNEL);
if (!ports) {
ret = -ENOMEM;
ports = memdup_array_user(u64_to_user_ptr(ioeventfd->ports),
kioreq->vcpus, sizeof(*ports));
if (IS_ERR(ports)) {
ret = PTR_ERR(ports);
goto error_kfree;
}

if (copy_from_user(ports, u64_to_user_ptr(ioeventfd->ports), size)) {
ret = -EFAULT;
goto error_kfree_ports;
}

for (i = 0; i < kioreq->vcpus; i++) {
kioreq->ports[i].vcpu = i;
kioreq->ports[i].port = ports[i];
Expand All @@ -1256,7 +1251,7 @@ struct privcmd_kernel_ioreq *alloc_ioreq(struct privcmd_ioeventfd *ioeventfd)
error_unbind:
while (--i >= 0)
unbind_from_irqhandler(irq_from_evtchn(ports[i]), &kioreq->ports[i]);
error_kfree_ports:

kfree(ports);
error_kfree:
kfree(kioreq);
Expand Down

0 comments on commit b2c52b8

Please sign in to comment.