RDMA/rtrs-srv: Replace device_register with device_initialize and device_add
authorMd Haris Iqbal <haris.iqbal@cloud.ionos.com>
Tue, 11 Aug 2020 09:27:22 +0000 (14:57 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Sep 2020 11:55:26 +0000 (13:55 +0200)
commit81aaf0645c8135b354c4df91bfcb96f5e26f7d01
treeb5062c55b70145fb87c7b499df9d636687870c29
parent8edf8c890ee27b0a4973afdebf4a89f6791573cf
RDMA/rtrs-srv: Replace device_register with device_initialize and device_add

[ Upstream commit baa5b28b7a474f66a511ebf71a2ade510652a2f6 ]

There are error cases when we will call free_srv before device kobject is
initialized; in such cases calling put_device generates the following
warning:

 kobject: '(null)' (000000009f5445ed): is not initialized, yet
 kobject_put() is being called.

So call device_initialize() only once when the server is allocated. If we
end up calling put_srv() and subsequently free_srv(), our call to
put_device() would result in deletion of the obj. Call device_add() later
when we actually have a connection. Correspondingly, call device_del()
instead of device_unregister() when srv->dev_ref falls to 0.

Fixes: 9cb837480424 ("RDMA/rtrs: server: main functionality")
Link: https://lore.kernel.org/r/20200811092722.2450-1-haris.iqbal@cloud.ionos.com
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Md Haris Iqbal <haris.iqbal@cloud.ionos.com>
Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c
drivers/infiniband/ulp/rtrs/rtrs-srv.c