Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566387lkm; Mon, 20 Sep 2021 18:53:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy++0Az6ki7vaK9C9c5Y8cCqrVCNwzKWcS/MknUO8nR8qPxXrvz5Su50At26tbeYDc/W0Nu X-Received: by 2002:a50:9b17:: with SMTP id o23mr33242625edi.341.1632189109316; Mon, 20 Sep 2021 18:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189109; cv=none; d=google.com; s=arc-20160816; b=VW0KNLkceqEVk6jQq4thTQsdo/Ran7gVxgKTNOIaRK9KwwrAVzrSoKeMhInt4GlQra jIKMLy/Xjc8QsDBW5jdBG1EFA/8N218ijNGhVudFxkh8SQdheZbEwvkDyeT+cUiBvAUg qoSnx4+l1a5CiRkfWxK02doLJWvcNUfQWsvFOK5RHdtTozAh4NMBIzCtZ7C2QorWYTe+ ZmrKwp0NsAKSRPuoPTQVHkit1lcQZLK3iOENcww4gKzqo9hhX7esMtE9sLDYv/gm7ntN Jnvt+vtFpGTaZes2s5k4682HAKWZiQWsS8lXvAWyJLumL5mAuwlh6gqf462ZEGUUlIxe 07VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AFDHm0x5fCIfO9sNUnMjNHBC5QfLbAry/86mc5SrbNI=; b=T2Sb+Rdf/MAylXxyj4ZxdVbFzvpEKnA5RjofU9E/dsOjCtggLRb9EKEo5+VROx0Crl e2kRR8V1Xibwuo+hftyBQ0YbSzv4lY+h1ZsUD+B293c41/u39yx80Hgr/8knYv3bu4JD jrWURpOBa/2RnX6Leii8/1X82KdbF2BmPJ9FSs/u3mi14kQKTuJRmI85nvGDHRiyHPVb rgnWGXLQF+s0MYvxpH89cWfxFHjA3BhGzqRLLUAPIEl/F8a8JOxTs8L0ij+vBe/w3hYC k2wD5PfCydESbz2rZIjd0otdpwyVavNtaqRP32KVLBoWP4g5qII5hB4dI/qeY79IwHRN 4/JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BCDpppne; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v8si18112006ejv.188.2021.09.20.18.51.26; Mon, 20 Sep 2021 18:51:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BCDpppne; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347515AbhITSIV (ORCPT + 99 others); Mon, 20 Sep 2021 14:08:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:60428 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350776AbhITSCe (ORCPT ); Mon, 20 Sep 2021 14:02:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6675763234; Mon, 20 Sep 2021 17:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158186; bh=QY6MBd25QKZiu36ewlOr0ps4BMJR4Qlho/OjIvbK2xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BCDpppne3Y6y72p1Wmr/xPmu61BCHyntV1YxkwNzhdT7/0amCwrP4ltMmDTtDPPWJ 2TxnVuYt9kypyMJsFP1lwOa1UDRJTI4B7j/Kia2/A6Df6FIGzR6NxxgRf6q6ekzAwL 0Ry2tVoy1vjViAW3+6x/XSia07XZN130fGolEwWI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.4 040/260] RDMA/iwcm: Release resources if iw_cm module initialization fails Date: Mon, 20 Sep 2021 18:40:58 +0200 Message-Id: <20210920163932.483041728@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leon Romanovsky [ Upstream commit e677b72a0647249370f2635862bf0241c86f66ad ] The failure during iw_cm module initialization partially left the system with unreleased memory and other resources. Rewrite the module init/exit routines in such way that netlink commands will be opened only after successful initialization. Fixes: b493d91d333e ("iwcm: common code for port mapper") Link: https://lore.kernel.org/r/b01239f99cb1a3e6d2b0694c242d89e6410bcd93.1627048781.git.leonro@nvidia.com Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/iwcm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index da8adadf4755..75b6da00065a 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c @@ -1187,29 +1187,34 @@ static int __init iw_cm_init(void) ret = iwpm_init(RDMA_NL_IWCM); if (ret) - pr_err("iw_cm: couldn't init iwpm\n"); - else - rdma_nl_register(RDMA_NL_IWCM, iwcm_nl_cb_table); + return ret; + iwcm_wq = alloc_ordered_workqueue("iw_cm_wq", 0); if (!iwcm_wq) - return -ENOMEM; + goto err_alloc; iwcm_ctl_table_hdr = register_net_sysctl(&init_net, "net/iw_cm", iwcm_ctl_table); if (!iwcm_ctl_table_hdr) { pr_err("iw_cm: couldn't register sysctl paths\n"); - destroy_workqueue(iwcm_wq); - return -ENOMEM; + goto err_sysctl; } + rdma_nl_register(RDMA_NL_IWCM, iwcm_nl_cb_table); return 0; + +err_sysctl: + destroy_workqueue(iwcm_wq); +err_alloc: + iwpm_exit(RDMA_NL_IWCM); + return -ENOMEM; } static void __exit iw_cm_cleanup(void) { + rdma_nl_unregister(RDMA_NL_IWCM); unregister_net_sysctl_table(iwcm_ctl_table_hdr); destroy_workqueue(iwcm_wq); - rdma_nl_unregister(RDMA_NL_IWCM); iwpm_exit(RDMA_NL_IWCM); } -- 2.30.2