syzbot is reporting refcount leak when client->add() from add_client_context() fails, for commit 11a0ae4c4bff ("RDMA: Allow ib_client's to fail when add() is called") for unknown reason ignores error from client->add(). We need to return an error in order to indicate that client could not be added, otherwise the caller will get confused. Reported-by: syzbot <syzbot+5e70d01ee8985ae62a3b@xxxxxxxxxxxxxxxxxxxxxxxxx> Link: https://syzkaller.appspot.com/bug?extid=5e70d01ee8985ae62a3b Fixes: 11a0ae4c4bff ("RDMA: Allow ib_client's to fail when add() is called") Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> --- drivers/infiniband/core/device.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index a666847bd714..c72f810ceae1 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -718,17 +718,17 @@ static int add_client_context(struct ib_device *device, goto out; downgrade_write(&device->client_data_rwsem); if (client->add) { - if (client->add(device)) { + ret = client->add(device); + if (ret) { /* - * If a client fails to add then the error code is - * ignored, but we won't call any more ops on this - * client. + * If a client fails to add, we won't call any more + * ops on this client. */ xa_erase(&device->client_data, client->client_id); up_read(&device->client_data_rwsem); ib_device_put(device); ib_client_put(client); - return 0; + return ret; } } -- 2.18.4