RDMA/rtrs-clt: Fix possible double free in error case
authorMd Haris Iqbal <haris.iqbal@ionos.com>
Thu, 17 Feb 2022 03:09:28 +0000 (04:09 +0100)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 18 Feb 2022 15:59:33 +0000 (11:59 -0400)
commit8700af2cc18c919b2a83e74e0479038fd113c15d
tree7a815d3f387c0c0f6d5b7795376de2187f429adc
parent32f57cb1b2c8d6f20aefec7052b1bfeb7e3b69d4
RDMA/rtrs-clt: Fix possible double free in error case

Callback function rtrs_clt_dev_release() for put_device() calls kfree(clt)
to free memory. We shouldn't call kfree(clt) again, and we can't use the
clt after kfree too.

Replace device_register() with device_initialize() and device_add() so that
dev_set_name can() be used appropriately.

Move mutex_destroy() to the release function so it can be called in
the alloc_clt err path.

Fixes: eab098246625 ("RDMA/rtrs-clt: Refactor the failure cases in alloc_clt")
Link: https://lore.kernel.org/r/20220217030929.323849-1-haris.iqbal@ionos.com
Reported-by: Miaoqian Lin <linmq006@gmail.com>
Signed-off-by: Md Haris Iqbal <haris.iqbal@ionos.com>
Reviewed-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/ulp/rtrs/rtrs-clt.c