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 594 if (cmd.comp_vector >= file->device->num_comp_vectors) 595 595 return -EINVAL; 596 596 597 - if (cmd.comp_channel >= 0) 598 - ev_file = ib_uverbs_lookup_comp_file(cmd.comp_channel); 599 - 600 597 uobj = kmalloc(sizeof *uobj, GFP_KERNEL); 601 598 if (!uobj) 602 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 + } 603 608 604 609 uobj->uobject.user_handle = cmd.user_handle; 605 610 uobj->uobject.context = file->ucontext; ··· 669 664 ib_destroy_cq(cq); 670 665 671 666 err: 667 + if (ev_file) 668 + ib_uverbs_release_ucq(file, ev_file, uobj); 672 669 kfree(uobj); 673 670 return ret; 674 671 }