IB/uverbs: Release event file reference on ib_uverbs_create_cq() error

ib_uverbs_create_cq() should release the completion channel event file
if an error occurs after it looks it up. Also, if userspace asks for
a completion channel and we don't find it, an error should be returned
instead of silently creating a CQ without a completion channel.

Signed-off-by: Jack Morgenstein <jackm@mellanox.co.il>
Signed-off-by: Roland Dreier <rolandd@cisco.com>

authored by

Jack Morgenstein and committed by
Roland Dreier
ac4e7b35 ea5d4a6a

+10 -3
+10 -3
drivers/infiniband/core/uverbs_cmd.c
··· 594 if (cmd.comp_vector >= file->device->num_comp_vectors) 595 return -EINVAL; 596 597 - if (cmd.comp_channel >= 0) 598 - ev_file = ib_uverbs_lookup_comp_file(cmd.comp_channel); 599 - 600 uobj = kmalloc(sizeof *uobj, GFP_KERNEL); 601 if (!uobj) 602 return -ENOMEM; 603 604 uobj->uobject.user_handle = cmd.user_handle; 605 uobj->uobject.context = file->ucontext; ··· 669 ib_destroy_cq(cq); 670 671 err: 672 kfree(uobj); 673 return ret; 674 }
··· 594 if (cmd.comp_vector >= file->device->num_comp_vectors) 595 return -EINVAL; 596 597 uobj = kmalloc(sizeof *uobj, GFP_KERNEL); 598 if (!uobj) 599 return -ENOMEM; 600 + 601 + if (cmd.comp_channel >= 0) { 602 + ev_file = ib_uverbs_lookup_comp_file(cmd.comp_channel); 603 + if (!ev_file) { 604 + ret = -EINVAL; 605 + goto err; 606 + } 607 + } 608 609 uobj->uobject.user_handle = cmd.user_handle; 610 uobj->uobject.context = file->ucontext; ··· 664 ib_destroy_cq(cq); 665 666 err: 667 + if (ev_file) 668 + ib_uverbs_release_ucq(file, ev_file, uobj); 669 kfree(uobj); 670 return ret; 671 }